[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to maximize a window

Posted on 2009-04-13
1
Medium Priority
?
885 Views
Last Modified: 2012-08-13
I have an application that runs in the background. I need to call it, maximize it. Then capture it and finally minimize it.

I have tried several methods.......
like
SetWindowPos(mHandel, 0, 0, 0, 0, 0, SWP_NOSIZE)
and
BringWindowToTop(mHandel)
and
For Each p As Process In Process.GetProcessesByName("FXTSpp")
            ShowWindow(p.MainWindowHandle, SHOW_WINDOW.SW_MAXIMIZE)
Next p


BUT non of them is reliable, that is if I click on any other window and start interacting with it
the desired window will not get maximized.

Help is greatly appreciated, thank you for your time.
Private Sub Details_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        mHandel = FindWindow(vbNullString, "Marketscope 2.0")
        Dim dt1 As DateTime
        dt1 = DateTime.UtcNow
        mCurrentDateTime = CDate(DateTime.UtcNow.ToString("MM/dd/yyyy HH:mm:ss"))
        Timer3.Enabled = True
        'Call UpdateDataBaseWithPicture()
    End Sub  
 
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
        'MaximizeFXCMGraph()
        SetWindowPos(mHandel, 0, 0, 0, 0, 0, SWP_NOSIZE)
        'MoveWindow(mHandel, 0, 0, 1200, 768, False)
        'BringWindowToTop(mHandel)
        Application.DoEvents()
        Application.DoEvents()
        'Application.DoEvents()
        'Dim MyRect As Rectangle = New Rectangle(0, Screen.PrimaryScreen.Bounds.Top - 0, 1000, 700)
        'Dim MyPic As Bitmap = BlitterChip.ScreenGrab(MyRect)
        'SendKeys.Send("%{PRTSC}")          '<alt + printscreen>
        'PictureBox2.Image = MyPic 'Clipboard.GetImage
        'Clipboard.SetDataObject(0)      'save memory by removing the image from the clipboard
        'MoveWindow(mHandel, -10000, -10000, 1000, 600, True)
        'BringWindowToTop(Me.Handle)
    End Sub
 
 
 <Flags()> _
    Private Enum SHOW_WINDOW As Integer
        SW_HIDE = 0
        SW_SHOWNORMAL = 1
        SW_NORMAL = 1
        SW_SHOWMINIMIZED = 2
        SW_SHOWMAXIMIZED = 3
        SW_MAXIMIZE = 3
        SW_SHOWNOACTIVATE = 4
        SW_SHOW = 5
        SW_MINIMIZE = 6
        SW_SHOWMINNOACTIVE = 7
        SW_SHOWNA = 8
        SW_RESTORE = 9
        SW_SHOWDEFAULT = 10
        SW_FORCEMINIMIZE = 11
        SW_MAX = 11
    End Enum
 
    Private Sub MaximizeFXCMGraph()
        For Each p As Process In Process.GetProcessesByName("FXTSpp")
            ShowWindow(p.MainWindowHandle, SHOW_WINDOW.SW_MAXIMIZE)
        Next p
    End Sub
 
    Private Sub MinimizeFXCMGraph()
        For Each p As Process In Process.GetProcessesByName("FXTSpp")
            ShowWindow(p.MainWindowHandle, SHOW_WINDOW.SW_MINIMIZE)
        Next p
    End Sub

Open in new window

0
Comment
Question by:tamu111981
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 15

Accepted Solution

by:
oobayly earned 1500 total points
ID: 24130062
Try this code, it's modified from what I use for a singleton application instance.
Private Sub GetScreenShot(ByVal ps As Process)
    Dim hWnd As IntPtr = ps.MainWindowHandle
    
    ' Restores a minimized (iconic) window to its previous size and position; it then activates the window. 
    ' http://msdn.microsoft.com/en-us/library/ms633535(VS.85).aspx
    OpenIcon(hWnd)
    
    ' Puts the thread that created the specified window into the foreground and activates the window.
    ' http://msdn.microsoft.com/en-us/library/ms633539(VS.85).aspx
    SetForegroundWindow(hWnd)
    
    ' Sets the specified window's show state. 
    ' http://msdn.microsoft.com/en-us/library/ms633548(VS.85).aspx
    ShowWindow(hWnd, ShowWindowCommand.SW_SHOWMAXIMIZED)
    
    ' Wait 2 seconds to allow for the window to redraw
    System.Threading.Thread.Sleep(2000)
    
    ' PrintScreen & grab the image
    SendKeys.Send("{PRTSC}")
    Dim img As Image = Clipboard.GetImage()
    
    ' Close the app's window
    ShowWindow(hWnd, ShowWindowCommand.SW_MINIMIZE)
End Sub
 
<DllImport("user32.dll")> _
Public Shared Function OpenIcon(ByVal hWnd As IntPtr) As Boolean
End Function
 
<DllImport("user32.dll")> _
Public Shared Function SetForegroundWindow(ByVal hWnd As IntPtr) As Boolean
End Function
 
<DllImport("user32.dll")> _
Public Shared Function ShowWindow(ByVal hWnd As IntPtr, ByVal cmd As ShowWindowCommand) As Boolean
End Function
 
Public Enum ShowWindowCommand As Integer
    SW_HIDE = 0
    SW_SHOWNORMAL = 1
    SW_NORMAL = 1
    SW_SHOWMINIMIZED = 2
    SW_SHOWMAXIMIZED = 3
    SW_MAXIMIZE = 3
    SW_SHOWNOACTIVATE = 4
    SW_SHOW = 5
    SW_MINIMIZE = 6
    SW_SHOWMINNOACTIVE = 7
    SW_SHOWNA = 8
    SW_RESTORE = 9
    SW_SHOWDEFAULT = 10
    SW_FORCEMINIMIZE = 11
    SW_MAX = 11
End Enum

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question