是否可以向 Win32Gui 中的 WindowProcedure 发送自定义消息?

Is it possible to send a custom message to the WindowProcedure in Win32Gui?

很抱歉,如果我问了一些荒谬的问题(我是 win32 菜鸟),但我想知道是否 happen.Is 我们可以根据自己的情况更改消息并在 switch 中处理它(消息)如代码所示?

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{

      switch (message){      

          case WM_DESTROY:
              PostQuitMessage(0);
              break;

          case FindWindowA(NULL,"Task Manager"): // like this 
              //do something
              break;

          default:
              return DefWindowProc(hwnd,message,wParam,lParam);

      } 

      return 0;
}

您可以定义新消息:

#define WM_MY_MSG (WM_USER+0)

#define WM_MY_MSG (WM_APP+0)

请注意 WM_USER + x 范围内的消息对 window class 是私有的,而应用程序私有消息需要在 WM_APP + x 范围内范围。 然后使用 SendMessagePostMessage API 函数将此消息发送到具有已知处理程序 (hwnd) 的 window。 并进一步处理它:

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{

      switch (message){      

          case WM_DESTROY:
              PostQuitMessage(0);
              break;

          case WM_MY_MSG: // like this 
              // Do something, for example FindWindowA(NULL,"Task Manager")
              break;

          default:
              return DefWindowProc(hwnd,message,wParam,lParam);

      } 

      return 0;
}