How to use Findwindow to get windows handle? 
Author Message
 How to use Findwindow to get windows handle?

:-)  Number 1 mistake.  The Title Bar Changes and is not a valid parameter.

        Surf the registry and find the ClassName...  Or when it is first opened
and no document is loaded get the Window using your method and then use
GetClassName to get the ClassName Access and then use the ClassName instead
of the Windows Text.  The Windows Text Method doesn't work at all buddy.

        Same thing for your AppActivate commands.  If the TitleBar Changes you are
messed.  One solution is to do the following.

        X = GetWindow(Form1.hWnd, GW_FIRST)
        X = GetWindow(X, GW_NEXT)
        <Do a GetWindowsText here>
        If Right(Text, 16) = "Microsoft Access"
                Then <Window is now Found> Exit Loop
        Loop Until X = 0
        If X = 0 Then Exit Sub Else <Use X as Handle for functions>
                                        <Or use Text for AppActivate>

CEO DigiTec Web Consultants
Justin Rogers
Personal Programmer and Web Consultant  Home Page:      Soon to come

> Hi,
> I have a problem with my VB3.0 app. Hope someone can help me out. Thanks
> in advance.

> In my app, I want to launch MS access, do some DDE, and then close it.
> The problem is I cannot get the windows handle of MS Access when I try
> to close it.


> Declare Function FindWindow Lib "User" (ByVal lpClassName As Any, ByVal
> lpWindowName As Any) As Integer
> Declare Function PostMessage Lib "User" (ByVal hWnd As Integer, ByVal
> wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Integer
> Const WM_Close = &H10

>     Dim hdlAccess As Integer
>     Dim x As Integer

>     x  = Shell("c:\msoffice\access\msaccess.exe", 1)

>    .
>    .
>    .

>     'following method doesn't work when user log off or locks NT
> workstation (I use AT scheduler to run this app. on NT)

>     'AppActivate "Microsoft Access"
>     'SendKeys "%F"
>     'SendKeys "x"

>    'try to use PostMessage to close it

>     hdlAccess = FindWindow("", "Microsoft Access")
>     x = PostMessage(hdlAccess, WM_Close, 0, 0)


- Show quoted text -


> The above FindWindow always return hdlAccess=0. How to call FindWindow
> correctly? Or is there another way to close MS Access?

Fri, 12 Nov 1999 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Problems getting the handle of a MDI form using the FindWindow API

2. Using FindWindow to get the handle on another Window

3. Using FindWindow to get first handle windows finds

4. Findwindow (get window handles)

5. Getting window handle after using Shellexecute

6. Sendkey to found window using FindWindow

7. Find the Windows Sidebar under Vista/7 using FindWindow(Ex)

8. Getting Windows Handle

9. Problem getting handle of a child window

10. Getting Window Handle

11. Getting Window Handle

12. Q: Getting the desktop window's handle (GetDesktopWindow ain't cutting it)


Powered by phpBB® Forum Software