Annotation of q_a/samples/resdll/main.c, revision 1.1.1.1

1.1       root        1: /************************************************************************\
                      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: *
                     16: \************************************************************************/
                     17: 
                     18: #include <windows.h>
                     19: #include "Main.h"
                     20: #include "the_dll.h"
                     21: 
                     22: 
                     23: 
                     24: /************************************************************************\
                     25: *
                     26: *  FUNCTION:    WinMain (standard WinMain INPUTS/RETURNS)
                     27: *
                     28: *  GLOBAL VARS: hLib - library instance handle
                     29: *
                     30: *  LOCAL VARS:  hwnd - handle of the main standard window
                     31: *               msg  - msg to get/dispatch
                     32: *
                     33: \************************************************************************/
                     34: 
                     35: int APIENTRY WinMain (HANDLE hInstance,HANDLE hPrevInstance,
                     36:                       LPSTR lpCmdLine, int nCmdShow) {
                     37:   HWND hwnd;
                     38:   MSG msg;
                     39: 
                     40: 
                     41:   if ((hLib = LoadLibrary ((LPTSTR)"the_dll.dll")) == NULL)
                     42:   { MessageBox (NULL, "WinMain(): LoadLibrary() failed",
                     43:                 "Err! - RESDLL", MB_OK | MB_ICONHAND);
                     44:     return 0;
                     45:   }
                     46: 
                     47:   if (!hPrevInstance)
                     48:   {
                     49:     WNDCLASS wc;
                     50: 
                     51:     wc.style         = CS_HREDRAW | CS_VREDRAW;;
                     52:     wc.lpfnWndProc   = (WNDPROC)MainWndProc;
                     53:     wc.cbClsExtra    = 0;
                     54:     wc.cbWndExtra    = 0;
                     55:     wc.hInstance     = hInstance;
                     56:     wc.hIcon         = LoadIcon (hLib, "dllicon");
                     57:     wc.hCursor       = LoadCursor (hLib, "dllcursor");
                     58:     wc.hbrBackground = GetStockObject (WHITE_BRUSH);
                     59:     wc.lpszMenuName  = NULL;
                     60:     wc.lpszClassName = (LPSTR) "RESDLL";
                     61: 
                     62:     if (!RegisterClass (&wc))
                     63:     { MessageBox (NULL, "WinMain(): RegisterClass() failed",
                     64:                   "Err! - MAIN", MB_OK | MB_ICONHAND);
                     65:       return(FALSE);
                     66:     }
                     67:   }
                     68: 
                     69:   if (!(hwnd = CreateWindow ("RESDLL", "RESDLL Sample Application",
                     70:                              WS_OVERLAPPEDWINDOW,
                     71:                              CW_USEDEFAULT, CW_USEDEFAULT,
                     72:                              CW_USEDEFAULT, CW_USEDEFAULT,
                     73:                              NULL, NULL, hInstance, NULL)))
                     74:     return (NULL);
                     75: 
                     76:   ShowWindow(hwnd, nCmdShow);
                     77: 
                     78:   while (GetMessage(&msg, NULL, NULL, NULL))
                     79:   { TranslateMessage(&msg);
                     80:     DispatchMessage(&msg);
                     81:   }
                     82:   FreeLibrary (hLib);
                     83:   return (msg.wParam);
                     84:   UNREFERENCED_PARAMETER(lpCmdLine);
                     85: }
                     86: 
                     87: 
                     88: 
                     89: /************************************************************************\
                     90: *
                     91: *  FUNCTION:    MainWndProc (standard window procedure INPUTS/RETURNS)
                     92: *
                     93: *  GLOBAL VARS: hLib - library instance handle
                     94: *
                     95: *  LOCAL VARS:  hbm - handle of bitmap in THE_DLL.DLL
                     96: *
                     97: \************************************************************************/
                     98: 
                     99: LONG APIENTRY MainWndProc (HWND hwnd, UINT message, UINT wParam,
                    100:                            LONG lParam)
                    101: { static HBITMAP hbm;
                    102: 
                    103:   switch (message)
                    104:   { case WM_CREATE:
                    105:       hbm = LoadBitmap (hLib, "dllbitmap");
                    106:       break;
                    107:     case WM_PAINT:
                    108:     { RECT        rect;
                    109:       PAINTSTRUCT ps;
                    110: 
                    111:       GetClientRect (hwnd, &rect);
                    112:       BeginPaint (hwnd, &ps);
                    113:       /******************************************************************\
                    114:       *  draw the dllbitmap centered in middle of our client rect
                    115:       \******************************************************************/
                    116:       DrawBitmap (ps.hdc, hbm,
                    117:                   rect.right/2 - DLLBITMAP_WIDTH/2,
                    118:                   rect.bottom/2 - DLLBITMAP_HEIGHT/2);
                    119:       EndPaint (hwnd, &ps);
                    120:       return 0;
                    121:     }
                    122:     case WM_DESTROY:
                    123:       DeleteObject ((HANDLE) hbm);
                    124:       PostQuitMessage(NULL);
                    125:       break;
                    126:     default:
                    127:       return (DefWindowProc(hwnd, message, wParam, lParam));
                    128:   }
                    129:   return (NULL);
                    130: }
                    131: 
                    132: 
                    133: 
                    134: /************************************************************************\
                    135: *
                    136: *  FUNCTION:    DrawBitmap
                    137: *
                    138: *  INPUTS:      hdc    - device context in which to draw bitmap
                    139: *               hbm    - handle of bitmap to draw
                    140: *               xStart - x-coordinate of upper-left corner of destination
                    141: *                        rectangle
                    142: *               yStart - y-coordinate of upper-left corner of destination
                    143: *                        rectangle
                    144: *
                    145: *  LOCAL VARS:  bm     - BITMAP info of "hbm"
                    146: *               hdcMem - a memory DC used for blt-ing
                    147: *
                    148: *  COMMENTS:    Draws a bitmap "hbm" in a DC "hdc" given the upper-left
                    149: *               corner "xStart,yStart" of a destination rectangle.
                    150: *
                    151: \************************************************************************/
                    152: 
                    153: void DrawBitmap (HDC hdc, HBITMAP hbm, int xStart, int yStart)
                    154: {
                    155:   BITMAP bm;
                    156:   HDC    hdcMem;
                    157: 
                    158:   hdcMem = CreateCompatibleDC (hdc);
                    159:   SelectObject (hdcMem, hbm);
                    160:   SetMapMode (hdcMem, GetMapMode(hdc));
                    161: 
                    162:   GetObject (hbm, sizeof(BITMAP), (LPSTR)&bm);
                    163:   BitBlt (hdc, xStart, yStart, bm.bmWidth, bm.bmHeight,
                    164:           hdcMem, 0, 0, SRCCOPY);
                    165: 
                    166:   DeleteDC(hdcMem);
                    167: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.