Win32模板程序
2015-04-29 11:52
232 查看
#pragma comment(lib,"user32.lib") #pragma comment(lib,"gdi32.lib") #include <windows.h> #include <math.h> #define NUM 1000 #define TWOPI (2*3.14159) LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT("SineWave"); HWND hwnd; MSG msg; WNDCLASS wndclass; wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = szAppName; if (!RegisterClass(&wndclass)) { MessageBox(NULL, TEXT("Program requires Windows NT!"), szAppName, MB_ICONERROR); return 0; } hwnd = CreateWindow(szAppName, TEXT("Sine Wave Using Polyline"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); ShowWindow(hwnd, iCmdShow); UpdateWindow(hwnd); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static int cxClient, cyClient; HDC hdc; int i; PAINTSTRUCT ps; POINT apt[NUM]; switch (message) { case WM_SIZE: cxClient = LOWORD(lParam); cyClient = HIWORD(lParam); return 0; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); MoveToEx(hdc, 0, cyClient/2, NULL); LineTo(hdc, cxClient, cyClient/2); for (i = 0; i < NUM; i++) { apt[i].x = i*cxClient/NUM; apt[i].y = (int)(cyClient / 2 * (1-sin(TWOPI * i / NUM))); } Polyline(hdc, apt, NUM); EndPaint(hwnd, &ps); return 0; case WM_COMMAND: return 0; case WM_CREATE: return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, message, wParam, lParam); }
相关文章推荐
- win32强化练习2.0_手工打造自己的对话框程序模板
- Win32编程模板程序
- win32 Application 模板 建立 MFC程序
- VS2013 + Win8.1 创建的Win32 SDK程序模板
- Win32 SDK 实现UDP聊天室程序(二)
- 微信小程序模板和模块化用法实例分析
- Win32程序函数调用时堆栈变化情况
- 帝国 标签模板 使用程序代码 去除html标记 并 截取字符串
- cocos2d-x win32程序和NDK交叉编译
- WIN32程序挂钩SetLastError,输出错误描述到控制台
- 帝国 标签模板 使用程序代码 自定义 时间显示方式
- cocos2d-x的android环境搭建与win32程序移植至android(查漏补缺版)
- win32控制台程序中,使用MFC的方法
- [置顶] win32命令行小程序获取指定文件夹或者目录下面的所有文件大小,文件数量,目录数量
- 简单收集微信小程序formId,解决发送模板消息不够用的问题
- WIN32程序挂钩SetLastError,输出错误描述到控制台
- [cocos2d-x 学习] 第一个cocos2d-x win32程序和Android NDK交叉编译
- 如何在Win32窗口程序中发命令打开一个控制台,往里面打印(printf())输出一些数据
- 用VS2012或VS2013在win7下编写的程序在XP下运行就出现“不是有效的win32应用程序
- MATLAB作图之贝塞尔曲线(beizer)模板程序+效果图