#include <windows.h>
#pragma comment(lib, "winmm")
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd)
{
static TCHAR str1[] = TEXT("李赛赛爱邱坤小美女\n");
HWND hwnd1;
MSG msg1;//也是一个结构体
WNDCLASS wndclass;//窗口过程类是个结构体
wndclass.style = CS_HREDRAW | CS_VREDRAW;//窗口过程类初始化
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground =(HBRUSH) GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = str1;
if (!RegisterClass(&wndclass))//注册窗口过程类
{
MessageBox(NULL, TEXT("注册窗口过程类错误"), TEXT("错误"), 0);
return 0;
}
hwnd1 = CreateWindow(str1, L"邱坤小美女", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);//1标题
ShowWindow(hwnd1, nShowCmd);
UpdateWindow(hwnd1);
while (GetMessage(&msg1, NULL, 0, 0))//消息循环
{
TranslateMessage(&msg1);//调动消息
DispatchMessage(&msg1);//分派消息
}
return msg1.wParam;
//MessageBox(NULL, L"22222", L"1111111", 0);
return 0;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)//窗口回调函数
{
HDC hdc;
PAINTSTRUCT ps; //绘画结构
RECT rect;
switch (message)
{
case WM_CREATE:
PlaySound(TEXT("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC);
return 0;
case WM_PAINT://话绘画
hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rect);
DrawText(hdc, TEXT("我爱邱坤"), -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY://摧毁
PostQuitMessage(0);//快速
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
创建窗口的过程 windows程序的结构
最新推荐文章于 2023-03-19 19:53:23 发布