# Re: 如何送一字串至某一视窗

Posted by chjichin on December 18, 1998 at 11:51:11:

In Reply to: Re: 如何送一字串至某一视窗 posted by 七枷社 on December 16, 1998 at 18:18:10:

: : 如何送一字串至某一视窗

: 希望下面的程式能帮到你。

: You can use the FindWindow and PostMessage API functions to find a window and then close it. This example show how you can close down a Window with a caption of "Calculator".

: Dim winHwnd As Long
: Dim RetVal As Long
: winHwnd = FindWindow(vbNullString, "Calculator")
: Debug.Print winHwnd
: If winHwnd <> 0 Then
: RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)
: If RetVal = 0 Then
: MsgBox "Error posting message."
: End If
: Else
: MsgBox "The Calculator is not open."
: End If
:
: For this code to work, you must have declared the API functions in a module in your project. You must put the following in the declarations section of the module.

: Declare Function FindWindow Lib "user32" Alias _
: "FindWindowA" (ByVal lpClassName As String, _
: ByVal lpWindowName As String) As Long
: Declare Function PostMessage Lib "user32" Alias _
: "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
: ByVal wParam As Long, lParam As Any) As Long
: Public Const WM_CLOSE = &H10

谢谢!
但是假设我试的结果,并没有办法送出字串,可否指导一下.

Follow Ups:

- Re: 如何送一字串至某一视窗 cww 16:47:47 12/18/98 (0)