No announcement yet.

MSGBOX Function

  • Filter
  • Time
  • Show
Clear All
new posts

  • MSGBOX Function


    Sorry if this is a dumb question... How do I get
    the window that's created by the MSGBOX function to
    be centered on the parent window instead of centered
    on the desktop? Thanks!


    Scott Wolfington

  • #2
    I suspect the MSGBOX function always uses the desktop as the "parent" window. You might prefer to use the MessageBox API call here instead, as it allows you to specify the desired parent window.

    Tom Hanlin
    PowerBASIC Staff


    • #3
      As Tom said, you'll need to use the API to create the message box instead of the MSGBOX function, and use the handle of your window as the parent of the message box.

      But that will still result in a message box that is centered on the deskstop, and since you don't have access to the message box's callback function you have to jump through some hoops...

      Then the trick is to subclass the parent window just before calling the messagebox API function, and when your window proc sees %WM_ACTIVATE, get the window handle of the message box from lParam and use SetWindowPos to move the message box to the desired location. You'll need to calculate the center of the parent window and the size of the message box in order to obtain the necessary location for SetWindowPos.

      After the message box is dismissed, un-subclass the parent window to return everything to normal.

      -- Eric

      Perfect Sync: Perfect Sync Development Tools
      Email: mailto:[email protected][email protected]</A>

      "Not my circus, not my monkeys."


      • #4
        Maybe easier to build child DDT (two buttons, ImageX, label/disabled textbox)



        • #5
          A vb example is on my site uls32 or something and also MsgboxPos

          uls shows you how to change the icon and fonts.

          [email protected]