Advertisement
Guest User

Untitled

a guest
Jan 12th, 2021
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.48 KB | None | 0 0
  1. /*
  2.  * PROJECT:         ReactOS Simple Program
  3.  * LICENSE:         GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
  4.  * PURPOSE:         Main file code
  5.  * COPYRIGHT:       Copyright ??? (???)
  6.  */
  7.  
  8. /* INCLUDES *******************************************************************/
  9.  
  10. #include "precomp.h"
  11.  
  12. /* GLOBALS ********************************************************************/
  13.  
  14. HINSTANCE hGlobalInstance = NULL;
  15. HICON hIcon = NULL;
  16.  
  17. /* FUNCTIONS ******************************************************************/
  18.  
  19. BOOL
  20. DlgInitHandler(_In_ HWND hDlg)
  21. {
  22.     INT PosX, PosY;
  23.     RECT Rect;
  24.     WCHAR szAppPath[MAX_BUFFER];
  25.  
  26.     /* Center the dialog on the screen */
  27.     GetWindowRect(hDlg, &Rect);
  28.     PosX = (GetSystemMetrics(SM_CXSCREEN) - Rect.right) / 2;
  29.     PosY = (GetSystemMetrics(SM_CYSCREEN) - Rect.bottom) / 2;
  30.     SetWindowPos(hDlg, 0, PosX, PosY, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
  31.  
  32.     /* Extract the icon resource from the executable process */
  33.     GetModuleFileNameW(NULL, szAppPath, _countof(szAppPath));
  34.     hIcon = ExtractIconW(hGlobalInstance, szAppPath, 0);
  35.  
  36.     /* Set the icon within the dialog's title bar */
  37.     if (hIcon)
  38.     {
  39.         SendMessageW(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
  40.     }
  41.  
  42.     return TRUE;
  43. }
  44.  
  45. INT_PTR CALLBACK
  46. DlgProc(
  47.     _In_ HWND hDlg,
  48.     _In_ UINT Msg,
  49.     _In_ WPARAM wParam,
  50.     _In_ LPARAM lParam)
  51. {
  52.     switch (Msg)
  53.     {
  54.         case WM_INITDIALOG:
  55.             return DlgInitHandler(hDlg);
  56.  
  57.         case WM_CLOSE:
  58.             DestroyIcon(hIcon);
  59.             EndDialog(hDlg, FALSE);
  60.             break;
  61.  
  62.         case WM_COMMAND:
  63.         {
  64.             switch (LOWORD(wParam))
  65.             {
  66.                 case IDC_SIMPLE_BUTTON:
  67.                     DestroyIcon(hIcon);
  68.                     EndDialog(hDlg, FALSE);
  69.                     break;
  70.  
  71.                 default:
  72.                     break;
  73.             }
  74.  
  75.             break;
  76.         }
  77.     }
  78.  
  79.     return 0;
  80. }
  81.  
  82.  
  83. int WINAPI
  84. wWinMain(
  85.     _In_ HINSTANCE hInstance,
  86.     _In_ HINSTANCE hPrevInstance,
  87.     _In_ LPWSTR pCmdLine,
  88.     _In_ int nCmdShow)
  89. {
  90.     UNREFERENCED_PARAMETER(hPrevInstance);
  91.     UNREFERENCED_PARAMETER(pCmdLine);
  92.     UNREFERENCED_PARAMETER(nCmdShow);
  93.  
  94.     /* Cache the handle instance of our program */
  95.     hGlobalInstance = hInstance;
  96.  
  97.     /* Create the dialog box */
  98.     DialogBoxW(
  99.         hInstance,
  100.         MAKEINTRESOURCEW(IDD_SIMPLE_DIALOG),
  101.         GetDesktopWindow(),
  102.         DlgProc);
  103.  
  104.     return 0;
  105. }
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement