VB中SendMessage和postmessage的详细用法。
3个回答
2013-09-25
展开全部
SendMessage : 发送一个消息给操作系统,并且等待操作系统执行完这个消息。postmessage : 发送一个消息给操作系统,不等待操作系统执行完这个消息就立即返回执行下一条语句。 SendMessage 定义:Public Shared Sub SendMessage ( _ ByRef m As Message _ ) SendMessage 调用: Dim m As Message MessageWindow.SendMessage(m) postmessage 定义: Public Shared Sub PostMessage ( _ ByRef m As Message _ ) postmessage 调用: Dim m As Message MessageWindow.PostMessage(m) 它们的定义和调用格式是一样的,只是执行时的效果不一样,刚才我已经说过了。 参数的m含义: 是一个windows的消息结构体,用来描述传递的消息。 比如: Dim msg As Microsoft.WindowsCE.Forms.Message = _ Microsoft.WindowsCE.Forms.Message.Create(MsgWin.Hwnd, _ MsgWindow.WM_CUSTOMMSG, New IntPtr(e.X), New IntPtr(e.Y)) MessageWindow.SendMessage(msg)MsgWin.Hwnd :表示消息的句柄。MsgWindow.WM_CUSTOMMSG :表示消息的ID,就是一个唯一的消息的标识号,是一个整数。IntPtr(e.X) 和 New IntPtr(e.Y) : 消息的两个附加参数,这要根据具体的消息而论了。
2013-09-25
展开全部
先Copy两段权威的。 SendMessage, SendMessageBynum, SendMessageByStringVB声明Declare Function SendMessage& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
Declare Function SendMessageBynum& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
Declare Function SendMessageByString& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String)说明调用一个窗口的窗口函数,将一条消息发给那个窗口。除非消息处理完毕,否则该函数不会返回。SendMessageBynum, SendMessageByString是该函数的“类型安全”声明形式返回值Long,由具体的消息决定参数表参数类型及说明hwndLong,要接收消息的那个窗口的句柄wMsgLong,消息的标识符wParamLong,具体取决于消息lParamAny,具体取决于消息 PostMessage, PostMessageBynum, PostMessageBystringVB声明Declare Function PostMessage& Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
Declare Function PostMessageByNum& Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
Declare Function PostMessageByString& Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String)说明将一条消息投递到指定窗口的消息队列。投递的消息会在Windows事件处理过程中得到处理。在那个时候,会随同投递的消息调用指定窗口的窗口函数。特别适合那些不需要立即处理的窗口消息的发送返回值Long,如消息投递成功,则返回TRUE(非零)。会设置GetLastError参数表参数类型及说明hwndLong,接收消息的那个窗口的句柄。如设为HWND_BROADCAST,表示投递给系统中的所有顶级窗口。如设为零,表示投递一条线程消息(参考PostThreadMessage)wMsgLong,消息标识符wParamLong,具体由消息决定lParamAny,具体由消息决定 最后我来说一下两者的主要区别,SendMessage发送消息之后是要等目标窗口处理完该消息之后函数才会返回,而PostMessage是立刻返回,其它的基本一样。一般我喜欢用PostMessage。
Declare Function SendMessageBynum& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
Declare Function SendMessageByString& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String)说明调用一个窗口的窗口函数,将一条消息发给那个窗口。除非消息处理完毕,否则该函数不会返回。SendMessageBynum, SendMessageByString是该函数的“类型安全”声明形式返回值Long,由具体的消息决定参数表参数类型及说明hwndLong,要接收消息的那个窗口的句柄wMsgLong,消息的标识符wParamLong,具体取决于消息lParamAny,具体取决于消息 PostMessage, PostMessageBynum, PostMessageBystringVB声明Declare Function PostMessage& Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
Declare Function PostMessageByNum& Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
Declare Function PostMessageByString& Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String)说明将一条消息投递到指定窗口的消息队列。投递的消息会在Windows事件处理过程中得到处理。在那个时候,会随同投递的消息调用指定窗口的窗口函数。特别适合那些不需要立即处理的窗口消息的发送返回值Long,如消息投递成功,则返回TRUE(非零)。会设置GetLastError参数表参数类型及说明hwndLong,接收消息的那个窗口的句柄。如设为HWND_BROADCAST,表示投递给系统中的所有顶级窗口。如设为零,表示投递一条线程消息(参考PostThreadMessage)wMsgLong,消息标识符wParamLong,具体由消息决定lParamAny,具体由消息决定 最后我来说一下两者的主要区别,SendMessage发送消息之后是要等目标窗口处理完该消息之后函数才会返回,而PostMessage是立刻返回,其它的基本一样。一般我喜欢用PostMessage。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-09-25
展开全部
又是这2个函数,,,,也难怪,用处大呗留下邮箱吧,我吧视频教程发给你
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询