在SendMessage()中,WPARAM 参数 和LPARAM 有什么不一样?

HUSTCPH 2005-04-15 04:45:19
MSDN上只是说都是Specifies additional message-specific information.
但是这两者好像有区别的,不能互换,有人知道这两者有什么不同吗?
...全文
225 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
charleschung 2005-04-15
  • 打赏
  • 举报
回复
WPARAM 和 LPARAM 本质上没有什么区别:都是32位数,
但是区别也还是有的:除了上面几位若仁兄说的关于16位的的历史问题外,MICROSOFT在使用时两种参数分别代表不同的含义和内容,WPARAM常常代表一些控件的ID或者高位底位组合起来分别表示鼠标的未知,如果消息的发送者需要将某种结构的指针或者是某种类型的句柄时,习惯上用LPARAM来传递,可以参考各种控件的通知消息:可以查看:EN_CHANGE (EDIT控件的一个通知消息),CBEM_INSERTITEM(可扩展组合框的可接受消息)等等来加以领会。
理论上在使用自定义消息时,WPARAM LPARAM的含义可以程序员任意指定的,但是最好遵从MFC中的习惯。在调用SendMessage()函数时,第二个参数是WPARAM,第三个参数是这个消息的LPARAM,但是你在程序中某个类中写下ON_MESSAGE()宏来处理这个消息时,处理函数SomeHandler(WPARAM,LPRAM(默认是0))中解释这两个参数时必须按照SendMessage调用中的意义来进行。
Hendy_So 2005-04-15
  • 打赏
  • 举报
回复
我所说的是两个参数不能换,不同的情况下各有不同的含义,至于两个参数的类型WPARAM及LPARAM,它们的定义是:
#endif // !_LONG_DEFINED
#ifndef _WPARAM_DEFINED
#define _WPARAM_DEFINED
typedef UINT WPARAM;

#endif // !_DWORD_DEFINED
#ifndef _LPARAM_DEFINED
#define _LPARAM_DEFINED
typedef LONG LPARAM;

我上面所说的歧义就是我们分别把你所说的区别理解成了参数本身与参数类型了。
HUSTCPH 2005-04-15
  • 打赏
  • 举报
回复
但是 Hendy_So()说得也有道理啊,这两者之间是有区别的,特别是在SendMessage()中,是不能互换的,到底怎么回事呢
qiangv 2005-04-15
  • 打赏
  • 举报
回复
mark一下,聆听一下
Hendy_So 2005-04-15
  • 打赏
  • 举报
回复
晕,看样子问题出现歧义了,呵呵。
wshcdr 2005-04-15
  • 打赏
  • 举报
回复
没有区别,都是32位数据,用不同的名称是因为最初的16位windowsyongWPARAM表示一个16位数据,LPARAM表示32位数据,现在32位的windows系统两个参数都是32位,用不同的名字是为了兼容性考虑

//////////////////////
正解!
  • 打赏
  • 举报
回复
没有区别,都是32位数据,用不同的名称是因为最初的16位windowsyongWPARAM表示一个16位数据,LPARAM表示32位数据,现在32位的windows系统两个参数都是32位,用不同的名字是为了兼容性考虑
mahatma_cn 2005-04-15
  • 打赏
  • 举报
回复
所以,你Sendmessage时不能对换他们的位置,否则系统无法解释你的消息的附加信息!出现错误
mahatma_cn 2005-04-15
  • 打赏
  • 举报
回复
具体哪个参数放什么,取决于消息本身,每个消息不尽相同!参考msdn
Hendy_So 2005-04-15
  • 打赏
  • 举报
回复
不同的消息两个参数有不同的含义,具体查MSDN,如:
对于WM_KEYDOWN:
wParam
Specifies the virtual-key code of the nonsystem key.
lParam
Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown in the following table.

对于WM_LBUTTONDOWN:
wParam
Indicates whether various virtual keys are down. This parameter can be one or more of the following values. Value Description
MK_CONTROL The CTRL key is down.
MK_LBUTTON The left mouse button is down.
MK_MBUTTON The middle mouse button is down.
MK_RBUTTON The right mouse button is down.
MK_SHIFT The SHIFT key is down.
MK_XBUTTON1 Windows 2000/XP: The first X button is down.
MK_XBUTTON2 Windows 2000/XP: The second X button is down.

lParam
The low-order word specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.
The high-order word specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.

xqk 2005-04-15
  • 打赏
  • 举报
回复
up
#region 导入API函数 [DllImport("avicap32.dll")]//包含了执行视频捕获的函数,它给AVI文件I/O和视频、音频设备驱动程序提供一个高级接口 public static extern IntPtr capCreateCaptureWindow(string lpszWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hwndParent, int nID); /************参数说明************* * * 函数:capCreateCaptureWindow * * lpszWindowName:标识窗口的名称 * dwStyle:标识窗口风格 * x、y:标识窗口的左上角坐标 * nWidth、nHeight:标识窗口的宽度和高度 * hWnd:标识父窗口句柄 * nID:标识窗口ID * * 返回值:视频捕捉窗口句柄。 * ********************************/ [DllImport("AVICAP32.dll", CharSet = CharSet.Unicode)] public static extern bool capGetDriverDescription(int wDriverIndex, StringBuilder lpszName, int cbName, StringBuilder lpszVer, int cbVer); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, bool wParam, int lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, short wParam, int lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, short wParam, FrameEventHandler lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, ref BITMAPINFO lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, ref CAPDRIVERCAPS lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, ref CAPTUREPARMS lParam); [DllImport("User32.dll")] public static extern bool SendMessage(IntPtr hWnd, int wMsg, int wParam, ref CAPSTATUS lParam); [DllImport("User32.dll")] public static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags); [DllImport("avicap32.dll")] public static extern int capGetVideoFormat(IntPtr hWnd, IntPtr psVideoFormat, int wSize); #endregion

16,551

社区成员

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

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

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