#include #include // 全域性變數
rect rc; //記錄滾屏的矩形區域
int xchar, ychar; //文字輸入點座標
wndclas*** wnd; //視窗類結構變數
//函式宣告
lresult callback wndproc(hwnd, uint, wparam, lparam);
bool myregisterclass(hinstance hinstance);
bool initinstance(hinstance hinstance,int icmdshow);
//函式:winmain
//作用:入口函式
int winapi winmain(hinstance hinstance,hinstance hprevinstance,lpstr szcmdline,int icmdshow)
if(!initinstance(hinstance,icmdshow))
while (getmessage (&msg, null, 0, 0))
return msg.wparam;
}//函式:showkey
//作用:實現在視窗中顯示按鍵資訊
void showkey (hwnd hwnd, int itype,char *szmessage,wparam wparam,lparam lparam)
; char szbuffer[80];
hdc hdc;
scrollwindowex(hwnd, 0, -ychar, &rc,&rc,null,null,sw_invalidate);
hdc = getdc(hwnd);
selectobject (hdc, getstockobject (system_fixed_font));
textout(hdc,
xchar,
rc.bottom-ychar,
szbuffer,
wsprintf(szbuffer,
szformat[itype],
szmessage,
wparam,
(byte)(wparam),
loword(lparam),
hiword(lparam)&0xff,
(pstr)(0x01000000&lparam?"是":"否"),
(pstr)(0x20000000&lparam?"是":"否"),
(pstr)(0x40000000&lparam?"按下":"抬"),
(pstr)(0x80000000&lparam?"按下":"抬起")));
releasedc (hwnd, hdc);
validaterect (hwnd, null);
}//函式:wndproc
//作用:處理主視窗的訊息
lresult callback wndproc (hwnd hwnd, uint imsg, wparam wparam, lparam lparam)
else
/*if(wparam==13)
*///處理鍵盤上某一鍵按下的訊息
showkey (hwnd, 0, "wm_keydown",wparam, lparam);
return 0;
case wm_keyup:
//處理鍵盤上某一按下鍵被釋放的訊息
//傳送c
//postmessage(hwnd,wm_keydown,'a',0x2e0001);
//showkey (hwnd, 0, "wm_keyup", wparam, lparam);
return 0;
case wm_char:
//處理擊鍵過程中產生的非系統鍵的可見字元訊息
//showkey(hwnd, 1, "wm_char", wparam, lparam);
return 0;
case wm_deadchar:
//處理擊鍵過程中產生的非系統鍵"死字元"訊息
//showkey (hwnd, 1, "wm_deadchar", wparam, lparam);
return 0;
case wm_syskeydown:
//處理系統鍵按下的訊息
showkey (hwnd, 0, "wm_syskeydown",wparam, lparam);
break;
case wm_syskeyup:
//處理系統鍵抬起的訊息
showkey (hwnd, 0, "wm_syskeyup", wparam, lparam);
break;
case wm_syschar://處理系統鍵可見字元訊息
showkey (hwnd, 1, "wm_syschar", wparam, lparam);
break;
case wm_sysdeadchar://處理系統鍵"死字元"訊息
showkey (hwnd, 1, "wm_sysdeadchar", wparam, lparam);
break;
case wm_destroy:
//處理結束應用程式的訊息
postquitmessage (0);
return 0;
} return defwindowproc (hwnd, imsg, wparam, lparam);
}//函式:myregisterclass
//作用:註冊視窗類
bool myregisterclass(hinstance hinstance)
//函式:initinstance
//作用:建立主視窗
bool initinstance(hinstance hinstance,int icmdshow)
showwindow (hwnd, icmdshow);
updatewindow (hwnd);
return true;
}
C Win32訊息迴圈過程
include lresult callback windowproc hwnd hwnd,訊息所屬的視窗控制代碼 uint umsg,具體訊息名稱 wparam wparam,lparam lparam case wm keydown messagebox hwnd,l 鍵盤按下 l 鍵盤按下 m...
windows訊息機制
一 windows中有乙個系統訊息佇列,對於每乙個正在執行的windows應用程式,系統為其建立乙個 訊息佇列 即應用程式佇列,用來存放該程式可能 建立的各種視窗的訊息。應用程式中含有一段稱作 訊息迴圈 的 用來從訊息佇列中檢索這些訊息並把它們分發到相應的視窗函式中。二 windows為當前執行的每...
訊息機制 WSAAsyncSelect
訊息機制 wsaasyncselect wsaasyncselect基於windows訊息機制非同步i o模型,為特定網路事件指定系統通知資訊.函式定義 int wsaasyncselect socket s,hwnd hwnd,unsigned int wmsg,long levent 1 引數4...