zoukankan      html  css  js  c++  java
  • WinAPI first gui, 2nd edition, from sun xin

    #include <windows.h>
    #include <stdio.h>
    
    LONG WINAPI WndProc(HWND, UINT,WPARAM,LPARAM);	//回调原型
    
    int WINAPI WinMain(      
    				   HINSTANCE 
    				   hInstance,
    				   HINSTANCE 
    				   hPrevInstance,
    				   LPSTR 
    				   lpCmdLine,
    				   int 
    				   nCmdShow
    				   )
    {
    
    	WNDCLASS wc;
    	HWND hwnd;
    	MSG msg;
    
    	//1.设计窗体
    	//wc.style = CS_VREDRAW | CS_HREDRAW;
    	wc.style = CS_HREDRAW;
    	wc.lpfnWndProc = (WNDPROC)WndProc;
    	wc.cbClsExtra = 0;
    	wc.cbWndExtra = 0;
    	wc.hInstance = hInstance;
    	//wc.hIcon = LoadIcon(NULL,IDI_WINLOGO);
    	wc.hIcon = LoadIcon(NULL,IDI_ERROR);
    	//wc.hCursor = LoadCursor(NULL,IDC_ARROW);
    	wc.hCursor = LoadCursor(NULL,IDC_CROSS);
    	//wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    	//wc.hbrBackground = (HBRUSH)(COLOR_GRAYTEXT);
    	wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    	wc.lpszMenuName = NULL;
    	wc.lpszClassName = "MyWndClass";
    
    	RegisterClass(&wc);		//2.注册窗体
    
    	hwnd = CreateWindow(	//3.创建窗体
    			"MyWndClass",			//WNDCLASS NAME
    			"SDK APPLICATION标题",		//WINDOW TITLE
    			//WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX,	//WINDOW STYLE
    			WS_TILEDWINDOW,
    			10,			//Horizontal position
    			20,			//Vertical position
    			800,			//Initial width
    			600,			//Initial height
    			HWND_DESKTOP,			//Handle of parent window
    			NULL,					//Menu handle
    			hInstance,				//Application's instance handle
    			NULL					//Window-creation data
    		);
    
    
    	ShowWindow(hwnd,nCmdShow);	//4.显示更新窗体
    	UpdateWindow(hwnd);
    
    	while(GetMessage(&msg,NULL,0,0)){		//5.消息循环
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    	return msg.wParam;
    }
    
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message,WPARAM wParam,LPARAM lParam){
    	
    	PAINTSTRUCT ps;
    	HDC hdc;
    	const char chMsg[]="我是中国人";
    	switch(message){
    	case WM_CHAR:
    		char szCh[20];
    		sprintf(szCh,"char is %d",wParam);
    		MessageBox(hwnd,szCh,"info",0);
    		break;
    	case WM_LBUTTONDOWN:
    		MessageBox(hwnd,"Mouse Clicked","提示",0);
    		hdc=GetDC(hwnd);
    		TextOut(hdc,0,50,chMsg,strlen(chMsg));
    		ReleaseDC(hwnd,hdc);
    		break;
    	case WM_PAINT:
    		hdc=BeginPaint(hwnd,&ps);
    		Ellipse(hdc,0,0,200,100);
    		EndPaint(hwnd,&ps);
    		break;
    	case WM_CLOSE:
    		if(IDYES == MessageBox(hwnd,"确定退出吗?","确认",MB_YESNO)){
    			DestroyWindow(hwnd);
    		}		
    		break;
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		break;
    	default:
    		return DefWindowProc(hwnd,message,wParam,lParam);
    	}
    	return 0;
    }
    
  • 相关阅读:
    使用基于关系的选择器和伪类选择器创建纯CSS无JavaScript的鼠标移动到上面即可显示的下拉菜单
    git学习教程
    笔记
    luogu P1429 平面最近点对(加强版)
    可持久化数据结构
    luogu P4137 Rmq Problem / mex
    置换群(Burnside引理+Polya定理)
    luogu P1053 篝火晚会
    luogu P3238 [HNOI2014]道路堵塞
    luogu P3812 【模板】线性基
  • 原文地址:https://www.cnblogs.com/wucg/p/2353503.html
Copyright © 2011-2022 走看看