[AccessD] What is App.hInstance in Access

MartyConnelly martyconnelly at shaw.ca
Wed Nov 3 11:15:09 CST 2004


If you want the Access Application window handle

'You can use the Windows API GetWindow function to retrieve the handle
'of your application's window with the statement:
'    CurrWnd = GetWindow(Form1.hwnd, GW_HWNDFIRST)
' To use in Access replace with the following
'     parent_hwnd = FindWindow(vbNullString, "Microsoft Access")
'The first argument of the GetWindow function is the handle of the window
'that is at the top of the z-order. In this case, this is the handle of 
'Form1

 Here is some code I use to get  Task List handles
Maybe you can get something out of it.

'_______________________________________________________


Private Const VK_LWIN = &H5B 'Left window button
Private Const VK_RETURN = &HD  'ENTER key
Private Const VK_SHIFT = &H10 'SHIFT key
Private Const VK_CONTROL = &H11 'CTRL key
Private Const VK_MENU = &H12 'ALT key
Private Const VK_PAUSE = &H13 'PAUSE key
Private Const VK_CAPITAL = &H14 'CAPS LOCK key
Private Const VK_SNAPSHOT = &H2C  'Print Screen
Private Const VK_APPS = &H5D
         'Applications key on a Microsoft Natural Keyboard
'from http://support.microsoft.com/view/dev.asp?kb=242971

Const GW_HWNDFIRST = 0
Const GW_HWNDNEXT = 2
Private Const KEYEVENTF_KEYUP = &H2

Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
    ByVal bScan As Byte, ByVal dwflags As Long, ByVal dwExtraInfo As Long)
Private Declare Function GetWindow Lib "user32" _
   (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetParent Lib "user32" _
   (ByVal hwnd As Long) As Long
Private Declare Function GetWindowTextLength Lib _
   "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" _
   Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal _
   lpString As String, ByVal cch As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
   (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetFocusAPI Lib "user32" Alias "SetFocus" _
   (ByVal hwnd As Long) As Long




'Determining Which Tasks Are Running

'With the Microsoft Windows operating system,
'you can run any number of applications simultaneously.
'Occasionally, you may need to determine which tasks are currently being
'run.
'This can be accomplished by using several Windows application programming
'interface
'(API) functions.
'To find the names of all currently executing tasks,
'you must first determine the handle of the window that is currently
'at the top of the z-order. This, of course, would be the window of your
'own Microsoft Visual Basic application.
'You can use the Windows API GetWindow function to retrieve the handle
'of your application's window with the statement:

'    CurrWnd = GetWindow(Form1.hwnd, GW_HWNDFIRST)
' To use in Access replace with the following
'     parent_hwnd = FindWindow(vbNullString, "Microsoft Access")
'The first argument of the GetWindow function is the handle of the window
'that is at the top of the z-order. In this case, this is the handle of
'Form1.

'The second argument of the GetWindow function specifies the window
'you want to retrieve the handle for.
'This argument can have one of the following values:

'  GW_CHILD Retrieve the handle for the child window.
'  GW_HWNDFIRST Retrieve the handle for the window at the top of the z-
'order.
'  GW_HWNDLAST Retrieve the handle for the window at the bottom of the z-
'order.
'  GW_HWNDNEXT Retrieve the handle of the window below the specified window
'in the z-order.
'  GW_HWNDPREV Retrieve the handle of the window above the specified window
'in the z-order.
'  GW_OWNER Retrieve the handle of the window that owns the specified
'window, if any.

'After you have retrieved the application's window handle,
'you can use the Windows API GetParent function to retrieve this window's
'child window handle. Next, you call the Windows API GetWindowText and
'GetWindowTextLength functions to retrieve the text in the window's title
'bar
'and the length of this text, respectively. You can then use the text string
'in your own application. For example, you can save the title bar text
'to a List Box control.

'All of the above steps are repeated until you have processed all running
'tasks.
'You know that you have gone through each task when the current window is
'that'of your own application.


Function LoadTaskList() As String
Dim CurrWnd As Long
Dim Length As Long
Dim TaskName As String
Dim Parent As Long
Dim parent_hwnd As Long
Dim strMyTaskList As String
  strMyTaskList = " Task List " & vbCrLf

' This line below works from VB form
'CurrWnd = GetWindow(Form1.hwnd, GW_HWNDFIRST)
' get Parent Window Handle
     parent_hwnd = FindWindow(vbNullString, "Microsoft Access")
    If parent_hwnd = 0 Then
     MsgBox "Access Not Found"
      Exit Function
     End If
      'SetFocusAPI parent_hwnd
       CurrWnd = parent_hwnd
While CurrWnd <> 0
  Parent = GetParent(CurrWnd)
  Length = GetWindowTextLength(CurrWnd)
  TaskName = Space$(Length + 1)
  Length = GetWindowText(CurrWnd, TaskName, Length + 1)
  TaskName = Left$(TaskName, Len(TaskName) - 1)

  If Length > 0 Then
  'If TaskName <> Me.Caption Then
  'If TaskName <> "Microsoft Access" Then
     'List1.AddItem TaskName
     strMyTaskList = strMyTaskList & TaskName & vbCrLf
     Debug.Print TaskName
   'End If
  End If
  CurrWnd = GetWindow(CurrWnd, GW_HWNDNEXT)

    DoEvents
Wend
LoadTaskList = strMyTaskList
End Function



Colby, John wrote:

>In looking over the time sync stuff I found a class and module to replace
>the winsock OCX control.  It has a call:
>
>    p_lngWindowHandle = CreateWindowEx(0&, "STATIC", "SOCKET_WINDOW", 0&,
>0&, 0&, 0&, 0&, 0&, 0&, App.hInstance, ByVal 0&)
>
>which fails on App.hInstance.  I'm assuming that this is a handle to the
>application window.  Is there an equivelent in VBA?  I think I solved that
>one by:
>
>    p_lngWindowHandle = CreateWindowEx(0&, "STATIC", "SOCKET_WINDOW", 0&,
>0&, 0&, 0&, 0&, 0&, 0&, Application.hWndAccessApp, ByVal 0&)
>
>However I am now getting a compile error on:
>
>    m_lngResolveMessage = RegisterWindowMessage(App.EXEName &
>".ResolveMessage")
>
>There is no apparent equivelent property in the Application object.  Does
>anyone know what I would use here?
>
>John W. Colby
>The DIS Database Guy
>
>
>-----Original Message-----
>From: Gustav Brock [mailto:gustav at cactus.dk]
>Sent: Wednesday, November 03, 2004 4:34 AM
>To: Access Developers discussion and problem solving
>Subject: Re: [AccessD] Time Synchronization
>
>
>Hi Mark
>
>You can use an ActiveX control for this:
>
>http://www.universalthread.com/wconnect/wc.dll?FournierTransformation~
>
>"Synchronize your client machine or just the software itself by
>retrieving the highly accurate time from time servers [..] This is
>accurate to the millisecond range so a large use is for Timestamping
>of information independent of the local CPU clock."
>
>Or use the winsock ocx. Here's some VB code you probably can adapt:
>
>http://www.freevbcode.com/ShowCode.asp?ID=1594
>
>/gustav
>
>
>  
>
>>Date: 2004-11-02 18:39
>>    
>>
>
>  
>
>>Does anyone know of any VBA code to be placed within an Access application
>>that can easily poll an Internet-based time server, and return that time
>>to a variable?  Searching through the archives hasn't come up with
>>naything ... yet ...
>>    
>>
>
>  
>
>>Thanks,
>>    
>>
>
>  
>
>>Mark Naudé
>>    
>>
>
>  
>

-- 
Marty Connelly
Victoria, B.C.
Canada






More information about the AccessD mailing list