鱼C论坛

 找回密码
 立即注册
查看: 2416|回复: 1

WM_SYSDEADCHAR 消息问题

[复制链接]
发表于 2013-11-20 19:02:57 | 显示全部楼层 |阅读模式
1鱼币
代码如下:

  1. /*--------------------------------------------------------
  2. KEYVIEW1.C -- Displays Keyboard and Character Messages
  3. (c) Charles Petzold, 1998
  4. --------------------------------------------------------*/

  5. #include <windows.h>

  6. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;

  7. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  8. PSTR szCmdLine, int iCmdShow)
  9. {
  10. static TCHAR szAppName[] = TEXT ("KeyView1") ;
  11. HWND hwnd ;
  12. MSG msg ;
  13. WNDCLASS wndclass ;

  14. wndclass.style = CS_HREDRAW | CS_VREDRAW ;
  15. wndclass.lpfnWndProc = WndProc ;
  16. wndclass.cbClsExtra = 0 ;
  17. wndclass.cbWndExtra = 0 ;
  18. wndclass.hInstance = hInstance ;
  19. wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
  20. wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
  21. wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
  22. wndclass.lpszMenuName = NULL ;
  23. wndclass.lpszClassName = szAppName ;

  24. if (!RegisterClass (&wndclass))
  25. {
  26. MessageBox (NULL, TEXT ("This program requires Windows NT!"),
  27. szAppName, MB_ICONERROR) ;
  28. return 0 ;
  29. }

  30. hwnd = CreateWindow (szAppName, TEXT ("Keyboard Message Viewer #1"),
  31. WS_OVERLAPPEDWINDOW,
  32. CW_USEDEFAULT, CW_USEDEFAULT,
  33. CW_USEDEFAULT, CW_USEDEFAULT,
  34. NULL, NULL, hInstance, NULL) ;

  35. ShowWindow (hwnd, iCmdShow) ;
  36. UpdateWindow (hwnd) ;

  37. while (GetMessage (&msg, NULL, 0, 0))
  38. {
  39. TranslateMessage (&msg) ;
  40. DispatchMessage (&msg) ;
  41. }
  42. return msg.wParam ;
  43. }

  44. LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  45. {
  46. static int cxClientMax, cyClientMax, cxClient, cyClient, cxChar, cyChar ;
  47. static int cLinesMax, cLines ;
  48. static PMSG pmsg ;
  49. static RECT rectScroll ;
  50. static TCHAR szTop[] = TEXT ("Message Key Char ")
  51. TEXT ("Repeat Scan Ext ALT Prev Tran") ;
  52. static TCHAR szUnd[] = TEXT ("_______ ___ ____ ")
  53. TEXT ("______ ____ ___ ___ ____ ____") ;

  54. static TCHAR * szFormat[2] = {

  55. TEXT ("%-13s %3d %-15s%c%6u %4d %3s %3s %4s %4s"),
  56. TEXT ("%-13s 0x%04X%1s%c %6u %4d %3s %3s %4s %4s") } ;

  57. static TCHAR * szYes = TEXT ("Yes") ;
  58. static TCHAR * szNo = TEXT ("No") ;
  59. static TCHAR * szDown = TEXT ("Down") ;
  60. static TCHAR * szUp = TEXT ("Up") ;

  61. static TCHAR * szMessage [] = {
  62. TEXT ("WM_KEYDOWN"), TEXT ("WM_KEYUP"),
  63. TEXT ("WM_CHAR"), TEXT ("WM_DEADCHAR"),
  64. TEXT ("WM_SYSKEYDOWN"), TEXT ("WM_SYSKEYUP"),
  65. TEXT ("WM_SYSCHAR"), TEXT ("WM_SYSDEADCHAR") } ;
  66. HDC hdc ;
  67. int i, iType ;
  68. PAINTSTRUCT ps ;
  69. TCHAR szBuffer[128], szKeyName [32] ;
  70. TEXTMETRIC tm ;

  71. switch (message)
  72. {
  73. case WM_CREATE:
  74. case WM_DISPLAYCHANGE:

  75. // Get maximum size of client area

  76. cxClientMax = GetSystemMetrics (SM_CXMAXIMIZED) ;
  77. cyClientMax = GetSystemMetrics (SM_CYMAXIMIZED) ;

  78. // Get character size for fixed-pitch font

  79. hdc = GetDC (hwnd) ;

  80. SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT)) ;
  81. GetTextMetrics (hdc, &tm) ;
  82. cxChar = tm.tmAveCharWidth ;
  83. cyChar = tm.tmHeight ;

  84. ReleaseDC (hwnd, hdc) ;

  85. // Allocate memory for display lines

  86. if (pmsg)
  87. free (pmsg) ;

  88. cLinesMax = cyClientMax / cyChar ;
  89. pmsg = malloc (cLinesMax * sizeof (MSG)) ;
  90. cLines = 0 ;
  91. // fall through
  92. case WM_SIZE:
  93. if (message == WM_SIZE)
  94. {
  95. cxClient = LOWORD (lParam) ;
  96. cyClient = HIWORD (lParam) ;
  97. }
  98. // Calculate scrolling rectangle

  99. rectScroll.left = 0 ;
  100. rectScroll.right = cxClient ;
  101. rectScroll.top = cyChar ;
  102. rectScroll.bottom = cyChar * (cyClient / cyChar) ;

  103. InvalidateRect (hwnd, NULL, TRUE) ;
  104. return 0 ;

  105. case WM_KEYDOWN:
  106. case WM_KEYUP:
  107. case WM_CHAR:
  108. case WM_DEADCHAR:
  109. case WM_SYSKEYDOWN:
  110. case WM_SYSKEYUP:
  111. case WM_SYSCHAR:
  112. case WM_SYSDEADCHAR:

  113. // Rearrange storage array

  114. for (i = cLinesMax - 1 ; i > 0 ; i--)
  115. {
  116. pmsg[i] = pmsg[i - 1] ;
  117. }
  118. // Store new message

  119. pmsg[0].hwnd = hwnd ;
  120. pmsg[0].message = message ;
  121. pmsg[0].wParam = wParam ;
  122. pmsg[0].lParam = lParam ;

  123. cLines = min (cLines + 1, cLinesMax) ;

  124. // Scroll up the display

  125. ScrollWindow (hwnd, 0, -cyChar, &rectScroll, &rectScroll) ;

  126. break ; // ie, call DefWindowProc so Sys messages work

  127. case WM_PAINT:
  128. hdc = BeginPaint (hwnd, &ps) ;

  129. SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT)) ;
  130. SetBkMode (hdc, TRANSPARENT) ;
  131. TextOut (hdc, 0, 0, szTop, lstrlen (szTop)) ;

  132. TextOut (hdc, 0, 0, szUnd, lstrlen (szUnd)) ;

  133. for (i = 0 ; i < min (cLines, cyClient / cyChar - 1) ; i++)
  134. {
  135. iType = pmsg[i].message == WM_CHAR ||
  136. pmsg[i].message == WM_SYSCHAR ||
  137. pmsg[i].message == WM_DEADCHAR ||
  138. pmsg[i].message == WM_SYSDEADCHAR ;

  139. GetKeyNameText (pmsg[i].lParam, szKeyName,
  140. sizeof (szKeyName) / sizeof (TCHAR)) ;

  141. TextOut (hdc, 0, (cyClient / cyChar - 1 - i) * cyChar, szBuffer,
  142. wsprintf (szBuffer, szFormat [iType],
  143. szMessage [pmsg[i].message - WM_KEYFIRST],
  144. pmsg[i].wParam,
  145. (PTSTR) (iType ? TEXT (" ") : szKeyName),
  146. (TCHAR) (iType ? pmsg[i].wParam : ' '),
  147. LOWORD (pmsg[i].lParam),
  148. HIWORD (pmsg[i].lParam) & 0xFF,
  149. 0x01000000 & pmsg[i].lParam ? szYes : szNo,
  150. 0x20000000 & pmsg[i].lParam ? szYes : szNo,
  151. 0x40000000 & pmsg[i].lParam ? szDown : szUp,
  152. 0x80000000 & pmsg[i].lParam ? szUp : szDown)) ;
  153. }
  154. EndPaint (hwnd, &ps) ;
  155. return 0 ;

  156. case WM_DESTROY:
  157. PostQuitMessage (0) ;
  158. return 0 ;
  159. }
  160. return DefWindowProc (hwnd, message, wParam, lParam) ;
  161. }
复制代码

调试这个程序的时候发现,只要按下任意一个键 窗口过程就会收到  WM_SYSDEADCHAR消息
这个消息不是要按Alt+某键 才会产生吗,为什么随便按一个键就会有  WM_SYSDEADCHAR 这个消息呢
求解答

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2013-11-26 22:14:16 | 显示全部楼层
本帖最后由 如梦幻泡影 于 2013-11-26 22:15 编辑

WM_SYSDEADCHAR
The WM_SYSDEADCHAR message is sent to the window with the keyboard focus when a WM_SYSKEYDOWN message is translated by the TranslateMessage function. WM_SYSDEADCHAR specifies the character code of a system dead key — that is, a dead key that is pressed while holding down the alt key.

感觉跟参数有关系的,感觉而已啊==!
29 Specifies the context code. The value is 1 if the ALT key is down while the key is pressed; it is 0 if the WM_SYSKEYDOWN message is posted to the active window because no window has the keyboard focus.
//谷歌翻译:29指定上下文代码。该值是1 ,如果Alt键不放,同时按下键,否则,该值为0

判断是否有按下alt,还可以用GetKeyState这个来判断
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-1 14:04

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表