Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------
- Header.h
- --------
- #pragma once
- #define MI_EXIT 101
- #define ID_OK 201
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- void OnCommand(HWND, int, HWND, UINT);
- int OnDestroy(HWND hwnd);
- int MakingWindow(HINSTANCE, int, int,int,int);
- BOOL CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
- void DlgOnCommand(HWND, int, HWND, UINT);
- ---------
- Resource.rc
- ---------
- #include "winres.h"
- #include "Header.h"
- Main MENU
- {
- POPUP "&Помощь"
- {
- MENUITEM "&Выход", MI_EXIT;
- }
- }
- ExitConfirm DIALOG 300,100,93,50
- STYLE WS_CAPTION | WS_POPUP | DS_MODALFRAME
- CAPTION "Подтвердите выход"
- {
- CONTROL "Выход", ID_OK, "BUTTON", BS_PUSHBUTTON, 27, 32, 43, 12;
- }
- ----------
- SOURCE.CPP
- ----------
- #include <Windows.h>
- #include <windowsx.h>
- #include "Header.h"
- char szClassName[] = "Main";
- int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int)
- {
- WNDCLASS wd;
- ZeroMemory(&wd, sizeof(wd));
- wd.lpfnWndProc = WndProc;
- wd.lpszClassName = szClassName;
- wd.hInstance = hInst;
- wd.hCursor = LoadCursor(NULL, IDC_ARROW);
- wd.lpszMenuName = "Main";
- wd.hbrBackground = CreateSolidBrush(BLACK_BRUSH);
- RegisterClass(&wd);
- MakingWindow(hInst, 100,100,300,300);
- }
- int MakingWindow(HINSTANCE hInst, int x,int y, int width, int height)
- {
- HWND hwnd = CreateWindowEx(WS_EX_TOPMOST, szClassName, "Info", WS_OVERLAPPEDWINDOW, x, y, width, height, HWND_DESKTOP, NULL, hInst, NULL);
- ShowWindow(hwnd, SW_SHOWNORMAL);
- MSG msg;
- while (GetMessage(&msg, NULL, 0, 0))
- {
- DispatchMessage(&msg);
- }
- return 0;
- }
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- switch (msg)
- {
- HANDLE_MSG(hwnd, WM_COMMAND, OnCommand);
- HANDLE_MSG(hwnd, WM_DESTROY, OnDestroy);
- default:
- return(DefWindowProc(hwnd, msg, wParam, lParam));
- }
- }
- void OnCommand(HWND hwnd, int id, HWND, UINT)
- {
- switch (id)
- {
- case MI_EXIT:
- DialogBox((HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), "ExitConfirm", NULL, DlgProc);
- break;
- }
- }
- int OnDestroy(HWND hwnd)
- {
- RECT r;
- GetWindowRect(hwnd, &r);
- MakingWindow((HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), r.left, r.top, r.right-r.left, r.bottom-r.top);
- return 0;
- }
- //Обработка модального диалога ExitConfirm
- BOOL CALLBACK DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- switch (msg)
- {
- HANDLE_MSG(hwnd, WM_COMMAND, DlgOnCommand);
- default:
- return FALSE;
- }
- }
- void DlgOnCommand(HWND hwnd, int id, HWND, UINT)
- {
- switch (id)
- {
- case ID_OK:
- MessageBeep(MB_ICONASTERISK);
- EndDialog(hwnd, 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment