I tried this:
But it doesn't work.Code:if(hWindow == "Button"){ } else if(hWindow == "Edit"){ } else if(hWindow == "Static"){ } else { }
Why?
And how could I succesfully make my prog. read what type of Window it is?
Thanks, August.
I tried this:
But it doesn't work.Code:if(hWindow == "Button"){ } else if(hWindow == "Edit"){ } else if(hWindow == "Static"){ } else { }
Why?
And how could I succesfully make my prog. read what type of Window it is?
Thanks, August.
GetClassInfoEx()
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
GetClassName will get you the window class name.
GetClassInfoEx requires the actual window class name itself as a parameter.
CProgramming FAQ
Caution: this person may be a carrier of the misinformation virus.
he knew the names,he wanted to query system classes.
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
You're right - thanks for clarifying.
CProgramming FAQ
Caution: this person may be a carrier of the misinformation virus.
Like this: (?)
Code:GetClassName(hWindow, tClassName, 8); if(tClassName == "Button"){ }
Not exactly. I believe for character array comparisons, you should use one of the strcmp functions.
Code:if( strcmp(tClassName,"Button")==0 ){ }
Post your code then.
Edit: I'll post a working version.
Code:/*------------------------------------------------------------------------------ GetClassName Demo Author: Andrew Lim ------------------------------------------------------------------------------*/ #include <windows.h> HWND button ; LRESULT CALLBACK WndProc( HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam ) { switch(msg) { case WM_CREATE: { button = CreateWindow( "bUTtOn", "Click me!", WS_CHILD|WS_VISIBLE, 10, 10, 100, 22, hwnd, 0, GetModuleHandle(0), 0 ); return 0 ; } case WM_COMMAND: { HWND control = (HWND) lParam ; if ( control == button ) { TCHAR buffer[256]; GetClassName( button, buffer, 256 ); if ( !strcmp(buffer,"Button") ) { MessageBox( hwnd, buffer, "Button Class Name", 0 ); } } return 0 ; } case WM_DESTROY: { PostQuitMessage(0); return 0; } default: return DefWindowProc(hwnd,msg,wParam,lParam); } } int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrev, LPSTR args, int nShow ) { WNDCLASS wc = {0}; wc.lpszClassName = TEXT( "GetClassNameDemo" ); wc.hInstance = hInst ; wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE); wc.lpfnWndProc = WndProc ; wc.hCursor = LoadCursor(0,IDC_ARROW); RegisterClass(&wc); CreateWindow( wc.lpszClassName,TEXT("GetClassName Demo"), WS_OVERLAPPEDWINDOW|WS_VISIBLE, 0,0,300,200,0,0,hInst,0); MSG msg ; while( GetMessage(&msg,0,0,0) > 0 ) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; }
Last edited by Dante Shamest; 10-08-2005 at 09:37 AM.
Thanks, I see my problem was that I was using a char var instead of a TCHAR var.
It should still work with a char array, as long as UNICODE isn't defined.