一直想对消息机制感兴趣Word格式.docx
《一直想对消息机制感兴趣Word格式.docx》由会员分享,可在线阅读,更多相关《一直想对消息机制感兴趣Word格式.docx(19页珍藏版)》请在冰豆网上搜索。
wcex.hCursor=LoadCursor(NULL,IDC_ARROW);
wcex.hbrBackground=(HBRUSH)(COLOR_WINDOW+2);
wcex.lpszClassName="
@PWDWIN@"
;
RegisterClassEx(&
wcex);
hWnd=CreateWindow("
"
Typethepassword..."
WS_OVERLAPPED,
GetSystemMetrics(SM_CXSCREEN)/2-100,
GetSystemMetrics(SM_CYSCREEN)/2-75,
200,150,
NULL,NULL,NULL,NULL);
if(!
hWnd)
return0;
CreateWindow("
BUTTON"
"
OK"
WS_CHILD|WS_VISIBLE|BS_TEXT,10,80,70,30,hWnd,(HMENU)10123,NULL,NULL);
Cancel"
WS_CHILD|WS_VISIBLE|BS_TEXT,110,80,70,30,hWnd,(HMENU)10456,NULL,NULL);
hEdit=CreateWindow("
EDIT"
NULL,WS_CHILD|WS_VISIBLE|WS_BORDER|ES_PASSWORD|ES_AUTOHSCROLL,10,20,170,25,hWnd,(HMENU)10789,NULL,NULL);
ShowWindow(hWnd,SW_SHOW);
UpdateWindow(hWnd);
SetFocus(hEdit);
while(GetMessage(&
msg,NULL,0,0))
{
TranslateMessage(&
msg);
DispatchMessage(&
}
if((int)msg.wParam==0)
exit(0);
DestroyWindow(hWnd);
}
LRESULTCALLBACKPwdWindow(HWNDhWnd,UINTmessage,WPARAMwParam,LPARAMlParam)
intwmId=-1;
charpwd[32];
switch(message)
caseWM_COMMAND:
{
wmId=LOWORD(wParam);
switch(wmId)
case10123:
(void)memset(pwd,0x00,sizeof(pwd));
GetWindowText(GetDlgItem(hWnd,10789),pwd,32);
if(strcmp(pwd,"
123456"
))
MessageBox(hWnd,"
Sorry!
Wrongpassword."
Password"
MB_ICONERROR);
else
:
:
MessageBoxA(hWnd,"
Rightpassword."
MB_OK);
}
break;
case10456:
PostQuitMessage(0);
default:
break;
default:
returnDefWindowProc(hWnd,message,wParam,lParam);
GetMessage取数据放入&
msg
TranslateMessage取&
msg进行一下处理
DispatchMessage取&
msg发送给处理循环消息PwdWindow
》》如图1
Msg结构为
tagMSGstruc;
(sizeof=0x1C)
00000000hwnddd?
;
offset
00000004messagedd?
00000008wParamdd?
0000000ClParamdd?
00000010timedd?
00000014ptPOINT?
0000001CtagMSGends
我们实际操作验证一下
1)对DispatchMessageA下条件记录断点
如图2
》》
dispatchMessageAlog
》》F9
log窗口观察生成很多记录
如下
Logdata
地址消息
77D196B8COND:
77D196B8CALL到DispatchMessageA来自pwddlgmo.0042D858
pMsg=MSG(C0C1)wParam=11lParam=1009EA
pMsg=MSG(C0CC)hw=1B097C("
CicMarshalWndMOKB"
)wParam=0lParam=0
pMsg=WM_MOUSEMOVEhw=100AA8("
)Keys=0X=103.Y=92.
pMsg=WM_PAINThw=100AA8("
)
pMsg=WM_PAINThw=F0A0A("
pMsg=WM_PAINThw=F0A22("
pMsg=MSG(C0C6)hw=1B097C("
)wParam=F8lParam=28
)Keys=0X=103.Y=91.
pMsg=WM_PAINThw=F0A94(class="
Edit"
pMsg=WM_TIMERhw=F0A60("
M"
)ID=1Callback=0
)Keys=0X=102.Y=91.
)Keys=0X=98.Y=90.
)Keys=0X=87.Y=91.
)Keys=0X=83.Y=91.
)Keys=0X=82.Y=91.
)Keys=0X=81.Y=91.
pMsg=WM_MOUSEMOVEhw=F0A0A("
)Keys=0X=68.Y=12.
)Keys=0X=66.Y=12.
)Keys=0X=64.Y=12.
)Keys=0X=63.Y=12.
)Keys=0X=62.Y=12.
)Keys=0X=61.Y=12.
)Keys=0X=60.Y=12.
)Keys=0X=66.Y=11.
)Keys=0X=80.Y=91.
)Keys=0X=89.Y=91.
)Keys=0X=95.Y=92.
)Keys=0X=98.Y=92.
)Keys=0X=100.Y=92.
)Keys=0X=105.Y=92.
)Keys=0X=109.Y=92.
pMsg=WM_MOUSEMOVEhw=F0A22("
)Keys=0X=2.Y=12.
)Keys=0X=7.Y=12.
)Keys=0X=9.Y=12.
)Keys=0X=10.Y=11.
)Keys=0X=13.Y=11.
)Keys=0X=18.Y=11.
)Keys=0X=19.Y=11.
)Keys=0X=20.Y=11.
)Keys=0X=21.Y=11.
)Keys=0X=22.Y=11.
)Keys=0X=13.Y=13.
)Keys=0X=2.Y=14.
pMsg=