导航:
论坛 -> DELPHI技术
斑竹:liumazi,sephil
作者:
zxdcj (月下舞者)
★☆☆☆☆
-
盒子活跃会员
2003/12/23 19:30:33
标题:
请大家帮帮我这个笨学生吧(关于消息)!
浏览:2712
加入我的收藏
楼主:
学习消息过程中的一堆疑问: 1: wparam,lparam的值是怎么回事?是自己定的吗? 2: function PostMessage(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): BOOL; stdcall; function SendMessage(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; function TControl.Perform(Msg: Cardinal; WParam, LParam: Longint): Longint; 这三个定义中的Msg是一回事吗?怎么用的类型乱七八糟的, 3: 我还看到有的文档写到msg.msg(在procedure Tform1.WndProc(var msg:TMessage),这又是怎么回事啊,为什么要这样写啊? 4: 还有用TMessage(msg).msg:=……(procedure TForm1.DefaultHandler(var Msg);)的,这又是怎么回事啊? 5: 还有在消息定义中的msg参数到底该用什么类型的啊,怎么有用TMsg还有用TMessage的啊,它们肯定是不一样的,但什么时候用TMsg,什么时候用TMessage啊? 麻烦大家给解释解释吧,这些家伙已经把我的脑袋搞的很大很大了,大家不要因为我笨而不管我啊,不要把一个要当将军的笨兵给扼杀在初学者的大道上啊!!!谢谢大家了,拜托了!
----------------------------------------------
-
作者:
zxdcj (月下舞者)
★☆☆☆☆
-
盒子活跃会员
2003/12/23 19:50:55
1楼:
我知道我的这个问题挺烦,但我是真的被憋住了,哪怕您只帮我一条我也能解决一些问题啊!
----------------------------------------------
-
作者:
bios (阿贡)
★☆☆☆☆
-
盒子中级会员
2003/12/23 19:57:08
2楼:
偶也吓了一跳, 因为偶对这些消息映射 都是 看DELPHI的帮助(虽然是英文,但也要认真看) 由于对DELPHI的帮助的理解不一定对, 所以不敢乱讲 请原谅! 这回很难帮忙了!
----------------------------------------------
作者:
bios (阿贡)
★☆☆☆☆
-
盒子中级会员
2003/12/23 20:11:59
3楼:
第一: wParam Specifies additional message-specific information. lParam Specifies additional message-specific information. 第二: API函数的完整使用 ,一般都带有 句柄开头: 所以前面两个API 的参数是正常现象 而function TControl.Perform(Msg: Cardinal; WParam, LParam: Longint): Longint; var Message: TMessage; begin Message.Msg := Msg; Message.WParam := WParam; Message.LParam := LParam; Message.Result := 0; if Self <> nil then WindowProc(Message); Result := Message.Result; end; 在TControl 中 句柄已经被封装在 TControl 的 私有成员变量中 所以不用 比一般API函数 对一个参数 WindowProc是回调 偶们自己的 函数或结构体 表示 WINDOWS处理 有参数传进来的消息 第三: TMessage = packed record Msg: Cardinal; case Integer of 0: ( WParam: Longint; LParam: Longint; Result: Longint); 1: ( WParamLo: Word; WParamHi: Word; LParamLo: Word; LParamHi: Word; ResultLo: Word; ResultHi: Word); end; 这是他的结构体 里面有一个 变量 var msg:TMessage表示msg 是TMessage结构体 类型的变量 msg.msg表示具体变量调用这个结构体 类型的数据成员 第4: TMsg encodes the information from a Windows message. Unit Windows Delphi syntax: type TMsg = packed record hwnd: HWND; message: UINT; wParam: WPARAM; lParam: LPARAM; time: DWORD; pt: TPoint; end; C++ syntax: typedef struct tagMSG { HWND hwnd; UINT message; WPARAM wParam; LPARAM lParam; DWORD time; POINT pt; } MSG; typedef tagMSG TMsg; Description The TMsg type is holds the details of a Windows message. This is the structure that Windows uses to encode a message, as opposed to the TMessage type, which encodes the parameters that are passed to a CLX Window procedure. Note: In C++, TMsg is defined in terms of the tagMSG struct, which is defined in Winuser.h. The following table list the fields of TMsg: Field Meaning hwnd The handle of the window to which the message is sent. message The identifier of the message (the Windows message code). wParam The wParam of the message. lParam The lParam of the message. time The time that the message was sent. pt The position of the mouse cursor when the message was sent. 从帮助文件中看出 TMsg也是一个消息结构体 但他用于 CLX的 工程 软件中 至于CLX是什么???偶也不知道啦!
----------------------------------------------
作者:
avay (糖醋鼻子)
★☆☆☆☆
-
盒子活跃会员
2003/12/23 20:33:11
3楼:
看《WINDOWS程序设计》
----------------------------------------------
-
作者:
bios (阿贡)
★☆☆☆☆
-
盒子中级会员
2003/12/23 20:37:50
4楼:
请给出下载链接 谢谢大哥!
----------------------------------------------
作者:
zxdcj (月下舞者)
★☆☆☆☆
-
盒子活跃会员
2003/12/23 21:24:01
5楼:
先谢谢BIOS,我要研读研读!
----------------------------------------------
-
作者:
sephil (NAILY Soft)
★☆☆☆☆
-
盒子中级会员
2003/12/23 21:57:50
6楼:
1.WParam, LParam可以看做是参数 因为有很多消息都是要带参数的 2.PostMessage和SendMessage作用基本一样 只是SendMessage会等到函数完成才返回 而PostMessage不等函数完成就返回 Perform用法基本和SendMessage一样 研究一下TControl的源码你就知道了 3.msg.msg(在procedure Tform1.WndProc(var msg:TMessage) AMsg.Msg(在procedure TForm1.WndProc(var AMsg: TMessage)是一样的 前面的Msg就是调用的参数里的Msg,是个TMessage类型的参数,参数名字教Msg而已 后面的Msg是TMessage结构的一个成员,也就是具体的消息,也就是WM_KILLFOCUS之类的值 4.TMessage(Msg).Msg TMessage(Msg)将Msg强制转换为TMessage类型 TMessage(Msg).Msg则是取Msg的具体消息 5.一般不用TMsg,用TMessage就可以了 另外,SendMessage/PostMessage都用整形值作参数 如: SendMessage(Form1.Handle, WM_KEYDOWN, Ord('C'), 0); 发送按键(C键)消息给Form1
----------------------------------------------
Copyright 2008 ? NAILY Soft
Click here to redirect to my home Click here to redirect to my blog
作者:
zxdcj (月下舞者)
★☆☆☆☆
-
盒子活跃会员
2003/12/23 22:01:10
6楼:
《WINDOWS程序设计》 http://www.codestudy.net/book/list.asp?id=1193 用 湖北FTP 下
----------------------------------------------
-
作者:
zxdcj (月下舞者)
★☆☆☆☆
-
盒子活跃会员
2003/12/23 22:23:29
7楼:
多谢sephil兄,现在还在单位吗?
----------------------------------------------
-
作者:
zxdcj (月下舞者)
★☆☆☆☆
-
盒子活跃会员
2003/12/24 8:44:21
9楼:
啊,把你当花心萝卜了。 不过你给我的感觉就是一个富有经验的高手!!!
----------------------------------------------
-
作者:
zxdcj (月下舞者)
★☆☆☆☆
-
盒子活跃会员
2003/12/24 10:55:48
11楼:
呵,谦虚
----------------------------------------------
-