PDA

Click to See Complete Forum and Search --> : Comparing two strings (not working)


abdul
Jul 26th, 2002, 06:06 PM
I have hooked my window and I am trying to know when a menu window is created as a new window is created. The class for the menu window is #32770 (I think) so I am using the following chunk of code to check when a menu window is created:

LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam)
{
CWPSTRUCT *cw;
string classname;
switch (nCode)
{
case HC_ACTION:
cw = (CWPSTRUCT*)lParam;
GetTheClassName(cw->hwnd, classname);
// MessageBox(cw->hwnd,classname.c_str(),"",MB_OK);
if(strcmp(classname.c_str(),"#32770") == 0)
{
MessageBox("A menu window was created","",MB_OK);
//A menu window was created
}
return CallNextHookEx(myhook,nCode,wParam,lParam);
}

return CallNextHookEx(myhook,nCode,wParam,lParam);
}

void GetTheClassName(HWND hWnd, string &classdest)
{
char classname[128];
GetClassName(hWnd,classname, 128);
classdest = classname;
}


Now if I uncomment the line MessageBox(cw
>hwnd,classname.c_str(),"",MB_OK); before I use the if statement, some of the class names ARE "#32770" so it should actually return 0 from strcmpy but it's NOT. It never shows the message box inside the if statement which says "A menu window was created".

Technocrat
Jul 26th, 2002, 06:40 PM
Try making a temp VAR to hold your string compare and then if that VAR

abdul
Jul 26th, 2002, 06:53 PM
Nope, that doesn't work.

Technocrat
Jul 28th, 2002, 11:15 AM
Well what is the VAR equal to when you run it? 0, -1, > 0 ?

Maybe there is a return in your string

Try if(strcmp(classname.c_str(),"#32770") >= 0)