WINAPI MessageBox在消息队列中调用时,无法正常显示

蹦跶的钟 20 信誉分
2025-06-24T09:19:28.7366667+00:00

不会立即显示,但是可以使用Enter关闭消息框。只有按Alt时,消息框才会显示出来。

调用代码为

case WM_LBUTTONDOWN:
{

	MessageBox(NULL, L"123", L"错误", MB_OK);
}
开发人员技术 | C++
开发人员技术 | C++
一种通用的高级编程语言,作为 C 编程语言的扩展而创建,除了用于低级别内存操作的功能外,还具有面向对象、泛型和功能性等特点。
0 个注释 无注释
{count} 票

1 个答案

排序依据: 非常有帮助
  1. Gade Harika (INFOSYS LIMITED) 2,020 信誉分 Microsoft 外部员工
    2025-11-14T09:09:16.83+00:00
    • Thanks for reaching out.
      Calling MessageBox inside WM_LBUTTONDOWN doesn’t show immediately and only appears after pressing Alt. Cause:
      The message box is not getting proper foreground activation or ownership, or it conflicts with the current mouse/paint message phase. Solutions:
      1. Pass the parent window and bring it to the foreground:
      C++ MessageBox(hWnd, L"123", L"Error", MB_OK | MB_SETFOREGROUND | MB_TOPMOST); Show more lines
      1. Delay showing the message box by posting a custom message:
      C++ PostMessage(hWnd, WM_APP + 1, 0, 0); // In WM_APP+1 handler, call MessageBox Show more lines
      1. Check and fix WM_PAINT or continuous redraw issues that may block the message loop.
      References: Let us know if the issue persists after following these steps. I’ll be happy to assist further if needed. If the issue has been resolved, Kindly mark the provided solution as "Accept Answer", so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

你的答案

提问者可以将答案标记为“已接受”,版主可以将答案标记为“已推荐”,这有助于用户了解答案是否解决了提问者的问题。