|
|
1.1.1.2 ! root 1: /******************************************************************************\ 1.1 root 2: * 3: * PROGRAM: MAIN.C 4: * 5: * PURPOSE: To test the resource-only DLL "THE_DLL.DLL". 6: * 7: * FUNCTIONS: WinMain() - initialization, create window, msg loop 8: * MainWndProc() - processes main window msgs 9: * DrawBitmap() - draw a specified bitmap in a specified DC 10: * 11: * COMMENTS: Loads the bitmap, the cursor, and the icon from 12: * THE_DLL.DLL. Uses the first two ni registering the 13: * app's window class. Uses the bitmap when painting 14: * the client area. 15: * 1.1.1.2 ! root 16: * ! 17: * Microsoft Developer Support ! 18: * Copyright (c) 1992 Microsoft Corporation ! 19: * ! 20: \******************************************************************************/ 1.1 root 21: 22: #include <windows.h> 23: #include "Main.h" 24: #include "the_dll.h" 25: 26: 27: 1.1.1.2 ! root 28: /******************************************************************************\ 1.1 root 29: * 30: * FUNCTION: WinMain (standard WinMain INPUTS/RETURNS) 31: * 1.1.1.2 ! root 32: * GLOBAL VARS: ghLib - library instance handle 1.1 root 33: * 34: * LOCAL VARS: hwnd - handle of the main standard window 35: * msg - msg to get/dispatch 36: * 1.1.1.2 ! root 37: \******************************************************************************/ 1.1 root 38: 1.1.1.2 ! root 39: int WINAPI WinMain (HANDLE hInstance, HANDLE hPrevInstance, ! 40: LPSTR lpCmdLine, int nCmdShow) ! 41: { 1.1 root 42: HWND hwnd; 43: MSG msg; 44: 45: 1.1.1.2 ! root 46: if ((ghLib = LoadLibrary ((LPTSTR)"the_dll.dll")) == NULL) ! 47: { ! 48: MessageBox (NULL, (LPCTSTR) "WinMain(): LoadLibrary() failed", ! 49: (LPCTSTR) "Err! - RESDLL", MB_OK | MB_ICONEXCLAMATION); 1.1 root 50: return 0; 51: } 52: 53: if (!hPrevInstance) 54: { 55: WNDCLASS wc; 56: 57: wc.style = CS_HREDRAW | CS_VREDRAW;; 58: wc.lpfnWndProc = (WNDPROC)MainWndProc; 59: wc.cbClsExtra = 0; 60: wc.cbWndExtra = 0; 61: wc.hInstance = hInstance; 1.1.1.2 ! root 62: wc.hIcon = LoadIcon (ghLib, "dllicon"); ! 63: wc.hCursor = LoadCursor (ghLib, "dllcursor"); 1.1 root 64: wc.hbrBackground = GetStockObject (WHITE_BRUSH); 65: wc.lpszMenuName = NULL; 1.1.1.2 ! root 66: wc.lpszClassName = (LPCTSTR) "RESDLL"; 1.1 root 67: 68: if (!RegisterClass (&wc)) 1.1.1.2 ! root 69: { ! 70: MessageBox (NULL, (LPCTSTR) "WinMain(): RegisterClass() failed", ! 71: (LPCTSTR) "Err! - MAIN", MB_OK | MB_ICONEXCLAMATION); 1.1 root 72: return(FALSE); 73: } 74: } 75: 76: if (!(hwnd = CreateWindow ("RESDLL", "RESDLL Sample Application", 77: WS_OVERLAPPEDWINDOW, 78: CW_USEDEFAULT, CW_USEDEFAULT, 79: CW_USEDEFAULT, CW_USEDEFAULT, 80: NULL, NULL, hInstance, NULL))) 81: return (NULL); 82: 1.1.1.2 ! root 83: ShowWindow (hwnd, nCmdShow); 1.1 root 84: 1.1.1.2 ! root 85: while (GetMessage (&msg, NULL, NULL, NULL)) ! 86: { ! 87: TranslateMessage (&msg); ! 88: DispatchMessage (&msg); 1.1 root 89: } 1.1.1.2 ! root 90: FreeLibrary (ghLib); 1.1 root 91: return (msg.wParam); 92: } 93: 94: 95: 1.1.1.2 ! root 96: /******************************************************************************\ 1.1 root 97: * 98: * FUNCTION: MainWndProc (standard window procedure INPUTS/RETURNS) 99: * 1.1.1.2 ! root 100: * GLOBAL VARS: ghLib - library instance handle 1.1 root 101: * 102: * LOCAL VARS: hbm - handle of bitmap in THE_DLL.DLL 103: * 1.1.1.2 ! root 104: \******************************************************************************/ 1.1 root 105: 1.1.1.2 ! root 106: LRESULT CALLBACK MainWndProc (HWND hwnd, UINT message, WPARAM wParam, ! 107: LPARAM lParam) ! 108: { ! 109: static HBITMAP hbm; 1.1 root 110: 111: switch (message) 1.1.1.2 ! root 112: { ! 113: case WM_CREATE: ! 114: ! 115: hbm = LoadBitmap (ghLib, "dllbitmap"); 1.1 root 116: break; 1.1.1.2 ! root 117: 1.1 root 118: case WM_PAINT: 1.1.1.2 ! root 119: { ! 120: RECT rect; 1.1 root 121: PAINTSTRUCT ps; 122: 123: GetClientRect (hwnd, &rect); 124: BeginPaint (hwnd, &ps); 1.1.1.2 ! root 125: ! 126: // ! 127: // draw the dllbitmap centered in middle of our client rect ! 128: // ! 129: 1.1 root 130: DrawBitmap (ps.hdc, hbm, 131: rect.right/2 - DLLBITMAP_WIDTH/2, 132: rect.bottom/2 - DLLBITMAP_HEIGHT/2); 133: EndPaint (hwnd, &ps); 134: return 0; 135: } 1.1.1.2 ! root 136: 1.1 root 137: case WM_DESTROY: 1.1.1.2 ! root 138: 1.1 root 139: DeleteObject ((HANDLE) hbm); 1.1.1.2 ! root 140: PostQuitMessage (NULL); 1.1 root 141: break; 1.1.1.2 ! root 142: 1.1 root 143: default: 1.1.1.2 ! root 144: 1.1 root 145: return (DefWindowProc(hwnd, message, wParam, lParam)); 146: } 147: return (NULL); 148: } 149: 150: 151: 1.1.1.2 ! root 152: /******************************************************************************\ 1.1 root 153: * 154: * FUNCTION: DrawBitmap 155: * 156: * INPUTS: hdc - device context in which to draw bitmap 157: * hbm - handle of bitmap to draw 158: * xStart - x-coordinate of upper-left corner of destination 159: * rectangle 160: * yStart - y-coordinate of upper-left corner of destination 161: * rectangle 162: * 163: * LOCAL VARS: bm - BITMAP info of "hbm" 164: * hdcMem - a memory DC used for blt-ing 165: * 166: * COMMENTS: Draws a bitmap "hbm" in a DC "hdc" given the upper-left 167: * corner "xStart,yStart" of a destination rectangle. 168: * 1.1.1.2 ! root 169: \******************************************************************************/ 1.1 root 170: 171: void DrawBitmap (HDC hdc, HBITMAP hbm, int xStart, int yStart) 172: { 173: BITMAP bm; 174: HDC hdcMem; 175: 176: hdcMem = CreateCompatibleDC (hdc); 177: SelectObject (hdcMem, hbm); 178: SetMapMode (hdcMem, GetMapMode(hdc)); 179: 180: GetObject (hbm, sizeof(BITMAP), (LPSTR)&bm); 181: BitBlt (hdc, xStart, yStart, bm.bmWidth, bm.bmHeight, 182: hdcMem, 0, 0, SRCCOPY); 183: 184: DeleteDC(hdcMem); 185: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.