subclassing in win32
-
hai, I want to attach a bitmap to my button control.I'm using win32 vc++ and I am just the beginner to vc++. I used loadbitmap() and sendmessage() to button control.It worked.But I was requested to do with subclassing. I pretty much have no idea.I tried MSDN. It's there for MFC (subclassdlgitem())but I want to do in win32.Can anyone help me?
-
hai, I want to attach a bitmap to my button control.I'm using win32 vc++ and I am just the beginner to vc++. I used loadbitmap() and sendmessage() to button control.It worked.But I was requested to do with subclassing. I pretty much have no idea.I tried MSDN. It's there for MFC (subclassdlgitem())but I want to do in win32.Can anyone help me?
Subclassing in Win32 requires that you write your own window procedure (see
WindowProc
in MSDN) and specify it as thelpfnWndProc
parameter in theWNDCLASS
structure you use to register your window class. You use the class name you used in theWNDCLASS
structure in your call toCreateWindow
when you want to create your button. see MSDN for: WindowProc, WNDCLASS, RegisterClass, CreateWindow.
[
](http://www.canucks.com)"You're obviously a superstar." - Christian Graus about me - 12 Feb '03 "Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04 Within you lies the power for good - Use it!
-
hai, I want to attach a bitmap to my button control.I'm using win32 vc++ and I am just the beginner to vc++. I used loadbitmap() and sendmessage() to button control.It worked.But I was requested to do with subclassing. I pretty much have no idea.I tried MSDN. It's there for MFC (subclassdlgitem())but I want to do in win32.Can anyone help me?
You can try to do something like this....
WNDPROC wpOrigButtonProc; LRESULT APIENTRY DlgProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { HWND hwndButton; switch(uMsg) { case WM_INITDIALOG: // Retrieve the handle to the edit control. hwndButton = GetDlgItem(hwndDlg, ID_BUTTON); // Subclass the edit control. wpOrigButtonProc = (WNDPROC) SetWindowLong(hwndButton, GWL_WNDPROC, (LONG) ButtonSubclassProc); // // Continue the initialization procedure. // return TRUE; case WM_DESTROY: // Remove the subclass from the edit control. SetWindowLong(hwndButton , GWL_WNDPROC, (LONG) wpOrigButtonProc); // // Continue the cleanup procedure. // break; } return FALSE; UNREFERENCED_PARAMETER(lParam); } // Subclass procedure LRESULT APIENTRY ButtonSubclassProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case .... /* Process the messages you want here */ } /* else pass it to the original handler */ return CallWindowProc(wpOrigButtonProc, hwnd, uMsg, wParam, lParam); }
I hope this helps you out. -
You can try to do something like this....
WNDPROC wpOrigButtonProc; LRESULT APIENTRY DlgProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { HWND hwndButton; switch(uMsg) { case WM_INITDIALOG: // Retrieve the handle to the edit control. hwndButton = GetDlgItem(hwndDlg, ID_BUTTON); // Subclass the edit control. wpOrigButtonProc = (WNDPROC) SetWindowLong(hwndButton, GWL_WNDPROC, (LONG) ButtonSubclassProc); // // Continue the initialization procedure. // return TRUE; case WM_DESTROY: // Remove the subclass from the edit control. SetWindowLong(hwndButton , GWL_WNDPROC, (LONG) wpOrigButtonProc); // // Continue the cleanup procedure. // break; } return FALSE; UNREFERENCED_PARAMETER(lParam); } // Subclass procedure LRESULT APIENTRY ButtonSubclassProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case .... /* Process the messages you want here */ } /* else pass it to the original handler */ return CallWindowProc(wpOrigButtonProc, hwnd, uMsg, wParam, lParam); }
I hope this helps you out. -
hai, Thanks a lot.I understood your code.But inside this subclass procedure what I should do to attach my bitmap to the button? thanks.