DEMO6_1B.C
资源名称:winpaint.zip [点击查看]
上传用户:cncajx
上传日期:2007-01-03
资源大小:190k
文件大小:4k
源码类别:
GDI/图象编程
开发平台:
Visual C++
- 1 /****************************************************************/
- 2 /* Demo6_1b --- Play MetaFile */
- 3 /****************************************************************/
- 4
- 5 #include <windows.h>
- 6 #include "demo6_1b.h"
- 7
- 8 int PASCAL WinMain(HANDLE, HANDLE, LPSTR, int);
- 9 long FAR PASCAL MainWndProc(HWND, unsigned, WORD, LONG);
- 10
- 11
- 12 /****************************************************************/
- 13 /* WinMain() */
- 14 /****************************************************************/
- 15
- 16 int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
- 17 LPSTR lpszCmdLine, int nCmdShow)
- 18 {
- 19 WNDCLASS wclass;
- 20 MSG msg;
- 21 HWND hWnd;
- 22 char szName[] = "Demo6_1b";
- 23
- 24 if (!hPrevInstance)
- 25 {
- 26 wclass.style = CS_HREDRAW | CS_VREDRAW;
- 27 wclass.lpfnWndProc = MainWndProc;
- 28 wclass.cbClsExtra = 0;
- 29 wclass.cbWndExtra = 0;
- 30 wclass.hInstance = hInstance;
- 31 wclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- 32 wclass.hCursor = LoadCursor(NULL, IDC_ARROW);
- 33 wclass.hbrBackground = GetStockObject(WHITE_BRUSH);
- 34 wclass.lpszMenuName = szName;
- 35 wclass.lpszClassName = szName;
- 36
- 37 if (!RegisterClass (&wclass))
- 38 return (FALSE);
- 39 }
- 40
- 41 hWnd = CreateWindow(
- 42 szName,
- 43 "Play MetaFile",
- 44 WS_OVERLAPPEDWINDOW,
- 45 CW_USEDEFAULT,
- 46 CW_USEDEFAULT,
- 47 CW_USEDEFAULT,
- 48 CW_USEDEFAULT,
- 49 NULL,
- 50 NULL,
- 51 hInstance,
- 52 NULL );
- 53
- 54 if (!hWnd)
- 55 return (FALSE);
- 56
- 57 ShowWindow(hWnd, nCmdShow);
- 58 UpdateWindow(hWnd);
- 59
- 60 while (GetMessage(&msg, NULL, NULL,NULL))
- 61 {
- 62 TranslateMessage(&msg);
- 63 DispatchMessage(&msg);
- 64 }
- 65 return (msg.wParam);
- 66 }
- 67
- 68
- 69
- 70 /****************************************************************/
- 71 /* MainWndProc() */
- 72 /****************************************************************/
- 73
- 74 long FAR PASCAL MainWndProc(HWND hWnd, unsigned message,
- 75 WORD wParam, LONG lParam)
- 76 {
- 77 PAINTSTRUCT ps;
- 78 HDC hDC;
- 79 static HANDLE hMF;
- 80 char Filename[] = "demo6_1.mf";
- 81
- 82 switch (message)
- 83 {
- 84 case WM_CREATE :
- 85 srand(LOWORD(GetCurrentTime()));
- 86 hMF = GetMetaFile(Filename);
- 87 if (hMF == 0)
- 88 {
- 89 char Str[100];
- 90
- 91 sprintf(Str, "File %s not found !",
- 92 Filename);
- 93 MessageBox(hWnd,
- 94 Str,
- 95 NULL,
- 96 MB_OK | MB_ICONHAND);
- 97 DestroyWindow(hWnd);
- 98 }
- 99 return (0);
- 100
- 101 case WM_COMMAND :
- 102 switch(wParam)
- 103 {
- 104 case IDM_EXIT :
- 105 DestroyWindow (hWnd);
- 106 break;
- 107
- 108 case IDM_DRAW :
- 109 InvalidateRect(hWnd, NULL, TRUE);
- 110 break;
- 111 }
- 112 return (0);
- 113
- 114 case WM_PAINT :
- 115 hDC = BeginPaint(hWnd, &ps);
- 116
- 117 PlayMetaFile(hDC, hMF);
- 118
- 119 EndPaint(hWnd, &ps);
- 120 return (0);
- 121
- 122 case WM_DESTROY :
- 123 DeleteMetaFile(hMF);
- 124 unlink(Filename);
- 125 PostQuitMessage(0);
- 126 return (0);
- 127
- 128 default :
- 129 return (DefWindowProc(hWnd, message, wParam, lParam));
- 130 }
- 131 }