-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontextMenu.cpp
More file actions
56 lines (51 loc) · 2.04 KB
/
contextMenu.cpp
File metadata and controls
56 lines (51 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <Windows.h>
#include "globalVars.h"
#include "menuids.h"
#include "contextMenu.h"
void createContextMenu(HWND mainWindow, LPARAM coords) {
HMENU contextMenu;
POINT point;
UINT STYLE_FLAG, STYLE_FLAG_ADD;
//insert for file loading
if (OPENMODE==1) {
STYLE_FLAG = MF_GRAYED;
}
else {
STYLE_FLAG = MF_STRING;
}
contextMenu = CreatePopupMenu();
point.x = LOWORD(coords);
point.y = HIWORD(coords);
ClientToScreen(mainWindow, &point);
AppendMenu(contextMenu, STYLE_FLAG, IDM_STYLE_BOLD, _T("&Bold"));
AppendMenu(contextMenu, STYLE_FLAG, IDM_STYLE_ITALIC, _T("&Italic"));
AppendMenu(contextMenu, STYLE_FLAG, IDM_STYLE_UNDERLINED, _T("&Underline"));
AppendMenu(contextMenu, MF_SEPARATOR, NULL, NULL);
AppendMenu(contextMenu, STYLE_FLAG, IDM_JUSTIFY_LEFT, _T("&Left"));
AppendMenu(contextMenu, STYLE_FLAG, IDM_JUSTIFY_CENTER, _T("&Center"));
AppendMenu(contextMenu, STYLE_FLAG, IDM_JUSTIFY_RIGHT, _T("&Right"));
AppendMenu(contextMenu, MF_SEPARATOR, NULL, NULL);
AppendMenu(contextMenu, STYLE_FLAG, IDM_EDIT_COPY, _T("&Copy"));
AppendMenu(contextMenu, STYLE_FLAG, IDM_EDIT_PASTE, _T("&Paste"));
menuState.cbSize = sizeof(MENUITEMINFO);
GetMenuItemInfo(menuBar, IDM_JUSTIFY_RIGHT, false, (LPMENUITEMINFO)&menuState);
getCurrSelStatus(contextMenu);
TrackPopupMenu(contextMenu, TPM_TOPALIGN, point.x, point.y, 0, mainWindow, NULL);
DestroyMenu(contextMenu);
}
void getCurrSelStatus(HMENU contextHandle) {
contextMenuState.cbSize = sizeof(MENUITEMINFO);
ZeroMemory(&contextMenuState,sizeof(MENUITEMINFO));
enum menuItems {right=IDM_JUSTIFY_RIGHT, center, left, bold, italic, underlined};
for (register int x = right; x <= underlined; x++) {
menuState.fMask = MIIM_STATE;
GetMenuItemInfo(menuBar, x, false, (LPMENUITEMINFO)&menuState);
SetMenuItemInfo(contextHandle, x, false, (LPMENUITEMINFO)&menuState);
if (x < bold) {
menuState.fMask = MIIM_FTYPE;
menuState.fType = MFT_RADIOCHECK;
GetMenuItemInfo(menuBar, x, false, (LPMENUITEMINFO)&menuState);
SetMenuItemInfo(contextHandle, x, false, (LPMENUITEMINFO)&menuState);
}
}
}