中科院-杨力祥视频教程07课程

来源:互联网 发布:kwic软件体系结构 编辑:程序博客网 时间:2024/04/28 01:40

1.资源的使用方法 主要是 rc文件 resource.h文件


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 2LRESULT 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 nameTEXT ("The Hello Program"), // window captionWS_OVERLAPPEDWINDOW,        // window styleCW_USEDEFAULT,              // initial x positionCW_USEDEFAULT,              // initial y positionCW_USEDEFAULT,              // initial x sizeCW_USEDEFAULT,              // initial y sizeNULL,                       // parent window handleNULL,                       // window menu handlehInstance,                  // program instance handleNULL) ;                     // creation parametersShowWindow (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 RECTreBrush;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 ;}


0 0
原创粉丝点击