Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Centering Third Party App Windows

Status
Not open for further replies.

coboldave

MIS
Dec 20, 2001
41
US
When I load a 32 bit third party app, the windows load to the bottom left hand corner. How do I center it? vb6,WIN98/2000
 
In order to do this you have to get the handle for the window you are trying to position. You will have to use the Win 32 API to get this handle and position the window. First before I try to explain the process of doing this I would ask if you have any experience in using the Win API because it is not the easiest thing in the world to do.
 
No i don't have alot of experience, but I'm not afraid to learn. I downloaded a vb app that gets the handle and class an know the handle of my program. I've got that part licked.
 
Sorry it took so long to get back to you on this I was off yesterday. The API call you will need to use once you have the handle to the specific window is the MoveWindow API. the documentation for this API is as follows

Public Declare Function MoveWindow Lib "user32" 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

The parameters for this API function are

hwnd Long-Handle of th window to move
x Long-New left position for the window
y Long-New right position for the window
nWidth Long-New width for the window
nHeight Long-New height for the window
bRepaint Long-True(non-zero) if window should be redrawn.
False(zero) indicates that the application
will redraw the window.

Return Value
Long Nonzero on success, zero on failure

If you do not want the size of the window to be changed then prior to calling this API you will need to get the current dimensions of the window the nWidth & nHeight variables.

You will need to use the GetWindowRect API to get this information as declared as.

Public Declare Function GetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As Long, lpRect As RECT) As Long

The parameters for this API are
hwnd Long-the handle for the window for which you wish
to get the dimensions.

lpRect A Rectangle user defined type in which to load
the rectangle dimensions.

Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Return Value
Long Nonzero on success, zero on failure

I hope this will help you all dimensions used with these API's is in pixels so you will have to experiment to get the exact placement of the windows. You can make this very complicated and get system information regarding screen resolution and calculate the left a top positions based on the size of the window you wish to move if you want using other API's to get this information. If you really want to use window's API's for advanced functionallity like this I would recommend picking up the book Dan Appleman's Programmer's Guide To The Win32 API it is trully the Bible when it comes to dealing with API calls.
 
I inserted this in the declaration section of my form and recieved an error that I cannot include public statments. should this go in the main page or the module perhaps?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top