Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

390 lines
8.5 KiB

  1. #include <afx.h>
  2. #include "vktbl.h"
  3. char vkstrTable[][15] =
  4. {
  5. "VK_LBUTTON",
  6. "VK_RBUTTON",
  7. "VK_CANCEL",
  8. "VK_MBUTTON",
  9. "VK_BACK",
  10. "VK_TAB",
  11. "VK_CLEAR",
  12. "VK_RETURN",
  13. "VK_SHIFT",
  14. "VK_CONTROL",
  15. "VK_MENU",
  16. "VK_PAUSE",
  17. "VK_CAPITAL",
  18. "VK_ESCAPE",
  19. "VK_SPACE",
  20. "VK_PRIOR",
  21. "VK_NEXT",
  22. "VK_END",
  23. "VK_HOME",
  24. "VK_LEFT",
  25. "VK_UP",
  26. "VK_RIGHT",
  27. "VK_DOWN",
  28. "VK_SELECT",
  29. "VK_PRINT",
  30. "VK_EXECUTE",
  31. "VK_SNAPSHOT",
  32. "VK_INSERT",
  33. "VK_DELETE",
  34. "VK_HELP",
  35. "VK_LWIN",
  36. "VK_RWIN",
  37. "VK_APPS",
  38. "VK_NUMPAD0",
  39. "VK_NUMPAD1",
  40. "VK_NUMPAD2",
  41. "VK_NUMPAD3",
  42. "VK_NUMPAD4",
  43. "VK_NUMPAD5",
  44. "VK_NUMPAD6",
  45. "VK_NUMPAD7",
  46. "VK_NUMPAD8",
  47. "VK_NUMPAD9",
  48. "VK_MULTIPLY",
  49. "VK_ADD",
  50. "VK_SEPARATOR",
  51. "VK_SUBTRACT",
  52. "VK_DECIMAL",
  53. "VK_DIVIDE",
  54. "VK_F1",
  55. "VK_F2",
  56. "VK_F3",
  57. "VK_F4",
  58. "VK_F5",
  59. "VK_F6",
  60. "VK_F7",
  61. "VK_F8",
  62. "VK_F9",
  63. "VK_F10",
  64. "VK_F11",
  65. "VK_F12",
  66. "VK_F13",
  67. "VK_F14",
  68. "VK_F15",
  69. "VK_F16",
  70. "VK_F17",
  71. "VK_F18",
  72. "VK_F19",
  73. "VK_F20",
  74. "VK_F21",
  75. "VK_F22",
  76. "VK_F23",
  77. "VK_F24",
  78. "VK_NUMLOCK",
  79. "VK_SCROLL",
  80. "VK_LSHIFT",
  81. "VK_RSHIFT",
  82. "VK_LCONTROL",
  83. "VK_RCONTROL",
  84. "VK_LMENU",
  85. "VK_RMENU",
  86. "VK_ATTN",
  87. "VK_CRSEL",
  88. "VK_EXSEL",
  89. "VK_EREOF",
  90. "VK_PLAY",
  91. "VK_ZOOM",
  92. "VK_NONAME",
  93. "VK_PA1",
  94. "VK_OEM_CLEAR",
  95. // added for Pagasus
  96. "VK_OEM_PLUS",
  97. "VK_OEM_COMMA",
  98. "VK_OEM_MINUS",
  99. "VK_OEM_PERIOD",
  100. "VK_OEM_1",
  101. "VK_OEM_2",
  102. "VK_OEM_3",
  103. "VK_OEM_4",
  104. "VK_OEM_5",
  105. "VK_OEM_6",
  106. "VK_OEM_7",
  107. "VK_OEM_102"
  108. };
  109. DWORD vkdwTable[] =
  110. {
  111. VK_LBUTTON
  112. ,VK_RBUTTON
  113. ,VK_CANCEL
  114. ,VK_MBUTTON
  115. ,VK_BACK
  116. ,VK_TAB
  117. ,VK_CLEAR
  118. ,VK_RETURN
  119. ,VK_SHIFT
  120. ,VK_CONTROL
  121. ,VK_MENU
  122. ,VK_PAUSE
  123. ,VK_CAPITAL
  124. ,VK_ESCAPE
  125. ,VK_SPACE
  126. ,VK_PRIOR
  127. ,VK_NEXT
  128. ,VK_END
  129. ,VK_HOME
  130. ,VK_LEFT
  131. ,VK_UP
  132. ,VK_RIGHT
  133. ,VK_DOWN
  134. ,VK_SELECT
  135. ,VK_PRINT
  136. ,VK_EXECUTE
  137. ,VK_SNAPSHOT
  138. ,VK_INSERT
  139. ,VK_DELETE
  140. ,VK_HELP
  141. ,VK_LWIN
  142. ,VK_RWIN
  143. ,VK_APPS
  144. ,VK_NUMPAD0
  145. ,VK_NUMPAD1
  146. ,VK_NUMPAD2
  147. ,VK_NUMPAD3
  148. ,VK_NUMPAD4
  149. ,VK_NUMPAD5
  150. ,VK_NUMPAD6
  151. ,VK_NUMPAD7
  152. ,VK_NUMPAD8
  153. ,VK_NUMPAD9
  154. ,VK_MULTIPLY
  155. ,VK_ADD
  156. ,VK_SEPARATOR
  157. ,VK_SUBTRACT
  158. ,VK_DECIMAL
  159. ,VK_DIVIDE
  160. ,VK_F1
  161. ,VK_F2
  162. ,VK_F3
  163. ,VK_F4
  164. ,VK_F5
  165. ,VK_F6
  166. ,VK_F7
  167. ,VK_F8
  168. ,VK_F9
  169. ,VK_F10
  170. ,VK_F11
  171. ,VK_F12
  172. ,VK_F13
  173. ,VK_F14
  174. ,VK_F15
  175. ,VK_F16
  176. ,VK_F17
  177. ,VK_F18
  178. ,VK_F19
  179. ,VK_F20
  180. ,VK_F21
  181. ,VK_F22
  182. ,VK_F23
  183. ,VK_F24
  184. ,VK_NUMLOCK
  185. ,VK_SCROLL
  186. ,VK_LSHIFT
  187. ,VK_RSHIFT
  188. ,VK_LCONTROL
  189. ,VK_RCONTROL
  190. ,VK_LMENU
  191. ,VK_RMENU
  192. ,VK_ATTN
  193. ,VK_CRSEL
  194. ,VK_EXSEL
  195. ,VK_EREOF
  196. ,VK_PLAY
  197. ,VK_ZOOM
  198. ,VK_NONAME
  199. ,VK_PA1
  200. ,VK_OEM_CLEAR
  201. // added for Pagasus
  202. ,VK_OEM_PLUS
  203. ,VK_OEM_COMMA
  204. ,VK_OEM_MINUS
  205. ,VK_OEM_PERIOD
  206. ,VK_OEM_1
  207. ,VK_OEM_2
  208. ,VK_OEM_3
  209. ,VK_OEM_4
  210. ,VK_OEM_5
  211. ,VK_OEM_6
  212. ,VK_OEM_7
  213. ,VK_OEM_102
  214. };
  215. int imaxvktable = sizeof(vkdwTable)/sizeof(DWORD);
  216. CAccel::CAccel()
  217. {
  218. m_dwFlags = 0;
  219. m_dwEvent = 0;
  220. m_strText = "";
  221. }
  222. CAccel::CAccel(LPCSTR strText)
  223. {
  224. CString strAcc = strText;
  225. m_dwFlags = 0;
  226. m_dwEvent = 0;
  227. m_strText = "";
  228. // First check for the VIRTKEY or ASCII tag
  229. if(strAcc.Find("VIRTKEY")!=-1)
  230. {
  231. m_dwFlags |= ACC_VK;
  232. // Check for the Key tags
  233. if(strAcc.Find("Ctrl")!=-1)
  234. m_dwFlags |= ACC_CTRL;
  235. if(strAcc.Find("Shift")!=-1)
  236. m_dwFlags |= ACC_SHIFT;
  237. if(strAcc.Find("Alt")!=-1)
  238. m_dwFlags |= ACC_ALT;
  239. // Now clean the string and get the VK code
  240. int iPos = strAcc.Find("VK_");
  241. if(iPos==-1)
  242. {
  243. // something is wrong
  244. m_dwFlags = 0;
  245. m_dwEvent = 0;
  246. m_strText = "";
  247. }
  248. int iCount = 0;
  249. while(strAcc[iPos+iCount]!=',')
  250. iCount++;
  251. m_dwEvent = StringToVK(strAcc.Mid(iPos, iCount));
  252. }
  253. else if(strAcc.Find("ASCII")!=-1)
  254. {
  255. // Check for the Key tags
  256. if(strAcc.Find("Ctrl")!=-1)
  257. {
  258. int iPos = strAcc.Find('+');
  259. if(iPos!=-1)
  260. {
  261. m_dwEvent = ((DWORD)strAcc[iPos+1])-0x40;
  262. }
  263. }
  264. else if(strAcc.Find("Alt")!=-1)
  265. {
  266. int iPos = strAcc.Find('+');
  267. if(iPos!=-1)
  268. {
  269. m_dwEvent = ((DWORD)strAcc[iPos+1]);
  270. m_dwFlags |= ACC_ALT;
  271. }
  272. }
  273. else
  274. {
  275. m_dwEvent = (DWORD)strAcc[0];
  276. }
  277. }
  278. }
  279. CAccel::CAccel(DWORD dwFlags, DWORD dwEvent)
  280. {
  281. m_dwFlags = dwFlags;
  282. m_dwEvent = dwEvent;
  283. // Accelerator handling
  284. if(ISACCFLG(m_dwFlags, ACC_CTRL))
  285. m_strText += "Ctrl+";
  286. if(ISACCFLG(m_dwFlags, ACC_SHIFT))
  287. m_strText += "Shift+";
  288. if(ISACCFLG(m_dwFlags, ACC_ALT))
  289. m_strText += "Alt+";
  290. if(ISACCFLG(m_dwFlags, ACC_VK))
  291. {
  292. m_strText += VKToString(m_dwEvent);
  293. m_strText += ", VIRTKEY";
  294. }
  295. else
  296. {
  297. if(m_dwEvent + 0x40 >= 'A' && m_dwEvent + 0x40 <= 'Z')
  298. {
  299. m_strText += "Ctrl+";
  300. m_strText += (char)(m_dwEvent + 0x40);
  301. }
  302. else m_strText += (char)m_dwEvent;
  303. m_strText += ", ASCII";
  304. }
  305. }
  306. CString CAccel::VKToString(DWORD dwEvent)
  307. {
  308. CString strVK = "";
  309. if((dwEvent >= 0x30) && (dwEvent <= 0x5A))
  310. {
  311. strVK = "VK_";
  312. strVK += (char)dwEvent;
  313. }
  314. int i = 0;
  315. while(i<imaxvktable)
  316. {
  317. if(dwEvent==vkdwTable[i++])
  318. {
  319. strVK = vkstrTable[i-1];
  320. break;
  321. }
  322. }
  323. return strVK;
  324. }
  325. DWORD CAccel::StringToVK(CString str)
  326. {
  327. DWORD dwVK = 0;
  328. if(str.GetLength()==4)
  329. {
  330. // remove the VK_ and get the char
  331. str = str.Mid(3);
  332. dwVK = (DWORD)str[0];
  333. }
  334. else
  335. {
  336. int i = 0;
  337. while(i<imaxvktable)
  338. {
  339. if(str==vkstrTable[i++])
  340. {
  341. dwVK = vkdwTable[i-1];
  342. break;
  343. }
  344. }
  345. }
  346. return dwVK;
  347. }