Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #ifndef UNICODE
- #define UNICODE
- #endif
- #include <windows.h>
- LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMSG, WPARAM wParam, LPARAM lParam);
- int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCommandLine, int nShowCmd)
- {
- const wchar_t CLASS_NAME[] = L"class";
- WNDCLASS wc = { };
- wc.lpfnWndProc = WindowProc;
- wc.hInstance = hInstance;
- wc.lpszClassName = CLASS_NAME;
- RegisterClass(&wc);
- HWND hWnd = CreateWindowEx(
- 0,
- CLASS_NAME,
- L"Window Title",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
- NULL,
- NULL,
- hInstance,
- NULL
- );
- HWND testBtn = CreateWindow
- (
- L"BUTTON",
- L"TEXT",
- WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, // Styles
- 10, // x position
- 10, // y position
- 100, // Button width
- 20, // Button height,
- hWnd,
- NULL, // No menu.
- (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE),
- NULL); // Pointer not needed.
- if (hWnd == NULL)
- {
- return 0;
- // Termina el programa, es decir, no se ha creado la ventana principal.
- }
- ShowWindow(hWnd, nShowCmd);
- MSG msg = { };
- //ZeroMemory(&msg, sizeof(msg));
- while (GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return 0;
- }
- LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMSG, WPARAM wParam, LPARAM lParam)
- {
- RECT rect;
- switch (uMSG) {
- case WM_DESTROY:
- PostQuitMessage(0); // Hace que GetMessage devuelva 0, por lo que el bucle es terminado, y la ventana se cierra
- return 0;
- case WM_PAINT:
- {
- PAINTSTRUCT ps;
- HDC hdc = BeginPaint(hWnd, &ps);
- FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW));
- GetClientRect(hWnd, &rect);
- DrawText(hdc, L"Hola mundo", -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
- EndPaint(hWnd, &ps);
- }
- return 0;
- case WM_CLOSE: // Aparece si se usa alt f4, o el botón de la esquina de cerrar
- {
- if (MessageBoxW(hWnd, L"Text", L"Caption", MB_OKCANCEL) == IDOK)
- {
- DestroyWindow(hWnd);
- }
- }
- return 0; // Esto sucede si el usuario cancela o cierra el dialogo, el procedimiento se cierra
- }
- return DefWindowProc(hWnd, uMSG, wParam, lParam);
- }
Advertisement
Add Comment
Please, Sign In to add comment