先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。