i edited a program to superclassing the editbox.
The superclassing succeeded,but when i create the superclassed editbox ,there is a problem:
i first create the superclassed editbox in the window's
wm_create message,but the editbox can not be showed out.
But it can be showed out after i move it to the winmain.
how strange it is.
Anyone can tell me why?
thanks.
<br />
#include<windows.h><br />
#include<tchar.h><br />
<br />
#define IDC_SUPERCLASS1 1<br />
<br />
static HWND hsuperedit1;<br />
<br />
WNDPROC g_editwndOrg;<br />
static LPCTSTR sz_editsuperclass=TEXT("SuperclassEdit");<br />
<br />
LRESULT WINAPI EditSuperclassWndProc(HWND hedit,UINT msg,WPARAM wParam,LPARAM lParam);<br />
<br />
LRESULT WINAPI WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)<br />
{<br />
int cx,cy;<br />
switch(msg)<br />
{<br />
case WM_CREATE:<br />
hsuperedit1=CreateWindow(sz_editsuperclass,NULL,ES_AUTOHSCROLL|ES_LEFT|ES_MULTILINE|WS_CHILD|WS_VISIBLE,100,200,300,400,hwnd,(HMENU)IDC_SUPERCLASS1,HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);<br />
return 0;<br />
case WM_DESTROY:<br />
PostQuitMessage(0);<br />
return 0;<br />
}<br />
return DefWindowProc(hwnd,msg,wParam,lParam);<br />
}<br />
<br />
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE,LPSTR lpCmdLine,int nShowCmd)<br />
{<br />
static LPCSTR szClassName="Show Time";<br />
WNDCLASSEX wc_edit;<br />
WNDCLASSEX wc;<br />
<br />
ZeroMemory(&wc,sizeof(wc));<br />
wc.cbClsExtra =0;<br />
wc.cbSize =sizeof(WNDCLASSEX);<br />
wc.cbWndExtra =sizeof(LONG);<br />
wc.hbrBackground =(HBRUSH) GetStockObject (COLOR_BACKGROUND) ;<br />
wc.hCursor =LoadCursor (NULL, IDC_ARROW);<br />
wc.hIcon =NULL;<br />
wc.hIconSm =NULL;<br />
wc.hInstance =hInstance;<br />
wc.lpfnWndProc =WndProc;<br />
wc.lpszClassName =szClassName;<br />
wc.lpszMenuName =NULL;<br />
wc.style =CS_HREDRAW|CS_VREDRAW;<br />
<br />
ATOM atomclass=RegisterClassEx(&wc);<br />
if(atomclass==INVALID_ATOM)<br />
{<br />
MessageBox(NULL,"RegisterClass Error","RegisterClass Error",MB_OK);<br />
exit(1);<br />
}<br />
<br />
HWND hwnd=CreateWindowEx(NULL,szClassName,0,WS_OVERLAPPEDWINDOW,<br />
0,0,500,650,NULL,NULL,hInstance,NULL);<br />
<br />
ZeroMemory(&wc_edit,sizeof(wc_edit));<br />
GetClassInfoEx(NULL,"edit",&wc_edit);<br />
g_editwndOrg=wc_edit.lpfnWndProc;<br />
wc_edit.lpszClassName =sz_editsuperclass;<br />
wc_edit.hInstance =hInstance;<br />
wc_edit.lpfnWndProc =EditSuperclassWndProc;<br />
wc_edit.cbSize =sizeof(WNDCLASSEX);<br />
<br />
ATOM atomclass_edit=RegisterClassEx(&wc_edit);<br />
if(atomclass_edit==INVALID_ATOM)<br />
{<br />
MessageBox(NULL,"RegisterSuperClass Error","RegisterSuperClass Error",MB_OK);<br />
exit(1);<br />
}<br />
<br />
ShowWindow(hwnd,SW_SHOW); <br />
UpdateWindow(hwnd);<br />
<br />
<br />
MSG msg;<br />
while(GetMessage(&msg,NULL,NULL,NULL))<br />
{<br />
TranslateMessage(&msg);<br />
DispatchMessage(&msg);<br />
}<br />
return msg.wParam ;<br />
}<br />
<br />
LRESULT WINAPI EditSuperclassWndProc(HWND hedit,UINT msg,WPARAM wParam,LPARAM lParam)<br />
{<br />
LRESULT lResult;<br />
BOOL fCallOrgProc=TRUE;<br />
switch(msg)<br />
{<br />
case WM_CHAR:<br />
if(wParam=='a')<br />
{<br />
fCallOrgProc=FALSE;<br />
}<br />
break;<br />
}<br />
if(fCallOrgProc)<br />
{<br />
lResult=CallWindowProc(g_editwndOrg,hedit,msg,wParam,lParam);<br />
}<br />
return lResult;<br />
}<br />
<br />
|