summaryrefslogtreecommitdiff
path: root/Source/tests/win32/01-window/01_menu_bar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/tests/win32/01-window/01_menu_bar.cpp')
-rw-r--r--Source/tests/win32/01-window/01_menu_bar.cpp95
1 files changed, 95 insertions, 0 deletions
diff --git a/Source/tests/win32/01-window/01_menu_bar.cpp b/Source/tests/win32/01-window/01_menu_bar.cpp
new file mode 100644
index 0000000..95c95e4
--- /dev/null
+++ b/Source/tests/win32/01-window/01_menu_bar.cpp
@@ -0,0 +1,95 @@
+#include "config.h"
+
+#if _run_app == _menu_bar
+
+#include <windows.h>
+
+#include <windows.h>
+
+LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
+void AddMenus(HWND);
+
+#define IDM_FILE_NEW 1
+#define IDM_FILE_OPEN 2
+#define IDM_FILE_QUIT 3
+
+int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
+ PWSTR lpCmdLine, int nCmdShow) {
+
+ MSG msg;
+ WNDCLASSW wc = { 0 };
+ wc.lpszClassName = L"Simple menu";
+ wc.hInstance = hInstance;
+ wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
+ wc.lpfnWndProc = WndProc;
+ wc.hCursor = LoadCursor(0, IDC_ARROW);
+
+ RegisterClassW(&wc);
+ CreateWindowW(wc.lpszClassName, L"Simple menu",
+ WS_OVERLAPPEDWINDOW | WS_VISIBLE,
+ 100, 100, 350, 250, 0, 0, hInstance, 0);
+
+ while (GetMessage(&msg, NULL, 0, 0)) {
+
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+
+ return (int)msg.wParam;
+}
+
+LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,
+ WPARAM wParam, LPARAM lParam) {
+
+ switch (msg) {
+
+ case WM_CREATE:
+
+ AddMenus(hwnd);
+ break;
+
+ case WM_COMMAND:
+
+ switch (LOWORD(wParam)) {
+
+ case IDM_FILE_NEW:
+ case IDM_FILE_OPEN:
+
+ MessageBeep(MB_ICONINFORMATION);
+ break;
+
+ case IDM_FILE_QUIT:
+
+ SendMessage(hwnd, WM_CLOSE, 0, 0);
+ break;
+ }
+
+ break;
+
+ case WM_DESTROY:
+
+ PostQuitMessage(0);
+ break;
+ }
+
+ return DefWindowProcW(hwnd, msg, wParam, lParam);
+}
+
+void AddMenus(HWND hwnd) {
+
+ HMENU hMenubar;
+ HMENU hMenu;
+
+ hMenubar = CreateMenu();
+ hMenu = CreateMenu();
+
+ AppendMenuW(hMenu, MF_STRING, IDM_FILE_NEW, L"&New");
+ AppendMenuW(hMenu, MF_STRING, IDM_FILE_OPEN, L"&Open");
+ AppendMenuW(hMenu, MF_SEPARATOR, 0, NULL);
+ AppendMenuW(hMenu, MF_STRING, IDM_FILE_QUIT, L"&Quit");
+
+ AppendMenuW(hMenubar, MF_POPUP, (UINT_PTR)hMenu, L"&File");
+ SetMenu(hwnd, hMenubar);
+}
+
+#endif // _run_app == _menu_bar \ No newline at end of file