+ Reply to Thread
Results 1 to 3 of 3

Maximize external window when it's already open using the API.

Hybrid View

  1. #1
    Registered User
    Join Date
    04-16-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    52

    Maximize external window when it's already open using the API.

    I have this code which opens a file in a maximized form with no problem, however I'd like to maximize an already open file without reopening it.
    Private Const SW_MAXIMIZE As Long = 3
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    
    Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Sub maximizewindow()
    Filename = FindWindow(vbNullString, "Untitled.txt - Notepad")
    start_doc = ShellExecute(Filename, "open", "C:\Untitled.txt", 0, 0, SW_MAXIMIZE)
    End Sub
    Many Thanks
    Last edited by Leith Ross; 05-19-2013 at 11:06 PM. Reason: Added Code Tags

  2. #2
    Registered User
    Join Date
    04-16-2013
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    52

    re: Maximize external window when it's already open using the API.

    Never Mind, I found it:
    Private Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Private Const SW_MAXIMIZE As Long = 3
    Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    
    Sub maximize()
    Filename = FindWindow(vbNullString, "metro.txt - Notepad")
    Call ShowWindow(Filename, SW_MAXIMIZE)
    End Sub
    Last edited by Leith Ross; 05-19-2013 at 11:06 PM. Reason: Added Code Tags

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Maximize external window when it's already open using the API.

    FYI: This API code is for 32 bit windows only. This will crash on Windows 64 systems.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1