Get window size via Windows Messaging?

Evan1993

Well-known member
Joined
Apr 2, 2008
Messages
47
Programming Experience
1-3
Is there any way to retrieve a windows size with via SendNotifyMessage(or others..) ? I could not find any that would return the window size, only change it.
 
To GET the window size, use the GetWindowPlacement function or hook the WM_GETMINMAXINFO or WM_WINDOWPOSCHANGING notification messages.
 
I don't want to set a windows size, I want to get its size.

I wanted to know if there was any windows message that would return a windows size.

I need it doesn't have to be a windows message, but it has to be able to get the sizes of other progams windows besides my app. Edit Didn't see other post, h/o
 
>To GET the window size, use the GetWindowPlacement function
I'm having trouble getting this to work--It keeps returning 0,0 though. (and randomly says something like "attept to read or write protected memory")

Heres my code atm.

VB.NET:
    'UPGRADE_WARNING: Structure WINDOWPLACEMENT may require marshalling attributes to be passed as an argument in this Declare statement. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="C429C3A5-5D47-4CD9-8F51-74A1616405DC"'
'Upgraded from Vb 6
    Public Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Integer, ByRef lpwndpl As WINDOWPLACEMENT) As Integer

VB.NET:
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim struct As New WINDOWPLACEMENT
        Try
            GetWindowPlacement(CInt(AppDomain.GetCurrentThreadId()), struct)
            Messages.Text += vbCrLf & struct.rcNormalPosition.X
            Messages.Text += vbCrLf & struct.rcNormalPosition.Y
            Messages.Text += vbCrLf & GetLastError()
        Catch x As Exception
            MessageBox.Show(x.Message)
        End Try
    End Sub
 
Use GetWindowRect function.
VB.NET:
Declare Function GetWindowRect Lib "user32.dll" ( _ 
	 ByVal hwnd As Int32, _ 
	 ByRef lpRect As RECT) As Int32

Structure RECT
	Public Left As Int32
	Public Top As Int32
	Public Right As Int32
	Public Bottom As Int32
End Structure
 
Back
Top