Subclass Procedure failed for edit control
-
Hi to all, I am subclassing an EDIT Control. But the WM_CREATE is not fired in Subclassed Procedure EditProc. What is wrong, i am unable to find. I had tried WM_NCCREATE also, but failed. pls help.. :( :confused:
#include
#include "resource.h"WNDPROC OldEditProc;
HINSTANCE hInst;
HFONT hFont;WNDPROC SUBCLASS(HWND hControl,WNDPROC newWindowProc)
{
return (WNDPROC)SetWindowLong(hControl,GWL_WNDPROC,(LONG)newWindowProc);
}LRESULT CALLBACK EditProc(HWND hWnd,UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_CREATE:
SetWindowText(hWnd,L"Welcome");
break;
}
return OldEditProc(hWnd,Msg,wParam,lParam);
}LRESULT CALLBACK stdEditProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{switch(Msg) { case WM\_INITDIALOG: OldEditProc = SUBCLASS(GetDlgItem(hWnd,IDC\_EDIT1),EditProc); break; case WM\_CLOSE: EndDialog(hWnd,TRUE); break; } return FALSE;
}
INT APIENTRY wWinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPWSTR lpCmdLine, __in int nShowCmd )
{
hInst = hInstance;
return DialogBox(hInst,MAKEINTRESOURCE(IDD_DIALOG1),NULL,(DLGPROC)stdEditProc);
}Regards, Vishal
-
Hi to all, I am subclassing an EDIT Control. But the WM_CREATE is not fired in Subclassed Procedure EditProc. What is wrong, i am unable to find. I had tried WM_NCCREATE also, but failed. pls help.. :( :confused:
#include
#include "resource.h"WNDPROC OldEditProc;
HINSTANCE hInst;
HFONT hFont;WNDPROC SUBCLASS(HWND hControl,WNDPROC newWindowProc)
{
return (WNDPROC)SetWindowLong(hControl,GWL_WNDPROC,(LONG)newWindowProc);
}LRESULT CALLBACK EditProc(HWND hWnd,UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_CREATE:
SetWindowText(hWnd,L"Welcome");
break;
}
return OldEditProc(hWnd,Msg,wParam,lParam);
}LRESULT CALLBACK stdEditProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{switch(Msg) { case WM\_INITDIALOG: OldEditProc = SUBCLASS(GetDlgItem(hWnd,IDC\_EDIT1),EditProc); break; case WM\_CLOSE: EndDialog(hWnd,TRUE); break; } return FALSE;
}
INT APIENTRY wWinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPWSTR lpCmdLine, __in int nShowCmd )
{
hInst = hInstance;
return DialogBox(hInst,MAKEINTRESOURCE(IDD_DIALOG1),NULL,(DLGPROC)stdEditProc);
}Regards, Vishal
WM_CREATE
andWM_NCCREATE
will not be sent to the sub-classed procedure because they have already been sent to the original procedure. But you will get otherWM_COMMAND
messages and notifications.«_Superman_» _I love work. It gives me something to do between weekends.
-
WM_CREATE
andWM_NCCREATE
will not be sent to the sub-classed procedure because they have already been sent to the original procedure. But you will get otherWM_COMMAND
messages and notifications.«_Superman_» _I love work. It gives me something to do between weekends.
got it, but one small doubt, if i want to set font for a control i usually do it in
WM_INITDIALOG
orWM_CREATE
section, but in this case which Message has to be used for setting font, As i had found this can be done inWM_PAINT
section also, butWM_PAINT
is triggered every now and then, resulting in extra overload. Please guide which message will be better to set a font for a control in its subclassed procedure. Thanks.. :)Regards, Vishal
-
got it, but one small doubt, if i want to set font for a control i usually do it in
WM_INITDIALOG
orWM_CREATE
section, but in this case which Message has to be used for setting font, As i had found this can be done inWM_PAINT
section also, butWM_PAINT
is triggered every now and then, resulting in extra overload. Please guide which message will be better to set a font for a control in its subclassed procedure. Thanks.. :)Regards, Vishal
So if you do this before you sub-class the control in the original procedure, does it change after sub-classing? Don't do it in
WM_PAINT
. It will be an unnecessary overhead. Instead, you could define a custom message and do aPostMessage
with the custom message to the control after it is sub-classed inWM_INITDIALOG
.«_Superman_» _I love work. It gives me something to do between weekends.
-
So if you do this before you sub-class the control in the original procedure, does it change after sub-classing? Don't do it in
WM_PAINT
. It will be an unnecessary overhead. Instead, you could define a custom message and do aPostMessage
with the custom message to the control after it is sub-classed inWM_INITDIALOG
.«_Superman_» _I love work. It gives me something to do between weekends.