` Printed Icetips Article

Icetips Article



Par2: Popup menus -- specifying location dynamically
1998-05-15 -- Arnor Baldvinsson
 
>When I use x and y coordinates to specify the location for a popup menu,
>can I make those x and y coordinates refer to my MDI Frame instead of my
>desktop?


I've hit this problem and solved it.  The reason for the odd
positioning is that the position for the popup MUST be in pixels, not
dialog units.  But using pixels is not enough, because popup menus are
positioned relative to the screen, not the window.  So if you have a
popup at 100,100 pixels and your window is not maximized the popup
menu will not appear related to where your window is, but at 100,100
from the top left corner of the SCREEN!  Now, the solution is very
simple and requires one simple api call ClientToScreen.  It takes two
parameters, the window handle and a pointer to a POINT structure.  The
Point structure is declared as:

POINT           GROUP,TYPE
X                SIGNED
Y                SIGNED
                END

and the call is prototyped in 16bit:

Module('WIN16.LIB')
  ClientToScreen(HWND, *POINT),PASCAL,RAW
End

32 bit:

Module('WIN32.LIB')
  ClientToScreen(HWND, *POINT),PASCAL,RAW
End

To use it:

Loc:Point    POINT 
Loc:Xpos     SIGNED
Loc:Ypos     SIGNED
Code
Loc:Point.X = ?MyControl{Prop:Xpos}
Loc:Point.Y = ?MyControl{Prop:Ypos}
If ClientToScreen(Window{Prop:Handle},Loc:Point)
   Loc:Xpos = Loc:Point.X
   Loc:Ypos = Loc:Point.Y
Else
   Message('Could not convert client to screen')
End

I'm going a bit from memory here, but I think this is pretty much all
you need to do.  I don't remember if I had to set the
Window{Prop:Pixels}=True before getting the X/Y positions for the
control, seem to recall it worked with DLU too.



Printed May 4, 2024, 8:14 am
This article has been viewed/printed 35114 times.