zoukankan      html  css  js  c++  java
  • 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);
    }
    
  • 相关阅读:
    xcode debug
    ios 使用Quartz 2D画虚线
    ios UIGestureRecognizer
    ios 实现带矩形框的屏幕截图
    ios UISegemetedControl
    centos最小安装之后无法使用ifconfig
    无线LoRa智能远传水表
    智能水表188协议汇总
    无线LoRa远传智能水表
    静电除尘器除尘原理
  • 原文地址:https://www.cnblogs.com/neking/p/2518734.html
Copyright © 2011-2022 走看看