FindWindow API HELP! 
Author Message
 FindWindow API HELP!

I have written a program in C++ & a program in VB4 (16-bit).
The VB program need to sendmessage to the C++ program whenever a
command button is click.

My solution is to use FindWindow() to get the window handler of the
C++ Program("My Program"). Then using the handler to sendmessage()
from VB program.

------------------------
'Constant & Declaration
Global wndMyProgram As Integer
Global Const WM_USER=&H400
Global Const WM_USER1= WM_USER +1

Declare Function FindWindow Lib "User"(ByVal lpClassName As Any,
        ByVal lpWindowName As Any) As Integer
Declare SendMessage Lib "User"(ByVal hwnd As Integer,ByVal wMsg As
        Integer, ByVal wParam As Integer, ByVal lParam As Any)As Long

Sub Form_Load()
    wndMyProgram = FindWindow(NULL, "My Program")
End Sub

Sub cmdButton1_Click()
    Dim ret As Integer
    ret = SendMessage(wndMy, WM_USER1, 0, 0)
End Sub
----------------------------------------------

My Problem:

Why is it that wndMyProgram is always 0(Using debug to watch) ?
"My Program" don't received the message.
Where is my mistake ?

Any comment and advice will be appreciated.

Thanks very much.

LOW PS



Sat, 16 May 1998 03:00:00 GMT  
 FindWindow API HELP!

Following are valid when using FindWindow in VB :

      FindWindow(lpClassName$, 0&)
      FindWindow(0&, lpCaption$)
      FindWindow(lpClassName$,lpCaption$)

To find the classname of an application, you can use the SPY
application, or write code (more APIs) to find it.

Hope this helps.


says...

Quote:

>I have written a program in C++ & a program in VB4 (16-bit).
>The VB program need to sendmessage to the C++ program whenever a
>command button is click.

>My solution is to use FindWindow() to get the window handler of the
>C++ Program("My Program"). Then using the handler to sendmessage()
>from VB program.

>Sub Form_Load()
>    wndMyProgram = FindWindow(NULL, "My Program")
>End Sub

>Sub cmdButton1_Click()
>    Dim ret As Integer
>    ret = SendMessage(wndMy, WM_USER1, 0, 0)
>End Sub
>----------------------------------------------

>My Problem:
>Why is it that wndMyProgram is always 0(Using debug to watch) ?



Sun, 17 May 1998 03:00:00 GMT  
 FindWindow API HELP!

Quote:

> Path:

djaustin.demon.co.uk!news.demon.co.uk!demon!tank.news.pipex.net!pipex!usenet.
eel.ufl.edu!newsfeed.internetmci.com!in1.uu.net!meaddata!newsjunkie.ans.net!m
erlion.singnet.com.sg!lantana.singnet.com.sg!usenet
Quote:

> Newsgroups: comp.lang.basic.visual.database
> Subject: FindWindow API HELP!
> Date: 28 Nov 1995 23:11:49 GMT
> Organization: Singapore Telecom Internet Service
> Lines: 43

> NNTP-Posting-Host: ts900-1405.singnet.com.sg
> Mime-Version: 1.0
> Content-Type: text/plain; charset=us-ascii
> Content-Transfer-Encoding: 7bit
> X-Mailer: Mozilla 1.1N (Windows; I; 16bit)

> I have written a program in C++ & a program in VB4 (16-bit).
> The VB program need to sendmessage to the C++ program whenever a
> command button is click.

> My solution is to use FindWindow() to get the window handler of the
> C++ Program("My Program"). Then using the handler to sendmessage()
> from VB program.

> ------------------------
> 'Constant & Declaration
> Global wndMyProgram As Integer
> Global Const WM_USER=&H400
> Global Const WM_USER1= WM_USER +1

> Declare Function FindWindow Lib "User"(ByVal lpClassName As Any,
>         ByVal lpWindowName As Any) As Integer
> Declare SendMessage Lib "User"(ByVal hwnd As Integer,ByVal wMsg As
>         Integer, ByVal wParam As Integer, ByVal lParam As Any)As Long

> Sub Form_Load()
>     wndMyProgram = FindWindow(NULL, "My Program")
> End Sub

> Sub cmdButton1_Click()
>     Dim ret As Integer
>     ret = SendMessage(wndMy, WM_USER1, 0, 0)
> End Sub
> ----------------------------------------------

> My Problem:

> Why is it that wndMyProgram is always 0(Using debug to watch) ?
> "My Program" don't received the message.
> Where is my mistake ?

> Any comment and advice will be appreciated.

> Thanks very much.

> LOW PS

Look at this function below which I wrote some time ago to kill a given
window - you can substitute your own message
Sub DestroyWindow (ByVal sWindowCaption As String)
'   routine will kill another programme if its
'   caption is passed
'   eg DestroyWindow("Notepad - SAMPLE.INI") will kill this app
    Dim sTitle As String
    Dim ihWnd As Integer
    Dim ihTask As Integer
    Dim iRet As Integer

    ihWnd = FindWindow(0&, sWindowCaption)
    If ihWnd = 0 Then Exit Sub
    ihTask = GetWindowTask(ihWnd)
    iRet = PostAppMessage(ihTask, WM_QUIT, 0, 0&)
End Sub

This may be of help to other people trying to close programs remotely, etc.



Fri, 22 May 1998 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Help - Probs With API FindWindow

2. Help: RE FindWindow API (32 Bit)

3. Help! Problem when using FindWindow API

4. FindWindow API not working..Please help..:)

5. Help with FindWindow API Call

6. FindWindow, etc APIs (long code sample)

7. Access20 and FindWindow() API function

8. (API), FindWindow, GetWindowText Problem

9. FindWindow GetWindowText api calls

10. FindWindow API

11. findwindow API

12. (API), FindWindow, GetWindowText Problem

 

 
Powered by phpBB® Forum Software