我想模拟WM_COMMAND

lsaturn 2004-04-05 02:04:48
我有一个id为IDC_FINALPROT的控件
hwndTemp = GetDlgItem(hwnd, IDC_FINALPROT);//这个hwnd是正确的,大家就不要怀疑了!
SendMessage(hwnd, WM_COMMAND, IDC_FINALPROT, (LPARAM)hwndTemp);
我想这样来发消息来模拟WM_COMMAND
在hwnd的消息循环中是这样处理的
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_FINALPROT:
为什么无法响应我自己发的消息?

...全文
91 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lsaturn 2004-04-08
  • 打赏
  • 举报
回复
up一下
lsaturn 2004-04-05
  • 打赏
  • 举报
回复
up一下
lsaturn 2004-04-05
  • 打赏
  • 举报
回复
我也看了msdn
但是NOTIFY_CODE是什么呢?
我这里是点击一个check box
QunKangLi 2004-04-05
  • 打赏
  • 举报
回复
WM_COMMAND的LPARAM参数是处理该消息的窗口,WPARAM才是的低16位是发送方的控件ID,高16位是通知代码.正确的发送方法是:
#define NOTIFY_CODE IDC_FINALPROT
SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDC_FINALPROT,NOTIFY_CODE), (LPARAM)hwnd);

WM_COMMAND
The WM_COMMAND message is sent when the user selects a command item from a menu, when a control sends a notification message to its parent window, or when an accelerator keystroke is translated.

A window receives this message through its WindowProc function.

LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_COMMAND
WPARAM wParam, // notification code and identifier
LPARAM lParam // handle to control (HWND)
);
Parameters
wParam
The high-order word specifies the notification code if the message is from a control. If the message is from an accelerator, this value is 1. If the message is from a menu, this value is zero.
The low-order word specifies the identifier of the menu item, control, or accelerator.

lParam
Handle to the control sending the message if the message is from a control. Otherwise, this parameter is NULL.
Return Values
If an application processes this message, it should return zero.

Remarks
Accelerator keystrokes that select items from the window menu are translated into WM_SYSCOMMAND messages.

If an accelerator keystroke occurs that corresponds to a menu item when the window that owns the menu is minimized, no WM_COMMAND message is sent. However, if an accelerator keystroke occurs that does not match any of the items in the window's menu or in the window menu, a WM_COMMAND message is sent, even if the window is minimized.

If an application enables a menu separator, the system sends a WM_COMMAND message with the low-word of the wParam parameter set to zero when the user selects the separator.

Windows 98, Windows 2000: If a menu is defined with a MENUINFO.dwStyle value of MNS_NOTIFYBYPOS, WM_MENUCOMMAND is sent instead of WM_COMMAND.

Requirements
Windows NT/2000: Requires Windows NT 3.1 or later.
Windows 95/98: Requires Windows 95 or later.
Header: Declared in Winuser.h; include Windows.h.


lsaturn 2004-04-05
  • 打赏
  • 举报
回复
那应该怎么处理?
因为我要和正常的点击相兼容!
SendMessage(hwnd, WM_COMMAND, MAKEWPAMRAM(IDC_FINALPROT,3), (LPARAM)hwndTemp);
这样也不行
_foo 2004-04-05
  • 打赏
  • 举报
回复
你SendMessage时没把ID搞到LOWORD里,在处理时却从LOWORD取出来。。。
_foo 2004-04-05
  • 打赏
  • 举报
回复
LOWORD(wParam)?????

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧