Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting the x/y of a msg box

Posted on 2000-04-11
14
Medium Priority
?
159 Views
Last Modified: 2010-05-02
Say the browser was not maximized and you needed to click the stop button but didn't want to send "Esc" to the browser,  how could you find the height, x and y (of top left corner), width

is this possible?
0
Comment
Question by:ThaSmartUno
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 3
14 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 2705282
try this:

Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

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


Private Sub Command1_Click()
    Dim hWnd As Long
    Dim retval As Long
    Dim coord As RECT
    hWnd = FindWindow(CLng(0), Text1.Text)
    If hWnd = 0 Then MsgBox Text1.Text & " is not running"
    retval = GetWindowRect(hWnd, coord)
    List1.AddItem "x coordinate is " & coord.Left
    List1.AddItem "y coordinate is " & coord.Right
    List1.AddItem "Width is " & coord.Left - coord.Right
End Sub


0
 
LVL 32

Expert Comment

by:Erick37
ID: 2705287
After you get the window's handle, you can call GetWindowRect to retrieve the window's coordinates.

Dim lhWnd As Long
Dim rc as RECT

'Get the window with focus
lhWnd = GetForegroundWindow()
Call GetWindowRect(lhWnd, rc)
lTop = rc.Top
lLeft = rc.Left
0
 
LVL 10

Author Comment

by:ThaSmartUno
ID: 2705407
is text1.text supposed to be the exe name?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 32

Expert Comment

by:Erick37
ID: 2705500
No, it's the EXACT caption of the window.  e.g. "Visual Basic Question - Microsoft Internet Explorer"
0
 
LVL 10

Author Comment

by:ThaSmartUno
ID: 2705513
well then it doesn't work for me, everything it says is name is not running
0
 
LVL 10

Author Comment

by:ThaSmartUno
ID: 2705528
Erick ... using your way, would there be a way to get the 2nd focused window ... like the one under the program?
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 300 total points
ID: 2705551
Try changing the line to:

hWnd = FindWindow(vbNullString, Text1.Text)
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2705565
Or, if you are looking for the handle of IE (and it is the only IE window open) use:

hWnd = FindWindow("IEFrame", vbNullString)
0
 
LVL 10

Author Comment

by:ThaSmartUno
ID: 2705574
umm ... who should i give points to, cuz erick your change worked.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2705586
Me Me Me
:)
0
 
LVL 10

Author Comment

by:ThaSmartUno
ID: 2705604
k sure ... eh
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2705992
hmmmmm...takin advantage of me not being home to check my mail i see =P
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2706244
AzraSound

Just curious as to which platform your code worked in.

hWnd = FindWindow(CLng(0), Text1.Text)
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2706250
i dont know...i wasnt on a computer with vb so i was doing it all from memory...i knew that when i used it before i set it to nothing or 0 or something, i just guessed wrong.  had i looked at the damn declaration for the api call i probably wouldnt have erred.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

636 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