• Windows程序设计学习(2)


    一个Windows程序的开发步骤

    #include <windows.h>
    //1.窗口类需要一个窗口过程,所以先声明一个窗口过程函数
    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 app_name[] = TEXT("HelloWin");
    	
    	//2.注册一个窗口类
    	WNDCLASS wndclass =
    		{
    			CS_HREDRAW | CS_VREDRAW,
    			WndProc,
    			0,
    			0,
    			hInstance,
    			LoadIcon(nullptr, IDI_APPLICATION),
    			LoadCursor(nullptr, IDC_ARROW),
    			(HBRUSH)GetStockObject(WHITE_BRUSH),
    			nullptr,
    			app_name
    		};
    	if(!RegisterClass(&wndclass))
    	{
    		return 0;
    	}
    
    	//3.创建窗口并显示
    	HWND hwnd = CreateWindow(app_name, TEXT("The First Window"),
    							 WS_OVERLAPPEDWINDOW,
    							 CW_USEDEFAULT,
    							 CW_USEDEFAULT,
    							 CW_USEDEFAULT,
    							 CW_USEDEFAULT,
    							 nullptr,
    							 nullptr,
    							 hInstance,
    							 nullptr);
    	ShowWindow(hwnd, nShowCmd);
    	UpdateWindow(hwnd);
    
    	//4.循环消息队列
    	MSG msg; //消息结构
    	while(GetMessage(&msg, nullptr, 0, 0))
    	{
    		TranslateMessage(&msg);//转换某些键盘消息
    		DispatchMessage(&msg); //将消息发送给窗口过程
    	}
    
    	return msg.wParam;
    
    }
    
    //5.窗口过程
    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"), nullptr, SND_FILENAME|SND_ASYNC);
    		return 0;
    	case WM_PAINT:
    		{
    			hdc = BeginPaint(hwnd, &ps);
    			GetClientRect(hwnd, &rect);
    			DrawText(hdc, TEXT("Hello, Windows7!"), -1, &rect, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
    			EndPaint(hwnd, &ps);
    			return 0;
    		}
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		return 0;
    	}
    
    	return DefWindowProc(hwnd, message, wParam, lParam);
    }
    
  • 相关阅读:
    移动端a标签点击图片有阴影处理
    sublime vue 语法高亮插件安装
    mongodb 命令
    MongoDB给数据库创建用户
    windows32位系统 安装MongoDB
    ES6之主要知识点(十)Proxy
    ES6之主要知识点(九)Set和Map
    ES6之主要知识点(八)Symbol
    ES6之主要知识点(七)对象
    Ueditor 1.4.3 插入表格后无边框无颜色,不能正常显示
  • 原文地址:https://www.cnblogs.com/neking/p/2518734.html
Copyright © 2020-2023  润新知