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;
    }
    
  • 相关阅读:
    学习C#的一些笔记
    SQL高级应用
    SQL SERVER 视图
    ES5 Study
    面试官技巧
    WebServicexml操作
    用JS和HTML写自己的文本编辑器
    解决Win7 x64 VS2010调试网站出现 vs2010 未能将脚本调试器附加到计算机上的进程。已附加了一个调试器
    Microsoft.Practices.Unity实现代码依赖注入、XML依赖注入和AOP切面编程
    无法对数据库'XXX' 执行删除,因为它正用于复制"的解决方法
  • 原文地址:https://www.cnblogs.com/wucg/p/2353503.html
Copyright © 2011-2022 走看看