Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pak.h"
- #include <Windows.h>
- #include <tchar.h>
- #define save_instance(ins)\
- do { \
- instance = ins; \
- } while(0)
- /* prototypes */
- static int register_class (void);
- static int create_window (HWND *window);
- static LRESULT CALLBACK class_proc (HWND window, UINT msg, WPARAM wparam,
- LPARAM lparam);
- /* global variables */
- static HINSTANCE instance = NULL;
- int APIENTRY _tWinMain (HINSTANCE ins, HINSTANCE pins, LPTSTR args, int show)
- {
- save_instance(ins);
- if (register_class()) {
- MessageBox(NULL, TEXT("Error registrando ventana"),
- NULL, MB_OK | MB_ICONEXCLAMATION);
- return -1;
- }
- HWND mwindow;
- if (create_window(&mwindow)) {
- MessageBox(NULL, TEXT("Error creando ventana"),
- NULL, MB_OK | MB_ICONEXCLAMATION);
- return -1;
- }
- ShowWindow(mwindow, show);
- UpdateWindow(mwindow);
- MSG msg;
- while (GetMessage(&msg, NULL, 0, 0) > 0) {
- DispatchMessage(&msg);
- }
- return msg.wParam;
- }
- static int register_class (void)
- {
- WNDCLASS wc = { .lpfnWndProc = class_proc,
- .hInstance = instance,
- .hbrBackground = (void *)(COLOR_WINDOW + 1),
- .lpszClassName = TEXT("MainWindow") };
- return (RegisterClass(&wc) == 0);
- }
- static int create_window (HWND *window)
- {
- HWND _window = CreateWindow(TEXT("MainWindow"),
- TEXT("Prueba"),
- WS_OVERLAPPED,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- NULL,
- NULL,
- instance,
- NULL);
- if (_window == NULL) {
- return -1;
- }
- *window = _window;
- return 0;
- }
- static LRESULT CALLBACK class_proc (HWND window, UINT msg, WPARAM wparam,
- LPARAM lparam)
- {
- switch (msg) {
- case WM_CLOSE:
- if (MessageBox(NULL,
- TEXT("¿Quieres cerrar la ventana?"),
- TEXT("Cerrar"),
- MB_YESNO | MB_ICONEXCLAMATION) == IDYES) {
- DestroyWindow(window);
- return 0;
- } else {
- return -1;
- }
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- default:
- return DefWindowProc(window, msg, wparam, lparam);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement