Announcement

Collapse

Maintenance

The forum could be offline for 30-60 minutes in the very near future for maintenance (said 3pm Pacific). I was behind on getting this notice. I do apologize.
See more
See less

Centering Dialog in Parent

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Centering Dialog in Parent

    I am trying to center a pop-up dialog in it's parent window, but whenever I move the parent and call the pop-up dialog it centers inteself on the desktop.

    Accoring to the manual if I supply the parent window handle (hDlg in this case) and leave the x, y coords. out of the DIALOG NEW it should self center, but it doesn't seem to work for me.

    Here is the code I'm using for the dialog creation

    Code:
    DIALOG NEW hDlg, "", , , 180, 25, %WS_POPUP Or %WS_DLGFRAME TO sDlg
    CONTROL ADD LABEL, sDLg, 1, "The message list is updating, please wait...", 5, 10, 175, 15,%SS_CENTER
    DIALOG SHOW MODELESS sDlg

    [This message has been edited by George Bleck (edited March 18, 2000).]
    <b>George W. Bleck</b>
    <img src='http://www.blecktech.com/myemail.gif'>

  • #2
    George -
    Use %WS_CHILD instead of %WS_POPUP

    ------------------

    Comment


    • #3
      No good... now the dialog doesn't appear at all.
      <b>George W. Bleck</b>
      <img src='http://www.blecktech.com/myemail.gif'>

      Comment


      • #4
        Hmmm ...
        Code:
        #Compile Exe
        #Register None
        DefLng A-Z
        #Include "Win32Api.Inc"
        Function PbMain
           Local sdlg As Long
           Dialog New 0, "Select station", , , 200, 100, %WS_SYSMENU To hDlg
           Dialog New hDlg, "", 5, 45, 180, 10, %WS_CHILD Or %WS_VISIBLE Or %WS_DLGFRAME To sDlg
           Control Add Label, sDLg, 1, "The message list is updating, please wait...", 0, 0, 180, 10,%SS_CENTER
           Dialog Show Modeless sDlg
           Dialog Show Modal hDlg
        End Function
        Perhaps, you expect something another.
        If you use %WS_CHILD, you should give coordinates in client area
        (so, "self-centering" is impossible)

        Unlike %WS_CHILD, location of %WS_POPUP is independent from location of parent window and you set screen (not client's) coordinates. So, here centering is centering on desktop.

        If you move parent window, %WS_CHILD window moves together with parent. %WS_POPUP stays on old place.


        [This message has been edited by Semen Matusovski (edited March 18, 2000).]

        Comment


        • #5
          I didn't know you couldn't auto center a child dialog, Thanks Semen.

          I wound up using DIALOG GET SIZE of the parent and just figured out the center coords. from there.

          Thanks for the help!

          --- George
          <b>George W. Bleck</b>
          <img src='http://www.blecktech.com/myemail.gif'>

          Comment


          • #6
            George --
            Look this sample. I prefer SetWindowPos, because DIALOG GET SIZE, depends of styles, returns either window or client size.
            Code:
            #Compile Exe
            #Register None
            #Dim All
            #Include "Win32Api.Inc"
            Sub CenterChild (hWnd As Long)
               Dim tRect1 As Rect, tRect2 As Rect
               Local xx1 As Long, xx2 As Long, yy1 As Long, yy2 As Long
               GetClientRect GetParent(hWnd), tRect1
               GetWindowRect hWnd, tRect2
               xx1 = (tRect1.nRight - tRect1.nLeft): xx2 = (tRect2.nRight - tRect2.nLeft)
               yy1 = (tRect1.nBottom - tRect1.nTop): yy2 = (tRect2.nBottom - tRect2.nTop)
               SetWindowPos hWnd, 0, (xx1 - xx2) / 2, (yy1 - yy2) / 2, xx2, yy2, 0
            End Sub
            Function PbMain
               Local hdlg As Long, sDlg As Long
               Dialog New 0, "Centering", , , 400, 100, %WS_SYSMENU To hDlg
               Dialog New hDlg, "", , , 200, 30, %WS_CHILD Or %WS_VISIBLE Or %WS_DLGFRAME To sDlg
               CenterChild sDlg
               Control Add Label, sDLg, 101, "The message list is updating, please wait...", 0, 0, 140, 8,%SS_CENTER
               CenterChild GetDlgItem(sDlg, 101)
               Dialog Show Modeless sDlg
               Dialog Show Modal hDlg
            End Function

            [This message has been edited by Semen Matusovski (edited March 18, 2000).]

            Comment

            Working...
            X