中科院-杨力祥视频教程 07课程
2014-03-13 17:03
447 查看
1.资源的使用方法 主要是 rc文件 resource.h文件
2.定时器SetTimer的使用的两种方法。
①定义ID号 #define ID_TIMERTWOSEC
②创建SetTimer 使用WM_CREATE.
③WM_TIMER
④KillTImer(hwnd,ID_TIMERTWOSEC)
3.扫雷程序的需求。
以下是测试程序SetTimer的使用方法:
2.定时器SetTimer的使用的两种方法。
①定义ID号 #define ID_TIMERTWOSEC
②创建SetTimer 使用WM_CREATE.
③WM_TIMER
④KillTImer(hwnd,ID_TIMERTWOSEC)
3.扫雷程序的需求。
以下是测试程序SetTimer的使用方法:
/*------------------------------------------------------------ 本程序主要用来测试 SetTimer函数的用法 ------------------------------------------------------------*/ #include <windows.h> #define ID_TIMERONESEC 1 #define ID_TIMERTWOSEC 2 LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; VOID CALLBACK TimerProc(HWND, UINT, UINT, DWORD); int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT ("SetTimer") ; 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 = NULL;//(HBRUSH) GetStockObject (WHITE_BRUSH) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = szAppName ; if (!RegisterClass (&wndclass)) { MessageBox (NULL, TEXT ("This program requires Windows NT!"), szAppName, MB_ICONERROR) ; return 0 ; } hwnd = CreateWindow (szAppName, // window class name TEXT ("The Hello Program"), // window caption WS_OVERLAPPEDWINDOW, // window style CW_USEDEFAULT, // initial x position CW_USEDEFAULT, // initial y position CW_USEDEFAULT, // initial x size CW_USEDEFAULT, // initial y size NULL, // parent window handle NULL, // window menu handle hInstance, // program instance handle NULL) ; // creation parameters 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) { HDC hdc ; PAINTSTRUCT ps ; RECT rect ; static RECT reBrush; static int cxClient,cyClient; static bool bColorRed = true; static HBRUSH hBrush; static int i = 0; switch (message) { case WM_CREATE: reBrush.bottom = 400; reBrush.left = 50; reBrush.right= 400; reBrush.top = 50; SetTimer(hwnd,ID_TIMERONESEC,1000,NULL); SetTimer(hwnd,ID_TIMERTWOSEC,2000,TimerProc); return 0 ; case WM_SIZE: cxClient = LOWORD(lParam); cyClient = HIWORD(lParam); return 0; case WM_TIMER: i++; if (i > 5) { KillTimer(hwnd,ID_TIMERONESEC); } bColorRed = !bColorRed; InvalidateRect(hwnd,&reBrush,FALSE); return 0; case WM_PAINT: MessageBeep(-1); hdc = BeginPaint (hwnd, &ps) ; GetClientRect(hwnd,&rect); hBrush = CreateSolidBrush(bColorRed ? RGB(255,0,0):RGB(0,0,255)); FillRect(hdc,&rect,hBrush); EndPaint (hwnd, &ps) ; DeleteObject(hBrush); return 0 ; case WM_DESTROY: KillTimer(hwnd,ID_TIMERONESEC); KillTimer(hwnd,ID_TIMERTWOSEC); PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; } VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT iTimerID, DWORD dwTime) { static bool bColorBlue = true; bColorBlue = !bColorBlue; RECT rect; rect.bottom = 300; rect.left = 500; rect.right = 700; rect.top = 200; HDC hdc = GetDC(hwnd); HBRUSH brush = CreateSolidBrush(bColorBlue ? RGB(0,225,0):RGB(0,0,255)); HBRUSH hOldBrush = (HBRUSH)SelectObject(hdc,brush); FillRect(hdc,&rect,brush); SelectObject(hdc,hOldBrush); ReleaseDC(hwnd,hdc); DeleteObject(brush); return ; }
相关文章推荐
- 中科院-杨力祥视频教程 03课程
- 中科院-杨力祥视频教程 05课程
- 中科院-杨力祥视频教程 01课程
- 中科院-杨力祥视频教程 04课程
- 中科院-杨力祥视频教程 02课程
- 中科院-杨力祥视频教程 08课程
- 3G手机Android应用开发视频教程_黎活明老师的视频(第六天课程)总共有八天课程
- 【备忘】【No6】一套不可多得的Lucene视频教程带课程源码
- 免费课程:Java高级教程-理论部分视频――私塾在线提供
- Yeslab现任明教教主数据中心第二门课程UCS 视频教程下载
- 北风网web前端开发培训课程 web前端开发实例视频教程下载
- Oracle数据库基础入门培训视频课程_Oracle视频教程培训
- Unity3D泰课在线 ARPG 课程《泰斗破坏神》系列视频教程附素...
- Oracle存储结构深入分析与管理_超越OCP精通Oracle视频教程培训07
- 3G手机Android应用开发视频教程_黎活明老师的视频(第五天课程)总共有八天课程
- 07-阻塞赋值与非阻塞赋值原理分析——小梅哥FPGA设计思想与验证方法视频教程配套文档
- 免费课程:Java高级教程-项目部分视频――私塾在线提供
- Yeslab现任明教教主数据中心Nexus课程 视频教程 下载