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

x
?
Solved

How to tell if a window is within screen boundaries?

Posted on 2002-03-22
5
Medium Priority
?
251 Views
Last Modified: 2010-05-02
Scenerio:
My app is running.
If the user opens a window on a program and moves it anywhere outside the screen boundaries, my program detects it and puts up a msg box.
Basically, this app would know if the window that has focus is within or without the screen boundaries.
0
Comment
Question by:rbend
[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
  • 4
5 Comments
 
LVL 3

Accepted Solution

by:
jbil earned 300 total points
ID: 6888677
Here's what Ive got so far..
form with text1 and timer1


Option Explicit
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetActiveWindow Lib "user32" () As Long
Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Private Declare Function SetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Private Const SW_MINIMIZE = 6
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 Type WINDOWPLACEMENT
        Length As Long
        flags As Long
        showCmd As Long
        ptMinPosition As POINTAPI
        ptMaxPosition As POINTAPI
        rcNormalPosition As RECT
End Type

Dim myrect As RECT
Dim busywin As Long

Private Sub Form_Click()
Text1.Text = ""
End Sub


Private Sub Timer1_Timer()
Dim rside As Long
Dim bside As Long
Dim winpos As WINDOWPLACEMENT
Dim rtn As Long
 
   busywin = GetForegroundWindow
   winpos.Length = Len(winpos)
    rtn = GetWindowPlacement(busywin, winpos)
    myrect = winpos.rcNormalPosition
    rside = (myrect.Right) * Screen.TwipsPerPixelX
    bside = (myrect.Bottom) * Screen.TwipsPerPixelY
    If myrect.Top < 0 Or myrect.Left < 0 Or bside > Screen.Height Or rside > Screen.Width Then
        Text1.Text = "foul!"
        Beep
    End If

End Sub
0
 

Author Comment

by:rbend
ID: 6888845
jbil:
Just one more thing and I think this will work.
Can you add :
To close the window that "foul'd" ?
When it goes off the screen, close it?
More points when you do.
Thanks
0
 

Author Comment

by:rbend
ID: 6888893
jbil:
Never mind the second part.
I figured it out.
Thanks.
Perfect.
0
 

Author Comment

by:rbend
ID: 6888951
jbil:
I just noticed something...
If I click on the desktop (not on any icon or anything)
the "foul" message appears.
Can you make it so that "focus" on the desktop does NOT acitvate the program?
More Points.
0
 

Author Comment

by:rbend
ID: 6889032
jbil:
Ok...I took care of that too.
Thanks.
b
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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

604 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