Results 1 to 5 of 5

Thread: Tough Question .... at least for beginner!

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000


    Please help me on this one. I'm trying to get the position of any browser address bar. i've already tried the GetCursorPos API but it seems to cumbersome.

    What i have in mind is to make a command button that once activated, will enabled you to draw a selection box (around the address bar) and record the initial and final X,Y values of the selection box.

    If you know how or have a better idea for doing that, please tell me.

  2. #2
    Use the GetWindowRect api function:

    Private Declare Function FindWindow Lib "user32" _
    Alias "FindWindowA" (ByVal lpClassName As String, ByVal _
    lpWindowName As String) As Long
    Private Declare Function FindWindowEx Lib "user32" _
    Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As _
    Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Private Declare Function GetWindowRect Lib "user32" (ByVal _
    hwnd As Long, lpRect As RECT) As Long
    Private Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End Type
    Private Sub Command1_Click()
        Dim ieframe As Long, workera As Long, rebarwindow As Long
        Dim comboboxex As Long, combobox As Long, editx As Long
        Dim intWidth As Integer
        Dim intHeight As Integer
        Dim strMsg As String
        Dim TheRect As RECT
        ieframe = FindWindow("ieframe", vbNullString)
        workera = FindWindowEx(ieframe, 0&, "workera", vbNullString)
        rebarwindow = FindWindowEx(workera, 0&, "rebarwindow32", vbNullString)
        comboboxex = FindWindowEx(rebarwindow, 0&, "comboboxex32", vbNullString)
        combobox = FindWindowEx(comboboxex, 0&, "combobox", vbNullString)
        editx = FindWindowEx(combobox, 0&, "edit", vbNullString)
        ' size and position values stored in TheRect
        Call GetWindowRect(editx, TheRect)
        intWidth = TheRect.Right - TheRect.Left
        intHeight = TheRect.Bottom - TheRect.Top
        strMsg = strMsg & "Left: " & TheRect.Left & vbCrLf
        strMsg = strMsg & "Top: " & TheRect.Top & vbCrLf
        strMsg = strMsg & "Width: " & intWidth & vbCrLf
        strMsg = strMsg & "Height: " & intHeight & vbCrLf
        MsgBox strMsg
    End Sub

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2000


    Thanks Matthew !
    Eventhough it's a little complicated for a beginner like me to use (didn't manage to make it work), it was very helpful: i now know where to start (found a reference on and with a little bit of work, it "should" be ok

  4. #4
    What do you mean you didn't get it to work? It's all there. Just put it all into the form declarations. Make sure an IE window is open, place a command button on the form, click it and it should tell you where the IE Combobox/Address bar is located.

    [Edited by Matthew Gates on 11-19-2000 at 07:04 PM]

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Hello, i don't know why it didn't work eventhough all the necessary code was there! Anyway here's what i find (from and with some mod...) and it works like a charm!
    so thanks a lot, i think i should buy a book on VB API calls... so much to learn...

    Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

    Dim Pt As POINTAPI, mWnd As Long, WR As RECT, nDC As Long

    GetCursorPos Pt

    mWnd = WindowFromPoint(Pt.X, Pt.Y)

    GetWindowRect mWnd, WR

    X1.Caption = (WR.Left)
    Y1.Caption = (WR.Top)
    Xwidth.Caption = ((WR.Right) - (WR.Left))
    Yheight.Caption = ((WR.Bottom) - (WR.Top))

    End Sub

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