main page >programming tips (VB5/6) > Positioning a MessageBox or a CommonDialog diese Seite auf deutsch | |
By default a MessageBox is displayed at the center of the screen. In some situations, however, a different
position may be preferable. But how can this be accomplished?
A Hook is the solution here. Short background info: placing a Hook means to tell the operating system to call a certain routine whenever a Windows message is fired that concerns the current thread. We do this in order to be notified when the MessageBox window is created; at this point the Hook routine also gives us the window handle so we can now send a message that places the window at the desired screen coordinates. The Hook should then be released immediately - except you wish to do additional tasks with it. The creation of a window (by the way: controls like Buttons, TextBoxes and so on are windows also!) is indicated by the message WM_CREATE. Now we have to find out whether it's the window in question; we use GetClassName to find out whether it's a window of class #32770 - if so, it's the window we are looking for, and we treat it as described above. Place the following code in a standard module:
Now placing a MessageBox is a simple task:
Additionally, since the CommonDialog window is of class #32770 also, the exactly same code as above
can be used to place CommonDialogs as well.
|
|
main page > programming tips (VB5/6) > this page | |
© 2001-2021 Wolfgang Enzinger |