Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ShowWindow Function

    can anyone help please. I am using the ShowWindow API Function to bring a window to the top if a user does anything but close it. I have got the syntax from <A target="_blank" HREF=http://www.allapi.net>http://www.allapi.net</A>.
    Unfortunately the example only shows a value of 1 for a normal window size (ie not maximised or minimised). Does anyone know other values that would be appropriate as I need to maximise the window and give it the focus ?
    TIA

  2. #2
    JustCallMeAl
    Guest

    Re: ShowWindow Function

    You should download Allapi.net's api guide and toolshed. From the guide:

    SW_HIDE = 0
    Hides the window and activates another window.
    SW_MAXIMIZE = 3
    Maximizes the specified window.
    SW_MINIMIZE = 6
    Minimizes the specified window and activates the next top-level window in the Z order.
    SW_RESTORE = 9
    Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when restoring a minimized window.
    SW_SHOW = 5
    Activates the window and displays it in its current size and position.
    SW_SHOWDEFAULT = 10
    Sets the show state based on the SW_ flag specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application.
    SW_SHOWMAXIMIZED = 3
    Activates the window and displays it as a maximized window.
    SW_SHOWMINIMIZED = 2
    Activates the window and displays it as a minimized window.
    SW_SHOWMINNOACTIVE = 7
    Displays the window as a minimized window. The active window remains active.
    SW_SHOWNA = 8
    Displays the window in its current state. The active window remains active.
    SW_SHOWNOACTIVATE = 4
    Displays a window in its most recent size and position. The active window remains active.
    SW_SHOWNORMAL = 1
    Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when displaying the window for the first time.

    Here is the example they give:

    <pre>Private Declare Function FindWindow Lib "user32" _
    Alias "FindWindowA" (ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long
    Private Declare Function PostMessage Lib "user32" _
    Alias "PostMessageA" (ByVal hwnd As Long, _
    ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) _
    As Long
    Private Declare Function GetClassName Lib "user32" _
    Alias "GetClassNameA" (ByVal hwnd As Long, _
    ByVal lpClassName As String, ByVal nMaxCount As Long) _
    As Long
    Private Declare Function ShowWindow Lib "user32" _
    (ByVal hwnd As Long, _
    ByVal nCmdShow As Long) As Long

    Const SW_SHOWNORMAL = 1
    Const WM_CLOSE = &H10
    Const gcClassnameMSWord = "OpusApp"
    Const gcClassnameMSExcel = "XLMAIN"
    Const gcClassnameMSIExplorer = "IEFrame"
    Const gcClassnameMSVBasic = "wndclass_desked_gsk"
    Const gcClassnameNotePad = "Notepad"
    Const gcClassnameMyVBApp = "ThunderForm"
    Private Sub Form_Load()
    'KPD-Team 1998
    'URL: <A target="_blank" HREF=http://www.allapi.net/>http://www.allapi.net/</A>
    'E-Mail: KPDTeam@Allapi.net
    Dim WinWnd As Long, Ret As String, RetVal As Long, lpClassName As String
    'Ask for a Window title
    Ret = InputBox("Enter the exact window title:" + Chr$(13) + Chr$(10) + "Note: must be an exact match")
    'Search the window
    WinWnd = FindWindow(vbNullString, Ret)
    If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
    'Show the window
    ShowWindow WinWnd, SW_SHOWNORMAL
    'Create a buffer
    lpClassName = Space(256)
    'retrieve the class name
    RetVal = GetClassName(WinWnd, lpClassName, 256)
    'Show the classname
    MsgBox "Classname: " + Left$(lpClassName, RetVal)
    'Post a message to the window to close itself
    PostMessage WinWnd, WM_CLOSE, 0&, 0&
    End Sub</pre>


  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Cornwall, England
    Posts
    393
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ShowWindow Function

    Al,
    I have the guide and toolshed but did not find this list with the ShowWindow example, maybe my version is out of data.
    I think I will save this as a txt document for ready reference. thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •