Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- LPCWSTR g_szClassName = L"MainWindowClass";
- /*Define Section*/
- /*Buttons*/
- #define BUTTON_01 1
- /*Buttons - End*/
- /*Define Section - End*/
- /*Void Zone*/
- void checkIfComputerIsOpened()
- {
- LPCWSTR Computer = L"Computador";
- HWND computer = FindWindow(NULL, Computer);
- if (computer == NULL)
- {
- LPCWSTR ComputerError = L"Computer is not opened!";
- LPCWSTR ComputerError_Caption = L"Error";
- MessageBox(NULL, ComputerError, ComputerError_Caption, MB_OK | MB_ICONERROR);
- }
- else
- {
- LPCWSTR ComputerError = L"Computer is opened!";
- LPCWSTR ComputerError_Caption = L"Congrats";
- MessageBox(NULL, ComputerError, ComputerError_Caption, MB_OK | MB_ICONINFORMATION);
- }
- }
- /*Void Zone - End*/
- LRESULT CALLBACK WndProc(HWND hwnd, UINT Msg, WPARAM wParam , LPARAM lParam)
- {
- switch (Msg)
- {
- case WM_CREATE:
- {
- /*Button01*/
- LPCWSTR button01_ID = L"BUTTON";
- LPCWSTR button01_text = L"Verify";
- 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);
- /*Button01-End*/
- }
- break;
- case WM_COMMAND:
- {
- switch (wParam)
- {
- case BUTTON_01:
- checkIfComputerIsOpened();
- break;
- }
- }
- break;
- case WM_CLOSE:
- DestroyWindow(hwnd);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hwnd, Msg, wParam, lParam);
- }
- return 0;
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
- {
- WNDCLASSEX wc;
- MSG msg;
- HWND hwnd;
- ZeroMemory(&wc, sizeof(wc));
- wc.style = 0;
- wc.lpszMenuName = NULL;
- wc.lpszClassName = g_szClassName;
- wc.lpfnWndProc = WndProc;
- wc.hInstance = hInstance;
- wc.hIconSm = LoadIcon(NULL, IDC_ICON);
- wc.hIcon = LoadIcon(NULL, IDC_ICON);
- wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- wc.cbWndExtra = 0;
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.cbClsExtra = 0;
- if (!RegisterClassEx(&wc))
- {
- LPCWSTR Error01 = L"Could not register class";
- LPCWSTR Error01_Caption = L"Error";
- MessageBox(NULL, Error01, Error01_Caption, MB_OK | MB_ICONERROR);
- }
- LPCWSTR WindowTitle = L"TUTORIAL!!!";
- hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, g_szClassName, WindowTitle, WS_OVERLAPPEDWINDOW , CW_USEDEFAULT, CW_USEDEFAULT, 500, 300, NULL, NULL, hInstance, NULL);
- if (hwnd == NULL)
- {
- LPCWSTR Error02 = L"Could not create window!";
- LPCWSTR Error02_Caption = L"Error";
- MessageBox(NULL, Error02, Error02_Caption, MB_OK | MB_ICONERROR);
- }
- ShowWindow(hwnd, nCmdShow);
- UpdateWindow(hwnd);
- while (GetMessage(&msg, 0, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return msg.wParam;
- }
Advertisement
Add Comment
Please, Sign In to add comment