Win32编程模板程序
2014-03-25 17:01
232 查看
该程序是由VC生成的,经过本人修改,精简了内容,将必要原程序都集中于一个文件。
#include <windows.h> // C 运行时头文件 #include <stdlib.h> #include <malloc.h> #include <memory.h> #include <tchar.h> //GDI+包含项 #include <gdiplus.h> using namespace Gdiplus; #pragma comment (lib,"gdiplus.lib") // 全局变量: HINSTANCE hInst; // 当前实例 TCHAR *szTitle="HelloWorld"; // 标题栏文本 TCHAR *szWindowClass="MyClass"; // 主窗口类名 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; switch (message) { case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: 在此添加任意绘图代码... EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = NULL; wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = NULL; wcex.lpszClassName = szWindowClass; wcex.hIconSm = NULL; return RegisterClassEx(&wcex); } BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; hInst = hInstance; // 将实例句柄存储在全局变量中 hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE; } int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { //////////////GDI+代码////////////////// GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); ////////////////////////////////////////// MSG msg; // 初始化全局字符串 MyRegisterClass(hInstance); // 执行应用程序初始化: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } // 主消息循环: while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } //////////////////////////////////////////// GdiplusShutdown(gdiplusToken); return (int) msg.wParam;
相关文章推荐
- Win32 api编程模板和 加速键编程例子
- Win32 API编程简介Demo程序
- 【VC编程】笔记2--SDK编程的模板程序/MFC消息映射机制的本质解析
- win32编程中对话框处理函数最后的返回值为TRUE导致了程序异常
- VC++孙鑫-第三章-MFC AppWizard的原理与MFC程序框架-讲WIN32SDK和MFC编程的相同过程
- VS2013 + Win8.1 创建的Win32 SDK程序模板
- WIN32 编程示例:嵌入式式软件开发程序入门(完全从网上copy的文章)
- 解决Win32 SDK编程添加list control控件程序无法运行的问题 . 和如何画进度条
- Win32 API 窗口编程模板
- VC程序在Win32环境下动态链接库(DLL)编程原理
- 【C/C++学院】(26)Oracle数据库编程--程序模板c/cpp
- Win32程序文本输出 --设备无关的编程基础、滚动条
- Win32模板程序
- win32强化练习2.0_手工打造自己的对话框程序模板
- C/C++怎样编写高质量的程序:头文件和源文件模板------高质量C++/C编程指南-第1章-文件结构
- WIN32编程--用Windows API实现Windows NT服务的程序框架
- 解决Win32 SDK编程添加list control控件程序无法运行的问题
- 求解,windows编程中,win32程序,如何将字符串按一个一个字符逐个动态输出?
- 基于win32的socket编程及程序实现
- Win32 API编程简介Demo程序