Prev: Happy Birthday
Next: Print to a specific printer
From: mp on 21 Jun 2010 17:18 "Karl E. Peterson" <karl(a)exmvps.org> wrote in message news:hvojq7$aob$1(a)news.eternal-september.org... > Karl E. Peterson was thinking very hard : >> mp wrote : >>>>> be careful that you don't save the size if the window is minimized or >>>>> maximized; you can call GetWindowPlacement to get the normal window >>>>> rectangle regardless of the current state. >>>> >>>> Another thing that *really* irritates me is folks who don't check to >>>> see if the form is off the visible screen(s) when they restore a saved >>>> position! Dumb, dumb dumb, DUMB! >>> >>> yes, someone mentioned that also, will have to research how to tell. >>> thanks >> >> Here ya go: >> >> Karl Peterson Shows How to Make a More Considerate UI >> http://visualstudiomagazine.com/articles/2009/08/25/its-the-little-things.aspx >> >> and/or: >> >> http://vb.mvps.org/samples/Monitors >> >> :-) > > In a nutshell, this routine will test whether a given window is fully or > partially onscreen, and optionally slide it onto the nearest position that > is if it isn't... > > Public Function WindowOffscreen(ByVal hWnd As Long, Optional OverlapOK > As Boolean = True, Optional ForceOnscreen As Boolean = True) As Boolean > Dim rW As RECT, rM As RECT, rU As RECT > Dim Overlapped As Boolean > ' Collection needs to be initialized. > If (Monitors Is Nothing) Then MonitorsRefresh > > ' Test whether the specified window is actually within > ' the visible display area. > rW = WindowRectAbsolute(hWnd) > rM = MonitorRect(0) > > ' Do a quick union to see if window is entirely contained on desktop. > Call UnionRect(rU, rM, rW) > If EqualRect(rU, rM) Then Exit Function > > ' Next quick test is whether rectangle partially intersects desktop. > If IntersectRect(rU, rM, rW) Then > If OverlapOK Then Exit Function > End If > > ' ' Make sure window isn't larger than screen. > ' If OverlapOK = False Then > ' If (rW.Right - rW.Left) > (rM.Right - rM.Left) Then > ' rW.Right = rW.Left + (rM.Right - rM.Left) > ' End If > ' If (rW.Bottom - rW.Top) > (rM.Bottom - rM.Top) Then > ' rW.Bottom = rW.Top + (rM.Bottom - rM.Top) > ' End If > ' End If > > ' Assume window is wholly within the visible region. > ' Check each edge, and slide into screen as necessary. > ' Prefer top/left by setting it last. > If rW.Right > rM.Right Then > Call OffsetRect(rW, (rM.Right - rW.Right), 0) > End If > If rW.Bottom > rM.Bottom Then > Call OffsetRect(rW, 0, rM.Bottom - rW.Bottom) > End If > If rW.Left < rM.Left Then > Call OffsetRect(rW, (rM.Left - rW.Left), 0) > 'rW.Right = rM.Left + (rW.Right - rW.Left) > 'rW.Left = rM.Left > End If > If rW.Top < rM.Top Then > Call OffsetRect(rW, 0, (rM.Top - rW.Top)) > End If > > ' If rW has not changed, then it was entirely onscreen before. > If Not EqualRect(rW, WindowRectAbsolute(hWnd)) Then > WindowOffscreen = True > If ForceOnscreen Then > Call WindowMove(hWnd, rW) > End If > End If > End Function > > Public Function WindowRectAbsolute(ByVal hWnd As Long) As RECT > ' Supply absolute screen coordinates of window. > Call GetWindowRect(hWnd, WindowRectAbsolute) > End Function > > But note this also relies on a collection of CMonitor objects, based on > the class that's downloadable at the link above. > > -- > .NET: It's About Trust! http://vfred.mvps.org > Customer Hatred Knows No Bounds at MSFT > ClassicVB Users Regroup! comp.lang.basic.visual.misc > Free usenet access at http://www.eternal-september.org > on a silver platter no less!!! :-) thanks you are a gentleman and a scholar mark
From: Karl E. Peterson on 21 Jun 2010 17:37 on 6/21/2010, mp supposed : > on a silver platter no less!!! For the sake of the thread... ;-) Thanks! -- ..NET: It's About Trust! http://vfred.mvps.org Customer Hatred Knows No Bounds at MSFT ClassicVB Users Regroup! comp.lang.basic.visual.misc Free usenet access at http://www.eternal-september.org
From: David Kerber on 22 Jun 2010 15:11
In article <hvoh8q$jbg$1(a)news.eternal-september.org>, k(a)p.c says... > > "David Kerber" <dkerber(a)WarrenRogersAssociates.invalid> wrote in message > news:MPG.268974cf47c3d10b98968f(a)news.eternal-september.org... > : > : I do that in most of my apps, only I do it in form_close, rather than > : form_resize. > > Form_close? What version of VB you using? > > Or did you mean Form_Unload? Yes. Sorry for the brain fart; I'm using VB6. |