c建立win視窗

2022-03-09 16:19:10 字數 1316 閱讀 1037

windows程式設計示例:

1 #include "

windows.h"2

#pragma comment(lib, "winmm")34

lresult callback wndproc(hwnd, uint, wparam, lparam);56

int winapi winmain(hinstance hinstance, hinstance hprevinstance, pstr szcmdline, int

icmdshow)729

31 text("

hello world"),

3233

cw_usedefault,

34cw_usedefault,

35640,36

480,

37null,

38null,

39hinstance,

40null);

41showwindow(hwnd, icmdshow);

42updatewindow(hwnd);

4344

while (getmessage(&msg,null,0,0

))45

4950

return

msg.wparam;51}

5253

lresult callback wndproc(hwnd hwnd, uint message, wparam wparam, lparam lparam)

5474

return

defwindowproc(hwnd, message, wparam, lparam);

75 }

view code

建立步驟:

1.建立乙個wndclass結構體

2.使用registerclass註冊結構體

3.呼叫createwindow建立窗體並將控制代碼賦值給乙個hwnd結構體

4.呼叫showwindow顯示窗體

5.呼叫updatewindow更新窗體

6.執行訊息迴圈,使用getmessage獲取訊息,使用translatemessage轉換訊息,使用dispatchmessage分發訊息

ps:如果不加#pragma comment(lib, "winmm"),會報錯

錯誤 1 error lnk2019: 無法解析的外部符號 __imp__playsounda@12,該符號在函式 _wndproc@16 中被引用 e:\project\cwin\cwin\main.obj cwin

原因:呼叫了乙個多**函式,而多**物件庫並未包含在預設專案內

WIN32視窗建立

win32視窗建立過程 1 定義視窗類 在msdn中找到函式原型 winmain 2 定義視窗處理函式 在msdn中找到原型 windowproc 3 設計視窗類 4 註冊視窗類 registerclass registerclas 5 建立視窗 createwindow createwindowe...

建立Win32視窗程式

建立win32視窗程式的步驟 建立win32視窗程式 int winapi winmain hinstance hinstance,hinstance hprevinstance,lpstr lpcmdline,int nshowcmd 構造視窗 winmain wndclas wndclass w...

win32開發(建立子視窗)

在win32中,有的時候需要建立額外的子視窗。所謂子視窗的概念,就是視窗本身不會超出母視窗的邊界,所有的操作都是在母視窗裡面完成的。子視窗可以用os提供的預設型別來完成,也可以自定義型別來完成,即自定義wndclas 常用的子視窗有button combobox edit listbox stati...