Positioning Access Popup Form in relation to Screen (as opposed to Access Application)

I’ve searched everywhere for an answer to this, a lot of close answers but nothing that has worked.  This is my first question, so if it’s a duplicate or categorized incorrectly I apologize.  I’ve searched so long it’s getting to where I can’t see the forest for the trees!

I want to position a popup form on the screen.  It appears that the top, left position (0, 0) is inside the Access Application window, below the Ribbon and to the right of the Navigation pane.  So the actual top, left position (0, 0 in the Access Application), in relation to the screen (not the Access Application) will dynamically change based on the position of the Access Application window on the screen and the height of the Ribbon and the width of the Navigation pane.  For example, if I have the Access Application maximized and I move the popup form to just below the Ribbon and just to the right of the Navigation pane then the top, left of my popup form will be at 0, 0… if I move the popup form left or up then the top, left will become a negative number.  If I move the popup form to the very top, left of the screen (not of the Access Application) then the top, left will change dynamically just by moving the Access Application window around the screen (in Normal Mode, as opposed to Minimized/Maximized) and by changing the size of the Ribbon and/or the Navigation pane… all without actually moving the popup form.  And that position will change drastically when the Access Application is minimized (my database runs with Access minimized and in “/runtime” mode, so the user only sees the forms and not the Access environment).

To test this I created a small popup form with no record selectors or navigation buttons, just 2 textboxes.  One for the popup form top position and one for the popup form left position.  Since there is no “Move” event (even though there is a “Resize” event, odd) I set the timer to “1” and in the timer event I set the value of the first textbox to “Me.WindowTop” and the other to “Me.WindowLeft”.  This way I can see the values in real time as I move the popup form, and the Access Application around the screen.  Another issue I ran into is the WindowTop / WindowLeft / WindowWidth / WindowHeight settings are all integers, so in a dual monitor environment if one of those values goes beyond 32,767 the value will change to a negative number!

So my question is (I know it took a long time to get here) how do I position a popup form in relation to the screen and NOT in relation to the Access Application?  Some cool things I found in my search are how to get the height of the Ribbon { CommandBars("ribbon").Height } but I couldn’t find a way to get the width of the Navigation pane.  As well as MANY API calls to get the screen size and the number of monitors.
Richard KirklandAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tuviCommented:
Put the following inside a module:

' SetWindowPos Flags
Public Const SWP_NOSIZE = &H1
Public Const SWP_SHOWWINDOW = &H40

' SetWindowPos() hwndInsertAfter values
Public Const HWND_TOPMOST = -1

Public Declare PtrSafe Function SetWindowPos Lib "user32" (ByVal hwnd As LongPtr, ByVal hWndInsertAfter As LongPtr, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Open in new window


Then, in your Form_Load event:

Private Sub Form_Load()
   SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 500, 500, SWP_SHOWWINDOW + SWP_NOSIZE
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Anders Ebro (Microsoft MVP)Microsoft DeveloperCommented:
Jack Leach wrote a GUI module that works very well for all sorts of window sizing and placing. You can find it over at UtterAccess:
http://www.utteraccess.com/forum/Gui-Functions-Class-t1974349.html

You will probably want the SetWindowGeneralPlacement function.
1
Richard KirklandAuthor Commented:
"SetWindowPos" works great, is there a "GetWindowPos" (I couldn't find it) to GET the current window position (again, in relation to the screen and NOT the Access Application Window)?

I haven't had a chance to browse through the GUI Module by Jack Leach yet, and I can't download it at work (I work on a military base and they severely restrict what we can & can not get to... sometimes I think they go a bit overboard!).
0
tuviCommented:
Again, put these in a module:

Public Type Rect
   Left As Long
   Top As Long
   Right As Long
   Bottom As Long
End Type

Public Declare PtrSafe Function GetWindowRect Lib "user32" (ByVal hwnd As LongPtr, lpRect As Rect) As Long

Open in new window


Then to get your window position:

Dim Rect As Rect
GetWindowRect Me.hwnd, Rect

Open in new window



The Rect.Left, Rect.Top is your x, y screen coordinate... (Rect.Right - Rect.Left) is your window width and (Rect.Bottom - Rect.Top) is your window height.
0
Richard KirklandAuthor Commented:
Ok, thanks!  I tried GetWindowRect but was getting the wrong values, I guess I was passing it the wrong handle!

Thanks for everyone's help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.