#include
LRESULT CALLBACK WndProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) {
HWND hwndButton, hwndButton1,hwndButton2;
switch (umsg) {
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_CREATE:
hwndButton = CreateWindow("button", "anniu_1", WS_CHILD | WS_VISIBLE,
0, 0, 60, 30, hwnd, (HMENU)0, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
hwndButton1 = CreateWindow("button", "anniu_2", WS_CHILD | WS_VISIBLE,
70, 0, 60, 30, hwnd, (HMENU)0, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
hwndButton2 = CreateWindow("button", "anniu_3", WS_CHILD | WS_VISIBLE,
140, 0, 60, 30, hwnd, (HMENU)0, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
}
return DefWindowProc(hwnd, umsg, wParam, lParam);
}
int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
_In_ LPSTR lpCmdLine, _In_ int nCmdShow) {
WNDCLASS wc = { 0 };
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)(NULL_BRUSH);
wc.hCursor = NULL;
wc.hIcon = NULL;
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = "Main";
wc.lpszMenuName = NULL;
wc.style = CS_HREDRAW | CS_VREDRAW;//当窗口水平或垂直大小发生变化时,重绘窗口
RegisterClass(&wc);//将窗口类函数写入系统内核
HWND hwnd = CreateWindow("Main", "123", WS_OVERLAPPEDWINDOW, 0, 0, 500, 400, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
MSG msg = { 0 };
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
1.在C语言中,函数的定义顺序是有讲究的:默认情况下,只有后面定义的函数才可以调用前面定义过的函数
第5行定义的main函数调用了第1行的sum函数,这是合法的。如果调换sum函数和main函数的顺序,在标准的C编译器环境下是不合法的(在GCC编译器环境下只是一个警告)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)