subclassing in win32
-
hai, I want to attach a bitmap to my button using subclass.I'm using win32 vc++. I have subclassed my button(IDC_BUTTON1). ie. i have done lpfnOldWndProc = (WNDPROC)SetWindowLong( GetDlgItem(hDialog,IDC_BUTTON1),GWL_WNDPROC,(DWORD)SubClassFunc); ...... LONG FAR PASCAL SubClassFunc(HWND hWnd, UINT uMsg, WPARAM wParam, LONG lParam) { } but inside this SubClassFunc what should I do to attach the bitmap(IDB_BITMAP1)? Can anyone help?
-
hai, I want to attach a bitmap to my button using subclass.I'm using win32 vc++. I have subclassed my button(IDC_BUTTON1). ie. i have done lpfnOldWndProc = (WNDPROC)SetWindowLong( GetDlgItem(hDialog,IDC_BUTTON1),GWL_WNDPROC,(DWORD)SubClassFunc); ...... LONG FAR PASCAL SubClassFunc(HWND hWnd, UINT uMsg, WPARAM wParam, LONG lParam) { } but inside this SubClassFunc what should I do to attach the bitmap(IDB_BITMAP1)? Can anyone help?
Subclassing is quite powerful, actually. Not only can you get a pre-sniff on what is going to happen, you can get a post-sniff as well. The trick with post-sniffing is that you call the original window procedure first and save it's return value into a local variable. When this is done, check the
uMsg
parameter. If it is 'WM_PAINT', then enter a handler. In this handler, get the button's DC (You have the HWND, so just useGetDC
). Then create a compatible DC with this one. Load the bitmap from file/resource. Select the bitmap into the memory DC. Blit from the memory DC into the button's DC so, that the starting point of the blit operation is NOT in point 0,0, but somewhere more to the middle. How middle it is is determined by the size of the bitmap and where you want it on the button. UseGetWindowRect
to get the bouding rectangle of the button's DC. Then do math :) But, all in all, the idea is to first allow the original window procedure to run, then do post-processing by applying the bitmap. Allowing the original procedure to run first ensures that the borders and the button state (normal/sunken) are drawn correctly. -Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.