Go Premium for a chance to win a PS4. Enter to Win


Move window without resize

Posted on 2008-06-16
Medium Priority
Last Modified: 2008-10-03
Hi. I am trying to move a window to the upper left corner of my screen. I seem to have no problem moving the window to the corner , but it becomes very very small no matter what I set as nWidth & nHeight. The window i am moving is a "no resizeable" window, and i simply want it in the corner and nothing else.

    Declare Function MoveWindow Lib "user32.dll" Alias _
                    "MoveWindow" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long

Question by:soriega
LVL 27

Expert Comment

ID: 21797614
try something like this...

Dim frm As New Form1
        frm.Location = New Point(Me.Left + 200, Me.Top + 100)

Author Comment

ID: 21797716
Not really, i want to move another window, Not the Form of my application. Is there some way of using this method with the hwnd ?
I thought this was useful
Declare Function MoveWindow Lib "user32.dll" Alias _
                    "MoveWindow" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
This one seem to work, but it becomes very small, and it can after then only be closed
LVL 86

Accepted Solution

Mike Tomlinson earned 600 total points
ID: 21798122
Use SetWindowPos() with the SWP_NOSIZE flag:
    Private Const SWP_NOSIZE As Integer = &H1
    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
        SetWindowPos(someWindowHandleHere, 0, 0, 0, 0, 0, SWP_NOSIZE)

Open in new window


Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

772 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