Results 1 to 3 of 3

Thread: opposite of Setwindowpos?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2000
    Posts
    215
    hiyas,

    I was just wondering if any could tell me if there is an opposite api call of Setwindowpos? so I could get a windows position on the screen, and its width and height, I can't find one in Win32api.txt in the api viewer unless I have overlooked one.

    any help would be appreciated

    thanx.

  2. #2
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    No problem, use GetWindowRect()

    Consider this little cool effect:

    Private Type POINTAPI
    X As Long
    Y As Long
    End Type
    Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
    End Type
    Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function ExtTextOut Lib "gdi32" Alias "ExtTextOutA" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal wOptions As Long, ByVal lpRect As Any, ByVal lpString As String, ByVal nCount As Long, lpDx As Long) As Long
    Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    Private Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As POINTAPI) As Long
    Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long

    Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim Pt As POINTAPI
    Dim mWnd As Long
    Dim WR As RECT
    Dim nDC As Long
    Dim TextSize As POINTAPI
    Dim CX As Long
    Dim CY As Long

    'Get the current cursor position
    GetCursorPos Pt
    'Get the window under the current cursor pos
    mWnd = WindowFromPoint(Pt.X, Pt.Y)
    'Get the window's position & dimensions
    GetWindowRect mWnd, WR
    'Get the window's device context
    nDC = GetWindowDC(mWnd)
    'Get the height and width of our text
    GetTextExtentPoint32 nDC, "Hello !", Len("Hello !"), TextSize
    For CX = 1 To WR.Right - WR.Left Step TextSize.X
    For CY = 1 To WR.Bottom - WR.Top Step TextSize.Y
    'Draw the text on the window
    ExtTextOut nDC, CX, CY, 0, ByVal 0&, "Hello !", Len("Hello !"), ByVal 0&
    Next
    Next
    End Sub

    Private Sub Form_Paint()
    Me.CurrentX = 0
    Me.CurrentY = 0
    Me.Print "Click on this form," + vbCrLf + "Hold the mouse button," + vbCrLf + "drag the mouse over another window," + vbCrLf + "release the mouse button" + vbCrLf + "and see what happens!"
    End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2000
    Posts
    215
    Hiya Mad Compie,

    thanx for the help the GetWindowRect() api was the one I was after thanx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width