|
I am using Visual C++ 6.0 MFC. I have a tab control with dialog resources as tab pages. If I click on OK or CANCEL buttons the CWnd::SendMessage(WM_COMMAND, wParam, lParam) returns a value of 1 and everything is good. If I click on any other button control (whose resource value is stored in wParam) the CWnd::SendMessage(WM_COMMAND, wParam, lParam) returns a value of 0. Does anyone know what's going on inside the SendMessage() function? Why does the function not recognize the control ID?
Thanks
Buck Brown
|
|
|
|
|
Did you see MSDN.
From the MSDN:
"The SendMessage function sends the specified message to a window or windows. It calls the window procedure for the specified window and does not return until the window procedure has processed the message."
Syntax
<br />
LRESULT SendMessage(HWND hWnd,<br />
UINT Msg,<br />
WPARAM wParam,<br />
LPARAM lParam);<br />
|
|
|
|
|
Thanks to everyone at CodeProject for providing a fantastic resource for programmers.
I am using several comboboxes to navigate through a flat file database of my own construction. Three of these comboboxes are almost identical in structure and function.
When I select a record from the drop down list from two of the combo boxes (all are set in dropdown mode with identical checkboxes), the record is displayed, and the statements:
pComboBox1or2->SetFocus;
pComboBox1or2->SetEditSel(0,-1);
pComboBox1or2->Clear();
clears the edit box of comboboxes 1 and 2 exactly as expected.
However, when I use the same exact lines for combo box 3
pComboBox3->SetFocus;
pComboBox3->SetEditSel(0,-1);
pComboBox3->Clear();
in the same exact point in almost identical code for combobox 3, the edit box of the combobox refuses to clear.
Interestingly, calling the combobox3 lines from the combobox 1 or two functions clears the combobox3 edit box - however this is not adequate as I need to clear the edit box after selecting a record.
While trying to figure this problem out, I placed a 500 iteration loop around the statements for combobox1or2, and noted a flashing edit field - which ended with a blank edit field. When I tried the same thing with the troublesome combobox3, the edit field did not flash (although it took about the same amount of time for the process to finish), and the edit box did not clear.
I have tried everyhting I can think of to make the code for the various boxes as similar as possible, and find it very strange that two of the three comboboxes work as expected, while the third does not.
Any suggestions?
Thanks in advance for your assistance.
-- modified at 18:33 Wednesday 26th July, 2006
|
|
|
|
|
your problem is that combox1 and 2 are ok in a same way but combo3 its not same,Right?
|
|
|
|
|
Correct.
All three boxes are almost completely identical in every way - except their behavior. Combo 1 and 2 behave linearly (as expected) every time I try, but combo 3 does not behave linearly much at all, especially with respect to the key behavior of leaving the edit box blank after the record selection is complete.
Completely disabling the edit box, for example painting over it to hide the functinoing edit box underneath might be acceptable. I tried using the Drop List box, as a menas of achieving a secondary goal of preventing user input, but this makes the functioning bozes also fail to clear their edit boxes after record selection.
It is as if combo 3 is not completely switching out of Drop List mode when I change the selector in the resource editor (visual ++ 6.0) except that combo 3 allows changing the edit box text in drop down mode while combo 2 does not allow edit of edit box (in drop list mode).
A good work around would be a means to permanently hide the edit box so it didnot matter if it was not cleared and this would have the added feature of preventing user confusion/text entry in the edit box.
Thanks for your reply.
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
Possible workaround:
after trying many things such as calling the complete or partial selchange functions that did work, breaking the edit box clearing code out into a separate function etc. I appear to have found something that will work.
Inserting a pComboBox3->Paste(); line like this:
pComboBox3->SetFocus;
pComboBox3->SetEditSel(0,-1);
pComboBox3->Paste;
pComboBox3->SetEditSel(0,-1);
pComboBox3->Clear();
appears to clear the edit box.
It may not be pretty - but, well - neither am I.
Thanks to all of you who considered my problem and especially to WhiteSky who responded.
Thanks again to everyone at Code Project.
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
|
|
|
|
|
hello
I'm looking for a common dialog box to choose folders an exaple of files is GetOpenFileName(...) is there a common dialog box for directories.
Thank you
G_S
|
|
|
|
|
Look for SHBrowseForFolder ... I believe there is a decent article on it in CP ... and Google finds some others as well.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
|
|
I'm trying to code a function which returns the number of words in an array, strSentence[100, 1000].
Algorithm:
1. return the first occurrence of strWord.
2. Remove strWord from strSentence.
3. Repeat the above steps until (1) returns no value.
I am using strstr to return the first occurrence of strWord within strSentence. However, the following error is being displayed:
SentenceAr.cpp(94): error C2664: 'strstr' : cannot convert parameter 1 from 'char [100][1000]' to 'const char *'
Code:
int CSentenceAr::HowManyWords(const char strWord[MAX_WORD_LENGTH])
{ char *strCurrentSentence;
ZeroMemory(strCurrentSentence,sizeof(strCurrentSentence));
char *ptrPosition;
for (int iCurrent = 1; iCurrent <= iNumberOfLines; iNumberOfLines++)
{ strcpy(strCurrentSentence, strSentence[iCurrent]);
ptrPosition = strstr(strSentence, strWord);
}
Any work around for this, please?
Jon
|
|
|
|
|
strstr doesn't know about arrays of arrays of chars, it only knows about arrays of chars.
so... ptrPosition = strstr(strSentence[some_index], strWord);
|
|
|
|
|
jon_80 wrote: ZeroMemory(strCurrentSentence,sizeof(strCurrentSentence));
...
strcpy(strCurrentSentence, strSentence[iCurrent]);
These two statements look suspect as strCurrentSentence does not point to a valid memory address.
jon_80 wrote: ptrPosition = strstr(strSentence, strWord);
This should probably be:
ptrPosition = strstr(strCurrentSentence, strWord);
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
CSentenceAr.h
int HowManyWords(const char strWord[MAX_WORD_LENGTH]);
CSentenceAr.cpp
int CSentenceAr::HowManyWords(const char strWord[MAX_WORD_LENGTH])
{ char strCurrentSentence;
ZeroMemory(strCurrentSentence,sizeof(strCurrentSentence));
char ptrPosition;
for (int iCurrent = 1; iCurrent <= iNumberOfLines; iNumberOfLines++)
{ strcpy(strCurrentSentence, strSentence[iCurrent]);
ptrPosition = strstr(strSentence, strWord);
}
}
Now I'm getting more errors:
SentenceAr.cpp(89): error C2664: 'memset' : cannot convert parameter 1 from 'char' to 'void *'
SentenceAr.cpp(93): error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
SentenceAr.cpp(94): error C2664: 'strstr' : cannot convert parameter 1 from 'char [100][1000]' to 'const char *'
Jon
|
|
|
|
|
jon_80 wrote: ZeroMemory(strCurrentSentence,sizeof(strCurrentSentence));
This is not necessary (if strcpy() is to be used later on).
jon_80 wrote: SentenceAr.cpp(93): error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
The compiler is telling you exactly what the problem is. Parameter 1 needs to be a char* , but strCurrentSentence is just a char .
jon_80 wrote: SentenceAr.cpp(94): error C2664: 'strstr' : cannot convert parameter 1 from 'char [100][1000]' to 'const char *'
Parameter 1 cannot be a 2D array. Chris showed you a solution. Why did you not use it?
|
|
|
|
|
The program uses a fixed array, so I need to work around it. Sorry, but I'm a newbie.
Now I'm getting: SentenceAr.cpp(100): error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
for (int iCurrent = 1; iCurrent <= iNumberOfLines; iNumberOfLines++)
{ //retrieve line of text
strcpy(strCurrentSentence, strSentence[iCurrent]);
ptrCurrentSentence = &strCurrentSentence;
while (bFound == true)
{ ptrPosition = strstr(ptrCurrentSentence, strWord);
if (ptrPosition != NULL)
{ iResult++;
}
else if (ptrPosition = NULL)
{bFound = false;}
}
}
return 0;
}
Jon
|
|
|
|
|
jon_80 wrote: Now I'm getting: SentenceAr.cpp(100): error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
strCurrentSentence needs to be at least as large as strSentence[iCurrent] .
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Try this instead:
int CSentenceAr::HowManyWords(const char strWord[MAX_WORD_LENGTH])
{
const char* delimiters = " ,.!?;:\t\r\n()";
char buffer[MAX_WORD_LENGTH] = {0};
memcpy(buffer, strWord, MAX_WORD_LENGTH);
char* token = 0;
unsigned long wordCount = 0;
token = strtok(buffer, delimiters);
while (token != 0)
{
if (strlen(token) > 0)
{
++wordCount;
}
token = strtok(0, delimiters);
}
return (int)wordCount;
}
-- modified at 16:22 Wednesday 26th July, 2006
|
|
|
|
|
I'm not sure, but after following through the code, the code checks whether the word we are looking for is greater than length zero, hence always returning a value of at least 1.
What I was trying to do was to check for how many times $searchword appears within an array of an array of chars (simply put an array of strings) $sentences.
Jon
|
|
|
|
|
My apologies, the algorithm I posted will count the number of words in a character array. To find the number of times a substring appears in the array, you need to modify the algorithm to use strstr instead of strtok:
unsigned long HowManyWords(const char strWord[MAX_WORD_LENGTH], const char* substring)
{
char buffer[MAX_WORD_LENGTH] = {0};
memcpy(buffer, strWord, MAX_WORD_LENGTH);
char* token = 0;
unsigned long wordCount = 0;
token = strstr(buffer, substring);
while (token != 0 && *token != 0)
{
if (strlen(token) > 0)
{
++wordCount;
token += strlen(substring);
if (token >= buffer + MAX_WORD_LENGTH)
{
break;
}
}
token = strstr(token, substring);
}
return (int)wordCount;
}
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Thanks.. I have updated the code accordingly, adding also a memcpy so that memcpy is used to copy the variables to local variables. I assume that this is a workaround for strstr (right?).
However, token seems to have a value of 0xcccccccc <Bad Ptr> when debugging, so the program never really checks.
Code:
int CSentenceAr::HowManyWords(const char strWord[MAX_WORD_LENGTH])
{
// initialize local variables
char strSearch[MAX_WORD_LENGTH] = {0};
memcpy(strSearch, strWord, MAX_WORD_LENGTH); //copies fixed array to strSearch
char* ptrToken = 0;
char strSentence[MAX_SENTENCE_LENGTH] = {0};
int iWordCount = 0;
for (int iCurrent = 0; iCurrent <= iNumberOfLines; iNumberOfLines++)
{
ptrToken = strstr(strSentence, strSearch);
while (ptrToken != 0 && *ptrToken != 0)
{ memcpy(strSentence, this->strSentence[iCurrent], MAX_SENTENCE_LENGTH);
if (strlen(ptrToken) > 0)
{ ++iWordCount;
ptrToken += strlen(strWord);
if (ptrToken >= strSentence + MAX_WORD_LENGTH)
{break;}
}
ptrToken = strstr(ptrToken, strSearch);
}
}
return (int) iWordCount;
}
Jon
|
|
|
|
|
jon_80 wrote: for (int iCurrent = 0; iCurrent <= iNumberOfLines; iNumberOfLines++)
{
ptrToken = strstr(strSentence, strSearch);
while (ptrToken != 0 && *ptrToken != 0)
{ memcpy(strSentence, this->strSentence[iCurrent], MAX_SENTENCE_LENGTH);
if (strlen(ptrToken) > 0)
{ ++iWordCount;
ptrToken += strlen(strWord);
if (ptrToken >= strSentence + MAX_WORD_LENGTH)
{break;}
}
ptrToken = strstr(ptrToken, strSearch);
}
}
token = strstr(buffer, substring);
while (token != 0 && *token != 0)
{
if (strlen(token) > 0)
{
++wordCount;
token += strlen(substring);
if (token >= buffer + MAX_WORD_LENGTH)
{
break;
}
}
token = strstr(token, substring);
}
Your loop and mine are not the same, which is why you are having problems with it. Where is iNumberOfLines declared and initialized? Your outter for loop is still incrementing this value but checking it against the iterating value that doesn't change. After a while, you will find that token is invalid because you will have gone off into "never-never land" (part of memory that you shouldn't be in).
The function I posted will take any single character array and tell you how often a substring appears in it. If you want to do this for multiple lines, you would simple call that function in a loop:
char SomeWords[20][100] = { };
char SearchString[10] = { };
for (int i = 0; i < 20; ++i)
{
unsigned long count = HowManyWords(SomeWords[i], SearchString);
cout << "Found substring (" << SearchString << ") " << count
<< " times in string(" << i << ")." << endl;
}
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
I see... I was reading the string incorrectly.
Jon
|
|
|
|
|
I'm sorry I misunderstood the scope of the function.
Jon
|
|
|
|
|
Hi again,
I'm not sure if I'm repeating myself (sorry), but, strToken is returning a bad value:
+ strToken 0xcccccccc <Bad Ptr> char *
Code:
unsigned int CSentenceAr::search(const char *strWord)
{
// initialize local variables
unsigned long iWordCount = 0;
char buffer[MAX_WORD_LENGTH] = {0};
/* Algorithm:
strToken shall initially contain the sentence string.
When strWord is found from the string, this is removed
from the string so that this function checks the rest of the
string for other instances of the word.
*/
char *strToken = 0;
for (int iCurrent = 0; iCurrent < Size; iCurrent++)
// copy to buffer, used as parameter for strstr.
{ memcpy(buffer, Sentences.strSentence[iCurrent], MAX_SENTENCE_LENGTH);
strToken = strstr(buffer,strWord);
while (strToken !=0 && *strToken != 0)
{
if (strlen(strToken) > 0)
{
iWordCount++;
strToken += strlen(strWord);
}
strToken = strstr(strToken, strWord);
}
}
return (int) iWordCount;
}
Jon
|
|
|
|
|