vc子窗口SetFocus后标题栏仍为灰色,代码有何问题?(50分)

T

tropic

Unregistered / Unconfirmed
GUEST, unregistred user!
#include <windows.h>
#define ID_TEXT1 1
#define ID_TEXT2 2
#define ID_EXIT 3
#define WM_ACTION (WM_USER+1)
char szChildTextClassName[]="TextClass";
char szChildExitClassName[]="ExitClass";
int idFocus;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
LRESULT CALLBACK ChildText(HWND,UINT,WPARAM,LPARAM);
LRESULT CALLBACK ChildExit(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
LPSTR lpCmdLine,int nShowCmd)
{
char szClassName[]="SimChildWinSampleClass";
char szAppName[]="SimChildWinSample";
WNDCLASS wc;
MSG msg;
HWND hWnd;
wc.style=CS_HREDRAW|CS_VREDRAW;
wc.lpfnWndProc=(WNDPROC)WndProc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance=hInstance;
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName=NULL;
wc.lpszClassName=szClassName;
if (!RegisterClass(&amp;wc)) return 0;
/**********************************************/
wc.style=CS_HREDRAW|CS_VREDRAW;
wc.lpfnWndProc=(WNDPROC)ChildText;
wc.cbClsExtra=sizeof(long);
wc.cbWndExtra=sizeof(long);
wc.hIcon=NULL;
wc.lpszClassName=szChildTextClassName;
if (!RegisterClass(&amp;wc)) return 0;
/**********************************************/
wc.lpfnWndProc=(WNDPROC)ChildExit;
wc.cbClsExtra=0;
wc.lpszClassName=szChildExitClassName;
if (!RegisterClass(&amp;wc)) return 0;
hWnd=CreateWindow(szClassName,
"Simple Child Window Sample Program",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd,nShowCmd);
UpdateWindow(hWnd);
while( GetMessage(&amp;msg,NULL,0,0) )
{
TranslateMessage(&amp;msg);
DispatchMessage(&amp;msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
static HWND hwndText1,hwndText2,hwndExit;
static int cxClient,cyClient;
switch(message)
{
case WM_CREATE:
hwndText1=CreateWindow(szChildTextClassName,
"TEXTChild1",
WS_CHILD|WS_VISIBLE|WS_CAPTION,
0,
0,
0,
0,
hWnd,
(HMENU)ID_TEXT1,
(HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE),
NULL);
hwndText2=CreateWindow(szChildTextClassName,
"TEXTChild2",
WS_CHILD|WS_VISIBLE|WS_CAPTION,
0,
0,
0,
0,
hWnd,
(HMENU)ID_TEXT2,
(HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE),
NULL);
hwndExit=CreateWindow(szChildExitClassName,
"EXIT",
WS_CHILD|WS_VISIBLE|WS_CAPTION,
0,
0,
0,
0,
hWnd,
(HMENU)ID_EXIT,
(HINSTANCE)GetWindowLong(hWnd,GWL_HINSTANCE),
NULL);
break;
case WM_ACTION:
switch(wParam)
{
case ID_TEXT1:
InvalidateRect(hWnd,NULL,TRUE);
break;
}
break;
case WM_SIZE:
cxClient=LOWORD(lParam);
cyClient=HIWORD(lParam);
MoveWindow(hwndText1,cxClient/8,cyClient/8,cxClient/2,cyClient/4,TRUE);
MoveWindow(hwndText2,cxClient/8,5*cyClient/8,cxClient/2,cyClient/4,TRUE);
MoveWindow(hwndExit,cxClient*5/8,cyClient/8,cxClient/2,cyClient/4,TRUE);
break;
default:
return DefWindowProc(hWnd,message,wParam,lParam);
}
return 0;
}
LRESULT CALLBACK ChildText(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_SETTEXT:
InvalidateRect(hWnd,NULL,TRUE);
break;
case WM_CREATE:
SetClassLong(hWnd,0,0);
SetWindowLong(hWnd,0,0);
break;
case WM_LBUTTONUP:
SetFocus(hWnd);
SetClassLong(hWnd,0,GetClassLong(hWnd,0)+1);
break;
default:
return DefWindowProc(hWnd,message,wParam,lParam);
}
return 0;
}
LRESULT CALLBACK ChildExit(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_CREATE:
SetWindowLong(hWnd,0,0);
break;
default:
return DefWindowProc(hWnd,message,wParam,lParam);
}
return 0;
}
是ChildText函数有问题吗?
 
我没做过SDK,不知道加个 SetActiveWindow(hWnd) 行不行
 
TO:zw84611
不行,必须发送 WM_NCACTIVATE 消息。
 
跟踪一下代码执行了没有?????
 
另外说说你程序的意思!
 
顶部