--- q_a/samples/resdll/main.c 2018/08/09 18:29:19 1.1.1.1 +++ q_a/samples/resdll/main.c 2018/08/09 18:29:52 1.1.1.3 @@ -1,4 +1,4 @@ -/************************************************************************\ +/******************************************************************************\ * * PROGRAM: MAIN.C * @@ -13,7 +13,11 @@ * app's window class. Uses the bitmap when painting * the client area. * -\************************************************************************/ +* +* Microsoft Developer Support +* Copyright (c) 1992, 1993 Microsoft Corporation +* +\******************************************************************************/ #include #include "Main.h" @@ -21,26 +25,28 @@ -/************************************************************************\ +/******************************************************************************\ * * FUNCTION: WinMain (standard WinMain INPUTS/RETURNS) * -* GLOBAL VARS: hLib - library instance handle +* GLOBAL VARS: ghLib - library instance handle * * LOCAL VARS: hwnd - handle of the main standard window * msg - msg to get/dispatch * -\************************************************************************/ +\******************************************************************************/ -int APIENTRY WinMain (HANDLE hInstance,HANDLE hPrevInstance, - LPSTR lpCmdLine, int nCmdShow) { +int WINAPI WinMain (HANDLE hInstance, HANDLE hPrevInstance, + LPSTR lpCmdLine, int nCmdShow) +{ HWND hwnd; MSG msg; - if ((hLib = LoadLibrary ((LPTSTR)"the_dll.dll")) == NULL) - { MessageBox (NULL, "WinMain(): LoadLibrary() failed", - "Err! - RESDLL", MB_OK | MB_ICONHAND); + if ((ghLib = LoadLibrary ((LPTSTR)"the_dll.dll")) == NULL) + { + MessageBox (NULL, (LPCTSTR) "WinMain(): LoadLibrary() failed", + (LPCTSTR) "Err! - RESDLL", MB_OK | MB_ICONEXCLAMATION); return 0; } @@ -53,15 +59,16 @@ int APIENTRY WinMain (HANDLE hInstance,H wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; - wc.hIcon = LoadIcon (hLib, "dllicon"); - wc.hCursor = LoadCursor (hLib, "dllcursor"); + wc.hIcon = LoadIcon (ghLib, "dllicon"); + wc.hCursor = LoadCursor (ghLib, "dllcursor"); wc.hbrBackground = GetStockObject (WHITE_BRUSH); wc.lpszMenuName = NULL; - wc.lpszClassName = (LPSTR) "RESDLL"; + wc.lpszClassName = (LPCTSTR) "RESDLL"; if (!RegisterClass (&wc)) - { MessageBox (NULL, "WinMain(): RegisterClass() failed", - "Err! - MAIN", MB_OK | MB_ICONHAND); + { + MessageBox (NULL, (LPCTSTR) "WinMain(): RegisterClass() failed", + (LPCTSTR) "Err! - MAIN", MB_OK | MB_ICONEXCLAMATION); return(FALSE); } } @@ -71,67 +78,78 @@ int APIENTRY WinMain (HANDLE hInstance,H CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL))) - return (NULL); + return (0); - ShowWindow(hwnd, nCmdShow); + ShowWindow (hwnd, nCmdShow); - while (GetMessage(&msg, NULL, NULL, NULL)) - { TranslateMessage(&msg); - DispatchMessage(&msg); + while (GetMessage (&msg, NULL, 0,0)) + { + TranslateMessage (&msg); + DispatchMessage (&msg); } - FreeLibrary (hLib); + FreeLibrary (ghLib); return (msg.wParam); - UNREFERENCED_PARAMETER(lpCmdLine); } -/************************************************************************\ +/******************************************************************************\ * * FUNCTION: MainWndProc (standard window procedure INPUTS/RETURNS) * -* GLOBAL VARS: hLib - library instance handle +* GLOBAL VARS: ghLib - library instance handle * * LOCAL VARS: hbm - handle of bitmap in THE_DLL.DLL * -\************************************************************************/ +\******************************************************************************/ -LONG APIENTRY MainWndProc (HWND hwnd, UINT message, UINT wParam, - LONG lParam) -{ static HBITMAP hbm; +LRESULT CALLBACK MainWndProc (HWND hwnd, UINT message, WPARAM wParam, + LPARAM lParam) +{ + static HBITMAP hbm; switch (message) - { case WM_CREATE: - hbm = LoadBitmap (hLib, "dllbitmap"); + { + case WM_CREATE: + + hbm = LoadBitmap (ghLib, "dllbitmap"); break; + case WM_PAINT: - { RECT rect; + { + RECT rect; PAINTSTRUCT ps; GetClientRect (hwnd, &rect); BeginPaint (hwnd, &ps); - /******************************************************************\ - * draw the dllbitmap centered in middle of our client rect - \******************************************************************/ + + // + // draw the dllbitmap centered in middle of our client rect + // + DrawBitmap (ps.hdc, hbm, rect.right/2 - DLLBITMAP_WIDTH/2, rect.bottom/2 - DLLBITMAP_HEIGHT/2); EndPaint (hwnd, &ps); return 0; } + case WM_DESTROY: + DeleteObject ((HANDLE) hbm); - PostQuitMessage(NULL); + PostQuitMessage (0); break; + default: + return (DefWindowProc(hwnd, message, wParam, lParam)); } - return (NULL); + return (0); } -/************************************************************************\ +/******************************************************************************\ * * FUNCTION: DrawBitmap * @@ -148,7 +166,7 @@ LONG APIENTRY MainWndProc (HWND hwnd, UI * COMMENTS: Draws a bitmap "hbm" in a DC "hdc" given the upper-left * corner "xStart,yStart" of a destination rectangle. * -\************************************************************************/ +\******************************************************************************/ void DrawBitmap (HDC hdc, HBITMAP hbm, int xStart, int yStart) {