耐得住寂寞,禁得起诱惑,这就是程序人生步骤:1.在WinMain中定义各种变量2.注册窗口类RegisterClass3.创建窗口CreateWindow4.显示窗口和更新窗口下面是小编为大家整理的2023年C语言怎样创建windows窗口(完整),供大家参考。
耐得住寂寞,禁得起诱惑,这就是程序人生
步骤:
1.在WinMain中定义各种变量
2.注册窗口类RegisterClass
3.创建窗口CreateWindow
4.显示窗口和更新窗口
复制代码 代码如下:
ShowWindow hwnd, iCmdShow ;
UpdateWindow hwnd ;
5.消息循环
复制代码 代码如下:
while GetMessage &msg, NULL, 0, 0
TranslateMessage &msg ;
DispatchMessage &msg ;
完整代码:
复制代码 代码如下:
#include
LRESULT CALLBACK MyProcHWND hwnd,UINT message,WPARAM wParam,LPARAM lParam;
int WINAPI WinMainHINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd
MSG msg;
HWND hwnd;
static TCHAR szAppName[] = "hl";
WNDCLASS wndclass;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.lpfnWndProc = MyProc;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIconNULL,IDI_APPLICATION;
wndclass.hCursor = LoadCursorNULL,IDC_ARROW;
wndclass.hbrBackground= HBRUSHGetStockObjectWHITE_BRUSH;
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName= szAppName;
if!RegisterClass&wndclass
MessageBoxNULL,TEXT"error",TEXT"title",MB_ICONERROR;
return 0;
hwnd = CreateWindowszAppName,
TEXT"Hello",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
;
ShowWindowhwnd,nShowCmd;
UpdateWindowhwnd;
whileGetMessage&msg,hwnd,0,0
TranslateMessage&msg;
DispatchMessage&msg;
return msg.wParam;
LRESULT CALLBACK MyProcHWND hwnd,UINT message,WPARAM wParam,LPARAM lParam
switchmessage
case WM_DESTROY:
PostQuitMessage0;
return 0;
return DefWindowProchwnd,message,wParam,lParam;
推荐访问:创建 窗口 语言 C语言怎样创建windows窗口 C语言怎样创建windows窗口 c语言编写windows窗口 c语言如何创建窗口 C语言创建窗口