Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.12 KB | None | 0 0
  1. #include <windows.h>
  2.  
  3. const char g_szClassName[] = "myWindowClass";
  4.  
  5. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  6. {
  7.     switch(msg)
  8.     {
  9.         case WM_LBUTTONDOWN:
  10.         {
  11.             char szFileName[MAX_PATH];
  12.             HINSTANCE hInstance = GetModuleHandle(NULL);
  13.  
  14.             GetModuleFileName(hInstance, szFileName, MAX_PATH);
  15.             MessageBox(hwnd, szFileName, "This program is:", MB_OK | MB_ICONINFORMATION);
  16.         }
  17.         break;
  18.         case WM_CLOSE:
  19.             DestroyWindow(hwnd);
  20.         break;
  21.         case WM_DESTROY:
  22.             PostQuitMessage(0);
  23.         break;
  24.         default:
  25.             return DefWindowProc(hwnd, msg, wParam, lParam);
  26.     }
  27.     return 0;
  28. }
  29.  
  30. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  31.     LPSTR lpCmdLine, int nCmdShow)
  32. {
  33.     WNDCLASSEX wc;
  34.     HWND hwnd;
  35.     MSG Msg;
  36.  
  37.     wc.cbSize        = sizeof(WNDCLASSEX);
  38.     wc.style         = 0;
  39.     wc.lpfnWndProc   = WndProc;
  40.     wc.cbClsExtra    = 0;
  41.     wc.cbWndExtra    = 0;
  42.     wc.hInstance     = hInstance;
  43.     wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  44.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  45.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  46.     wc.lpszMenuName  = NULL;
  47.     wc.lpszClassName = g_szClassName;
  48.     wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
  49.  
  50.     if(!RegisterClassEx(&wc))
  51.     {
  52.         MessageBox(NULL, "Window Registration Failed!", "Error!",
  53.             MB_ICONEXCLAMATION | MB_OK);
  54.         return 0;
  55.     }
  56.  
  57.     hwnd = CreateWindowEx(
  58.         WS_EX_CLIENTEDGE,
  59.         g_szClassName,
  60.         "The title of my window",
  61.         WS_OVERLAPPEDWINDOW,
  62.         CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
  63.         NULL, NULL, hInstance, NULL);
  64.  
  65.     if(hwnd == NULL)
  66.     {
  67.         MessageBox(NULL, "Window Creation Failed!", "Error!",
  68.             MB_ICONEXCLAMATION | MB_OK);
  69.         return 0;
  70.     }
  71.  
  72.     ShowWindow(hwnd, nCmdShow);
  73.     UpdateWindow(hwnd);
  74.  
  75.     while(GetMessage(&Msg, NULL, 0, 0) > 0)
  76.     {
  77.         TranslateMessage(&Msg);
  78.         DispatchMessage(&Msg);
  79.     }
  80.     return Msg.wParam;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement