子窗口回调函数拦截WM_DESTROY消息
主函数中将获取消息、发送消息的过程放入死循环中,并在死循环中不停地给子窗口发送WM_PAINT,重绘整个屏幕
子窗口收到WM_PAINT消息之后将整个屏幕涂黑
本来准备用定时器做的,但是发现并不好使
这个程序一旦运行,我不知道有什么方法来结束它……
最后只能重启虚拟机。。。
恶作剧应该有用吧,嘎嘎
1 /*------------------------------------------------------------ 2 HELLOWIN.C -- Displays "Hello, Windows 98!" in client area 3 (c) Charles Petzold, 1998 4 ------------------------------------------------------------*/ 5 6 #include <windows.h> 7 8 #define ID_TIMER 1 9 10 LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; 11 12 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, 13 PSTR szCmdLine, int iCmdShow) 14 { 15 static TCHAR szAppName[] = TEXT ("HelloWin") ; 16 HWND hwnd ; 17 MSG msg ; 18 WNDCLASS wndclass ; 19 20 wndclass.style = CS_HREDRAW | CS_VREDRAW ; 21 wndclass.lpfnWndProc = WndProc ; 22 wndclass.cbClsExtra = 0 ; 23 wndclass.cbWndExtra = 0 ; 24 wndclass.hInstance = hInstance ; 25 wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; 26 wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; 27 wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ; 28 wndclass.lpszMenuName = NULL ; 29 wndclass.lpszClassName = szAppName ; 30 31 if (!RegisterClass (&wndclass)) 32 { 33 MessageBox (NULL, TEXT ("This program requires Windows NT!"), 34 szAppName, MB_ICONERROR) ; 35 return 0 ; 36 } 37 38 hwnd = CreateWindow (szAppName, // window class name 39 TEXT ("The Hello Program"), // window caption 40 WS_OVERLAPPEDWINDOW, // window style 41 CW_USEDEFAULT, // initial x position 42 CW_USEDEFAULT, // initial y position 43 CW_USEDEFAULT, // initial x size 44 CW_USEDEFAULT, // initial y size 45 NULL, // parent window handle 46 NULL, // window menu handle 47 hInstance, // program instance handle 48 NULL) ; // creation parameters 49 50 ShowWindow (hwnd, iCmdShow) ; 51 UpdateWindow (hwnd) ; 52 53 while (1) 54 { 55 GetMessage (&msg, NULL, 0, 0); 56 TranslateMessage (&msg) ; 57 DispatchMessage (&msg) ; 58 PostMessage( hwnd, WM_PAINT, 0, 0); 59 } 60 return msg.wParam ; 61 } 62 63 LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) 64 { 65 HDC hdc ; 66 PAINTSTRUCT ps ; 67 RECT rect ; 68 HDC hdcScreen ; 69 70 switch (message) 71 { 72 case WM_CREATE: 73 //SetTimer (hwnd, ID_TIMER, 1, NULL) ; 74 return 0 ; 75 76 /* case WM_TIMER : 77 InvalidateRect (hwnd, NULL, FALSE) ; 78 return 0 ; */ 79 case WM_PAINT: 80 hdc = BeginPaint (hwnd, &ps) ; 81 EndPaint (hwnd, &ps) ; 82 83 //获取整个屏幕的设备描述表 84 hdcScreen = CreateDC (TEXT ("DISPLAY"), NULL, NULL, NULL) ; 85 rect.left = rect.top = 0; 86 rect.right = GetDeviceCaps (hdcScreen, HORZRES) ; 87 rect.bottom = GetDeviceCaps (hdcScreen, VERTRES) ; 88 FillRect (hdcScreen, &rect, (HBRUSH)GetStockObject(BLACK_BRUSH)) ; 89 DeleteDC (hdcScreen) ; 90 return 0 ; 91 92 case WM_DESTROY: 93 //KillTimer (hwnd, ID_TIMER) ; 94 //PostQuitMessage (0) ; 95 return 0 ; 96 } 97 return DefWindowProc (hwnd, message, wParam, lParam) ; 98 }