|
Call PreTranslateMessage yourself; it's virtual.
Something like this:
BOOL CMyModelessDlg::PreTranslateMessage(MSG* pMsg)
{
if (!(m_hAccel && ::TranslateAccelerator(AfxGetApp()->m_pMainWnd->m_hWnd, m_hAccel, pMsg)))
return CDiaog::PreTranslateMessage(pMsg);
else
return TRUE;
}
Phil
The opinions expressed in this communication do not necessarily represent those of the author (especially if you find them impolite, discourteous or inflammatory).
|
|
|
|
|
I have something like you proposed:
<br />
BOOL CCentaurusDlg::PreTranslateMessage(MSG* pMsg) <br />
{<br />
BOOL handled = FALSE;<br />
<br />
if (pMsg->message == WM_KEYDOWN)<br />
{<br />
if (::TranslateAccelerator(m_hWnd, m_accelerators, pMsg) != 0)<br />
{<br />
handled = TRUE;<br />
}<br />
}<br />
<br />
if (!handled)<br />
{<br />
handled = CDialog::PreTranslateMessage(pMsg);<br />
}<br />
<br />
return handled;<br />
}<br />
But my PreTranslateMessage method is not called by the MFC framework. So where should I call PreTranslateMessage ?
|
|
|
|
|
I feel my computer is playing a cat and mouse game with me, and I am the one losing. Here's why!
I can enter a bunch of strings and it can read one and ignore the rest, (meaning, it'll only give me the first one that it read), or it can read ALL, but give me NOTHING (meaning, it'll hang in the loop)!! Here's the code.
string str;
vector<string> vStr;
do
{
cin>> str;
vStr.push_back(str);
cout<<"\n Size: " <<vStr.size();
} while(str.end()!="\r");
======================
vector<string>::iterator iterB = vStr.begin(), iterE = vStr.end();
for(; iterB!=iterE; ++iterB)
cout<< *iterB <<" ";
======================
cout<<"\n" <<endl; The condition shown in the 'while' statement, will show the vector growing as strings are entered, but WILL NOT exit the 'do/while' loop.
However, if I were to change the condition in the 'while' statement to:
while(str.end()=="\r"); It'll exit the loop, but will ONLY give me the first string it read.
Ideally, I would like for it to read all the strings entered, and report all that it accumulated in the vector.
Thanks for any help.
William
Fortes in fide et opere!
|
|
|
|
|
I'm a little confused as to what you want your end condition to be... cin >> str reads in tokens delimited by whitespace (including \r and \n ), and throws away the whitespace.
If you want to read an entire line of text at once, then look at cin.getline() .
- Mike
|
|
|
|
|
Try the following
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;
int main()
{
string line;
getline(cin,line);
istringstream istrstr(line);
vector<string> vStr;
for(;;)
{
string str;
if(!(istrstr>>str))break;
vStr.push_back(str);
cout<<"\n "<<str;
cout<<"\n Size: " <<vStr.size();
}
return 0;
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks for replying.
I did review several options to my situation which included the use of 'istringstream'. At first 'istringstream' looked very promising, but after studying it some more, it didn't quite offer me what I was looking for (viz., an option that didn't limit the number of strings I might be receiving at any time).
'istringstream' is ideal for formatted string input and for a set number of strings. IOW, in your input stream syntax, you would have to show the amount of strings you are going to be receiving and their types (if other types are going to be part of the input other than just 'string').
Because the number of strings I would be receiving varies, I had to choose something that didn't restrict me to a fix amount, which told me that a loop would have to be the main mechanism.
I will look at your example, and again review what 'istringstream' can do for me.
Thank you for replying. I appreciate it.
William
Fortes in fide et opere!
|
|
|
|
|
I think I understand your problem. Have you tried checking for str.empty before pushing to the vector, and exiting the loop if the string is actually empty? I've not tried it myself, but I guess it might work.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Yes, I did try:
while(str.empty()); and got nowhere with it (meaning, it would not exit the loop). I also tried the opposite, 'while(!str.empty());' and it exited the loop but with only the first string. (IOW, the computer and I playing the old cat and mouse game.)
Thanks for replying.
William
Fortes in fide et opere!
|
|
|
|
|
I did not explain myself clearly enough. I mean:
for(;;)
{
cin>>str;
if(str.empty())break;
vStr.push_back(str);
cout<<"\n Size: " <<vStr.size();
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks for replying.
I didn't exactly try your last suggestion (according to the way you coded it), but I did try using the 'break' syntax, and it certainly did take me out of the loop. But guess what, the vector only had the first string entered in it!!
Believe me, before I posted this problem on CP, I tried a lot of ways, but always with one of the two standard results: either I end up with just the first entry, or I couldn't exit the loop.
William
Fortes in fide et opere!
|
|
|
|
|
As I understand it, end() will point just beyond the end of the sequence. Maybe that is your intent, but I'm not sure. Anyway, what condition do you want to terminate the do/while loop? Maybe something like:
do
{
...
} while (str[0] != '\r');
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Thanks for replying.
Your sample gave the same result as:
while(str.end()!="\r"); which is, "receiving any number of strings and growing the vector, but unable to exit the loop."
The intent is to receive as many strings as inputted, and exit when finished.
The exiting part is the whole problem, because if I were to just enter one string, I can exit with:
while(str.end()=="\r"); I've tried a number of things while inside the loop (e.g. conducting certain discrete test and setting boolean values to signal to the loop that I'm ready to exit), and the best I could have ended up with came down to one of the two options I presented in my original posting.
William
Fortes in fide et opere!
|
|
|
|
|
From what I've seen, cin does not "return" until a non-whitespace character has been entered. This leads to something like:
string str;
vector<string> vStr;
do
{
cin >> str;
vStr.push_back(str);
cout << "\n Size: " << vStr.size();
} while (str != "9");
which is one step away from cheesy!
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Cheesy or not, at this point I'll take whatever works.
Something else I tried, included inserting a delimiter at the end of the last string inputted, to signal that I wanted to exit the loop (how much cheesier than that can you get, I don't know), but that didn't work either.
Am I desperate? Not quite, but am getting there.
Thanks for replying.
William
Fortes in fide et opere!
|
|
|
|
|
i've got a piece of code last week. When i wanted to compile it, the compiler couldn't recognise the symbols 'SEC_WINNT_AUTH_IDENTITY_EXW' and 'SEC_WINNT_AUTH_IDENTITY_VERSION' and 'FreeCredentialsHandle'
i've downloaded the latest Platform SDK (today). and put the include Path into the Directories for VC6.0 .. i am using Win2k.
Any ideas ?
Bernhard
"I'm from the South Bronx, and I don't care what you say: those cows look dangerous." U.S. Secretary of State Colin Powell at George Bush's ranch in Texas
|
|
|
|
|
My code is working fine when I manually start/stop the service.
The problem I facing is my service didn't signal stop event when i restart/shutdown my pc.
I am using CNTService code from PJ naughter
|
|
|
|
|
Hi All,
I am trying to save the clipboard content as a bmp file. I tried like this:
<br />
HANDLE hBmp;<br />
OpenClipboard();<br />
hBmp = GetClipboardData(CF_DIB); <br />
if(hBmp)<br />
{<br />
if (WriteDIB("c:\\TEST.BMP",GetClipboardData(CF_DIB)) == TRUE)<br />
{<br />
MessageBox("Success","BMP Written",NULL); <br />
}<br />
else<br />
{<br />
MessageBox("Failed","BMP Write",NULL);<br />
}<br />
EmptyClipboard ();<br />
}<br />
else<br />
{<br />
printerror(GetLastError());<br />
}<br />
CloseClipboard(); <br />
<br />
<br />
void printerror(long err)<br />
{<br />
LPVOID lpMsgBuf;<br />
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORM<br />
AT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSER<br />
TS,NULL,err,MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),(LPTSTR)&lpMsgBuf,30,NULL);<br />
MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION ); <br />
}<br />
I am getting NULL in hBmp. So if condition fails. I tried to get the error code. But error message says "Function completed successfully". Can anyone help me where i went wrong??
Thanks in advance,
Thoppae.
Its Always the Root that helps to Nurture Fruits.The Root is 'C'.
|
|
|
|
|
when i want to insert 5000-7000 items to a listctrl.
it's inserting process is very slow. how to deal with that?
3x. and anyother Q: when i use CListBox to SetCurSel(5000),or lager number it will also slow. how to do?
love program
|
|
|
|
|
For a good solution take a look at Chris Maunder article "Using text callbacks in ListView Controls"
bye,
CC.
|
|
|
|
|
Call "LockWindowUpdate" before bulk insertion and "UnlockWindowUpdate" after.
m_wndListCtrl.LockWindowUpdate();
m_wndListCtrl.UnlockWindowUpdate();
|
|
|
|
|
Hi All,
I am using a property sheet..i have created three property pages nad added them to the propert sheet. This property sheet is made visible when user clicks on the system Tray icon. One of the property page is displaying a web page is webbrowser control. Everything works fine for some time..then..it automatically either stops listening to right click event of mouse or even deletes one or more of the tabs..also sometimes it closes visual studio...can anyone help me out to sort out this problem..thanks a lot in advance for any help...
regards
Himanshu
|
|
|
|
|
With one of my applications using property sheets, I discovered that you cannot update page fields unless the property page is visible - just update the information and then update the form in OnShowWindow(). Also, you cannot have an active timer for a property page that is not visible. In both cases, if the property page is not visible, the window handle is not valid and all sorts of unusual behavior happens.
Steve
|
|
|
|
|
SOCKADDR_IN tempaddr;
tempaddr.sin_addr = INADDR_ANY;
I have seen code like this in many examples. I am not quite sure why the compiler would tell me that:
error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'unsigned long' (or there is no acceptable conversion)
I would have never gotten as far as I did with this program without all of your help.
Thank you
|
|
|
|
|
The compiler is telling you that, there is a type mismatch. The "sin_addr" is a structure. Read the MSDN about it. (In my humble opinion: you got to dig deeper in programming )
Try this @ home. (B&B)
|
|
|
|
|
Try this:
tempaddr.sin_addr.s_addr = INADDR_ANY;
In your example, you are trying to assign a single value to a structure.
Steve
|
|
|
|