?
Solved

Resize window using window handle

Posted on 2006-04-20
9
Medium Priority
?
463 Views
Last Modified: 2008-01-09
Does anyone know how to resize a window if I know that window handle?  (example: get the window handle of the Calculator program and change the size of the window)

THanks!
0
Comment
Question by:CaitlinRoberts
  • 5
  • 3
9 Comments
 
LVL 14

Assisted Solution

by:PockyMaster
PockyMaster earned 1000 total points
ID: 16501850
I believe this will work (not on calculator, because it's not sizable )
But anyway, it's SetWindowPos you are looking for

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim wnd As IntPtr = CWin32.FindWindow(Nothing, "SomeAppYouLookFor")
        CWin32.SetWindowPos(wnd, Nothing, 0, 0, 500, 500, 0)
    End Sub
End Class

Public Class CWin32
    Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
    Public Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer

End Class
0
 

Author Comment

by:CaitlinRoberts
ID: 16506828
For some reason this  code is seems to hide my window.  I've seen SetWindowPos before, but always have trouble getting it to work the way I need too.  Any suggestions?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16507820
Can you show us what you've got?...
0
 

Author Comment

by:CaitlinRoberts
ID: 16508054
Sure thing:

    Private Declare Auto Sub SetWindowPos Lib "user32" ( _
        ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, _
        ByVal X As Long, ByVal Y As Long, _
        ByVal Cx As Long, ByVal cy As Long, ByVal wFlags As Long)

 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim IE() As Process
        Dim n As Integer
        IE = Process.GetProcessesByName("IEXPLORE")
        If IE.Length > 0 Then
            For n = 0 To IE.Length - 1
                If IE(n).MainWindowTitle.StartsWith("Window Title") Then
                    SetWindowPos(IE(n).MainWindowHandle.ToInt32, Nothing, 0, -25, 500, 500, 0)
                End If
            Next
        End If

    End Sub
0
 

Author Comment

by:CaitlinRoberts
ID: 16508064
Woops, copied from the wrong file, the SetWindowPos line should read:
                    SetWindowPos(IE(n).MainWindowHandle, Nothing, 0, -25, 500, 500, 0)
0
 

Author Comment

by:CaitlinRoberts
ID: 16508086
Do I have to pass anything in to the hWndInsertAfter or wFlag parameters?  
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1000 total points
ID: 16508090
You're using an old VB6 API declaration with Long data types in it  (and IntPtr stuffed into it)....they should be Integer as in both my linked example and PockyMasters posted example!

    Private Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" _
        (ByVal hWnd As IntPtr, ByVal hWndInsertAfter As Integer, _
        ByVal x As Integer, ByVal y As Integer, _
        ByVal cx As Integer, ByVal cy As Integer, _
        ByVal wFlags As Integer) As Integer
0
 

Author Comment

by:CaitlinRoberts
ID: 16508124
Ahh, silly me!  That was a dumb mistake on my part.  Thanks!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

850 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