Guest User

Untitled

a guest
Feb 24th, 2014
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.76 KB | None | 0 0
  1. #include <Windows.h>
  2.  
  3. LPCWSTR g_szClassName = L"MainWindowClass";
  4.  
  5. /*Define Section*/
  6. /*Buttons*/
  7. #define BUTTON_01 1
  8. /*Buttons - End*/
  9. /*Define Section - End*/
  10.  
  11. /*Void Zone*/
  12. void checkIfComputerIsOpened()
  13. {
  14.     LPCWSTR Computer = L"Computador";
  15.     HWND computer = FindWindow(NULL, Computer);
  16.  
  17.     if (computer == NULL)
  18.     {
  19.         LPCWSTR ComputerError = L"Computer is not opened!";
  20.         LPCWSTR ComputerError_Caption = L"Error";
  21.         MessageBox(NULL, ComputerError, ComputerError_Caption, MB_OK | MB_ICONERROR);
  22.     }
  23.     else
  24.     {
  25.         LPCWSTR ComputerError = L"Computer is opened!";
  26.         LPCWSTR ComputerError_Caption = L"Congrats";
  27.         MessageBox(NULL, ComputerError, ComputerError_Caption, MB_OK | MB_ICONINFORMATION);
  28.     }
  29. }
  30. /*Void Zone - End*/
  31.  
  32. LRESULT CALLBACK WndProc(HWND hwnd, UINT Msg, WPARAM wParam , LPARAM lParam)
  33. {
  34.     switch (Msg)
  35.     {
  36.     case WM_CREATE:
  37.     {
  38.                       /*Button01*/
  39.                       LPCWSTR button01_ID = L"BUTTON";
  40.                       LPCWSTR button01_text = L"Verify";
  41.                       HWND button01 = CreateWindowEx(NULL, button01_ID, button01_text, BS_DEFPUSHBUTTON | WS_VISIBLE | WS_BORDER | WS_CHILD, 100, 50, 70, 30, hwnd, (HMENU)BUTTON_01, NULL, NULL);
  42.                       /*Button01-End*/
  43.     }
  44.         break;
  45.     case WM_COMMAND:
  46.     {
  47.                        switch (wParam)
  48.                        {
  49.                        case BUTTON_01:
  50.                            checkIfComputerIsOpened();
  51.                            break;
  52.                        }
  53.     }
  54.         break;
  55.     case WM_CLOSE:
  56.         DestroyWindow(hwnd);
  57.         break;
  58.     case WM_DESTROY:
  59.         PostQuitMessage(0);
  60.         break;
  61.     default:
  62.         return DefWindowProc(hwnd, Msg, wParam, lParam);
  63.     }
  64.     return 0;
  65. }
  66.  
  67. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  68. {
  69.     WNDCLASSEX wc;
  70.     MSG msg;
  71.     HWND hwnd;
  72.  
  73.     ZeroMemory(&wc, sizeof(wc));
  74.  
  75.     wc.style = 0;
  76.     wc.lpszMenuName = NULL;
  77.     wc.lpszClassName = g_szClassName;
  78.     wc.lpfnWndProc = WndProc;
  79.     wc.hInstance = hInstance;
  80.     wc.hIconSm = LoadIcon(NULL, IDC_ICON);
  81.     wc.hIcon = LoadIcon(NULL, IDC_ICON);
  82.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  83.     wc.cbWndExtra = 0;
  84.     wc.cbSize = sizeof(WNDCLASSEX);
  85.     wc.cbClsExtra = 0;
  86.  
  87.     if (!RegisterClassEx(&wc))
  88.     {
  89.         LPCWSTR Error01 = L"Could not register class";
  90.         LPCWSTR Error01_Caption = L"Error";
  91.         MessageBox(NULL, Error01, Error01_Caption, MB_OK | MB_ICONERROR);
  92.     }
  93.    
  94.     LPCWSTR WindowTitle = L"TUTORIAL!!!";
  95.  
  96.     hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, g_szClassName, WindowTitle, WS_OVERLAPPEDWINDOW , CW_USEDEFAULT, CW_USEDEFAULT, 500, 300, NULL, NULL, hInstance, NULL);
  97.  
  98.     if (hwnd == NULL)
  99.     {
  100.         LPCWSTR Error02 = L"Could not create window!";
  101.         LPCWSTR Error02_Caption = L"Error";
  102.         MessageBox(NULL, Error02, Error02_Caption, MB_OK | MB_ICONERROR);
  103.     }
  104.  
  105.     ShowWindow(hwnd, nCmdShow);
  106.     UpdateWindow(hwnd);
  107.  
  108.     while (GetMessage(&msg, 0, 0, 0))
  109.     {
  110.         TranslateMessage(&msg);
  111.         DispatchMessage(&msg);
  112.     }
  113.  
  114.     return msg.wParam;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment