Announcement

Collapse
No announcement yet.

Dialog drag anomaly and screen resolutions

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

  • Dialog drag anomaly and screen resolutions

    Two questions: can somebody help?

    First. A dialog is created with parent 0 (desktop) and

    Style = %WS_SYSMENU Or _
    %WS_MINIMIZEBOX Or _
    %DS_SETFOREGROUND Or _
    %WS_CAPTION

    --and displayed with ShowModal.

    A couple of further dialogs are added with the above one as parent, and shown as modeless.

    When the parent is dragged, the other two don't move along: only the parent dialog moves. Why is this?


    Second: is there a way to ensure that an application developed with a (say) 800 x 600 screen will display correctly on another PC with some other setting?


  • #2
    Going from my memory, the child dialogs should have the %WS_CHILD style, and you may need to add %DS_CONTROL (I'm not at my DEV PC to confirm this). When using %DS_CONTROL it is usual to give the 'parent' dialog the extended style %WS_EX_CONTROLPARENT.

    If you are still having problems, it may be a good idea if you could post the code... it's the fastest way to get definitive help. Thanks!

    With respect to screen resolution - the concept of using dialog units is to make your dialog boxes as resolution-independant as possible. However, once you start using non-standard fonts for your controls, you open yourself up to the possibility that on some PC's the requested font is not available in the exact size you want - if Windows uses another size/font/weight then your controls may clip the text.

    In general, using the standard dialog font results in the most reliable results. It often pays to develop your apps in 640x480 mode and then thoroughly test them in other resolutions and font size variations (remember that it is possible to specify a completely radical font and font size in Control Panel which can play havoc - luckily this is rare!)

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Windows terminology sadly does not distinguish between correctly the two "different" types of child windows.

      Using the term Parent window, would seemly imply that those windows who have a Parent must be children, but this is not correct.

      I prefer to use the following terminology:

      A Child Window (which uses the %WS_CHILD style) is always a control. Even if you embed a Dialog within a Dialog by giving it the %WS_CHILD style, technically it is just a control that holds other controls.

      Child windows always move with the Parent window and are also clipped by the Parent within the Parents client area.

      The second Child Like type of Window is what I like to call a Subordinate Window. This type of window does not use the %WS_CHILD style, but rather uses the %WS_POPUP style, but it also has a Parent (besides the desktop). These type of children "float" above their parent as independent windows. Because they have been assigned a Parent, they will always float above the Parent.

      This second type of child window while having a Parent (floating above it), does not act like the true Child window (%WS_CHILD). It does not follow the Parent around. The Parent can move but the child stays put. The child can move and the parent can stay put. They are truly independent windows, except that the child will always stay on top of its parent.

      I am assuming that your question is actually relating to the Subordinate type child window rather than the true child window (%WS_CHILD). Subordinate windows do not follow their parent around. You would have to respond to the %WM_MOVE message for the parent and then move the child yourself to make them stay together. The problem is that if the child has a caption bar it can be moved too. If you don't want this then simply remove the caption bar from the child.

      Now, if you are talking about a real child window (%WS_CHILD), then it must move with the Parent, because technically it is a control. Controls always move with their parent (at least under normal circumstances).


      ------------------
      Chris Boss
      Computer Workshop
      Developer of "EZGUI"
      http://cwsof.com
      http://twitter.com/EZGUIProGuy

      Comment


      • #4
        Lance and Chris, thank you.
        I modified as you suggest, but the parent dialog still moves with the children staying put.

        The code is rather big, but includes only the two functions concerned with creating the dialogs. There is code which may be irrelevant, but it is just possible that a gremlin hides there!
        Thanks again
        '________________________________________________________________

        CallBack Function QuLetter ()
        On Error GoTo QutLtrErr
        If ScrnName$="Edit quotation letter" Then Exit Function

        Local style As Long
        Local lf As LOGFONT
        Static RectLetter As RECT
        Local rectFill As RECT
        Static hBrush As Long

        QLready&=0

        Style = %WS_POPUP Or _
        %DS_SETFONT Or _
        %DS_NOFAILCREATE Or _
        %DS_MODALFRAME Or _
        %DS_3DLOOK Or _
        %DS_SETFOREGROUND Or _
        %WS_CHILD Or _
        %DS_CONTROL

        Dialog New pDlg&, "", 0, 63, 423, 315, Style To hDlg&

        ScrnName$="Edit quotation letter"
        CurrLine&=6
        Control Add Frame, hDlg&, %QLmbxFrm, "", 6, 1, 412, 310

        Control Add Label, hDlg&, %QLmhdLbl, "", 7, 8, 409, 20, %SS_CENTER
        hFont = MakeFont("Times New Roman", 20)
        GetObject hFont&, SizeOf(lf), ByVal VarPtr(lf)
        lf.lfWeight = %FW_BOLD
        hFont = CreateFontIndirect(lf)
        Control Send hDlg&, %QLmhdLbl, %WM_SETFONT, hFont, 1
        Control Disable hDlg&, %QLmhdLbl

        Control Add Label, hDlg&, %QLaddLbl, "", 7, 26, 409, 12, _
        %SS_CENTER Or %SS_NOPREFIX
        hFont = MakeFont("Times New Roman", 12)
        GetObject hFont&, SizeOf(lf), ByVal VarPtr(lf)
        lf.lfWeight = %FW_MEDIUM
        hFont = CreateFontIndirect(lf)
        Control Send hDlg&, %QLaddLbl, %WM_SETFONT, hFont, 2

        Control Add Label, hDlg&, %QLtelLbl, "", 7, 38, 409, 12, _
        %SS_CENTER Or %SS_NOPREFIX
        hFont = MakeFont("Times New Roman", 10)
        GetObject hFont&, SizeOf(lf), ByVal VarPtr(lf)
        lf.lfWeight = %FW_MEDIUM
        hFont = CreateFontIndirect(lf)
        Control Send hDlg&, %QLtelLbl, %WM_SETFONT, hFont, 2
        r$=CompanyInfo("QLheading"+Str$(CoNo&))
        Control Set Text hDlg&, %QLmhdLbl, r$
        Control Set Text hDlg&, %QLaddLbl, CompanyInfo("OurAddress")
        Control Set Text hDlg&, %QLtelLbl, CompanyInfo("OurTelephone")
        QLtrCreated&=LetterDone
        Dialog Show Modeless hDlg&

        Style = %WS_POPUP Or _
        %WS_BORDER Or _
        %DS_NOFAILCREATE Or _
        %WS_CHILD Or _
        %DS_CONTROL


        Dialog New pDlg&, "", 14, 104, 402, 252, Style To qDlg&

        LFont& = MakeFont("Courier New", 11)
        GetObject LFont&, SizeOf(lf), ByVal VarPtr(lf)
        LFont& = CreateFontIndirect(lf)
        Dialog Send qDlg&, %DS_SETFONT, LFont&, 0

        Style = %WS_POPUP Or _
        %DS_SETFONT Or _
        %DS_NOFAILCREATE Or _
        %DS_MODALFRAME Or _
        %DS_SETFOREGROUND Or _
        %WS_CHILD Or _
        %DS_CONTROL


        Dialog New pDlg&, "", 430, 63, 98, 315, Style To fDlg&

        Control Add Frame, fDlg&, %QLTbxFrm, "", 3, 1, 92, 294
        hFont& = MakeFont("MS Sans Serif", 8)
        GetObject hFont&, SizeOf(lf), ByVal VarPtr(lf)
        lf.lfWeight = %FW_BOLD
        hFont = CreateFontIndirect(lf)
        Control Send fDlg&, %QLTbxFrm, %WM_SETFONT, hFont&, 2

        Control Add Frame, fDlg&, %QLLngFrm, "Language", 8, 6, 82, 31
        Control Send fDlg&, %QLLngFrm, %WM_SETFONT, hFont&, 2
        Control Add ComboBox, fDlg&, %QLLngCbx,, 12, 19, 74, 40, _
        %CBS_DROPDOWNLIST Or _ %CBS_DISABLENOSCROLL, _
        %WS_EX_RIGHT Call SetLanguage

        ComboBox Reset fDlg&, %QLLngCbx
        ComboBox Add fDlg&, %QLLngCbx, "Afrikaans"
        ComboBox Add fDlg&, %QLLngCbx, "English"

        Control Add Frame, fDlg&, %QLctcFrm, "Contact people", 8, 37, 82, 31
        Control Send fDlg&, %QLctcFrm, %WM_SETFONT, hFont&, 1
        Control Add ComboBox, fDlg&, %QLctcCbx,, 12, 51, 74, 100, _
        %CBS_DROPDOWNLIST Or _ %CBS_DISABLENOSCROLL, _
        %WS_EX_RIGHT Call SetSalutName

        r$=DebtorContacts (AccountID$)
        ContactName$="": NickName$=""
        If Len(r$)<60 Then
        ContactName$=Trim$(Left$(r$,20))
        NickName$=Mid$(r$,21,15)
        Control Disable fDlg&, %QLctcCbx
        Control Disable fDlg&, %QLctcFrm
        End If

        Control Add Frame, fDlg&, %QLtxiFrm, "Text inserts", 8, 68, 82, 31
        Control Send fDlg&, %QLtxiFrm, %WM_SETFONT, hFont&, 1

        Control Add ComboBox, fDlg&, %QLtxiCbx,, 12, 83, 74, 100, _
        %CBS_DROPDOWNLIST, _
        %WS_EX_RIGHT Call SetTxtIns

        Control Add Frame, fDlg&, %QLpdpFrm, "Price display", 8, 99, 82, 31
        Control Send fDlg&, %QLpdpFrm, %WM_SETFONT, hFont&, 1

        Control Add ComboBox, fDlg&, %QLpdpCbx,, 12, 113, 74, 100, _
        %CBS_DROPDOWNLIST, _
        %WS_EX_RIGHT Call QLpriceDisplay

        Control Add Button, fDlg&, %QLronBtn, "Show run-on", 8, 134, 82, 20,_ %BS_MULTILINE Call RunOnClick

        hFont& = MakeFont("MS Sans Serif", 10)
        GetObject hFont&, SizeOf(lf), ByVal VarPtr(lf)
        hFont = CreateFontIndirect(lf)
        Control Send fDlg&, %QLronBtn, %WM_SETFONT, hFont&, 1

        Control Add Button, fDlg&, %QLUprBtn, "Show unit price", _
        8, 158, 82, 20, _
        %BS_MULTILINE Call QLunitPrice

        Control Send fDlg&, %QLUprBtn, %WM_SETFONT, hFont&, 1

        Control Add Button, fDlg&, %QLrdoBtn, "Cancel and restart", _
        8, 182, 82, 20, %BS_MULTILINE

        Control Send fDlg&, %QLrdoBtn, %WM_SETFONT, hFont&, 1

        Control Add Button, fDlg&, 4321, "SAVE CHANGES", 8, 206, 82, 20, _ %BS_MULTILINE Call ExitClick

        Control Send fDlg&, 4321, %WM_SETFONT, hFont&, 1

        Control Add Button, fDlg&, 4322, "EXIT", 8, 230, 82, 20, _
        %BS_MULTILINE Call Abandon

        Control Send fDlg&, 4322, %WM_SETFONT, hFont&, 1

        'Control Add TextBox, fDlg&, 12345, "Test results", 8, 254, 82, 52, _ %ES_MULTILINE Or _ %ES_WANTRETURN, _
        %WS_EX_CLIENTEDGE

        Dialog Set Loc fDlg&, 430, 63
        Dialog Set Loc hDlg&, 0, 63
        Dialog Set Loc qDlg&, 14, 104
        TxtIns$=""

        If QLtrCreated&>0 Then
        Control Disable fDlg&, %QLLngFrm
        Control Disable fDlg&, %QLLngCbx
        Control Disable fDlg&, %QLctcFrm
        Control Disable fDlg&, %QLctcCbx
        MakeQuoteLetter "English"
        Lng$=LanguageOfLetter
        Select Case Lng$
        Case "A"
        ComboBox Select fDlg&, %QLLngCbx, 1
        Case "E"
        ComboBox Select fDlg&, %QLLngCbx, 2
        End Select
        QLlines&=QuoteLetterLineCount
        LetterLanguage$=Lng$
        SetUpLetter
        Else
        Control Disable fDlg&, %QLctcFrm
        Control Disable fDlg&, %QLctcCbx
        Control Disable fDlg&, %QLtxiFrm
        Control Disable fDlg&, %QLtxiCbx
        Control Disable fDlg&, %QLpdpFrm
        Control Disable fDlg&, %QLpdpCbx
        Control Disable fDlg&, %QLronBtn
        Control Disable fDlg&, %QLuprBtn
        Control Disable fDlg&, %QLrdoBtn
        Control Disable fDlg&, 4321
        Control Set Focus fDlg&, %QLLngCbx
        ComboBox Select fDlg&, %QLLngCbx, 2
        End If
        Dialog Show Modeless qDlg& Call EditLetter
        Dialog Show Modeless fDlg& Call QletterProc
        If UnitPrice&=1 Then Control Disable fDlg&, %QLuprBtn
        Control Set Focus qDlg&, 6
        QLready&=1
        Exit Function
        QutLtrErr:
        MsgBox("Error"+Str$(Err)+" in Basix, QuLetter")
        End Function
        '_____________________________________________________________________

        Function MkLetter Alias "MkLetter" (ByVal Qadd&) Export As String
        Local CmdPtr As Asciiz Ptr
        Coys&=Val(CompanyCount)
        CoNo&=1
        Psp&=0
        NewQlt&=0
        FirstTime&=1
        Call SetCurDir(1)

        Local Style As Long

        Style = %WS_SYSMENU Or _
        %WS_MINIMIZEBOX Or _
        %DS_SETFOREGROUND Or _
        %WS_CAPTION
        Dialog New 0, "Quotation letter", 0, 32, 534, 300, Style, _ %WS_EX_CONTROLPARENT To pDlg&

        ScrnName$="Main menu"

        Qrd&=Val(QuoteCnt("Normal"))
        Call FetchQuote(Qadd&)
        n&=ActiveSection
        sxa&=n&
        Call GetSxn(sxa&)
        Qts&=NumberOfQuantities
        AccountID$=QhdInfo ("QdrUnino")

        Local lf As LogFont

        Control Send pDlg&, 0, %WM_SETFONT, fFont&, 1
        Control Send pDlg&, 0, %WM_GETFONT, 0, 0 To hFont&
        GetObject hFont&, SizeOf(lf), ByVal VarPtr(lf)
        lf.lfWeight = %FW_BOLD
        QHFont& = CreateFontIndirect(lf)
        Dialog Show Modal pDlg& Call QuLetter
        Control Set Focus qDlg&, 6
        Function="Ok, done."
        End Function
        '_____________________________________________________________________

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

        Comment


        • #5
          Dieny --
          it was another purpose of this sample, but look: child dialog like slave follows with parent dialog.

          Code:
          #Compile Exe
          #Register None
          #Dim All
          #Include "Win32Api.Inc"
          Global hdlg As Long, sDlg As Long
          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
          CallBack Function ButCB
            Static StCh As Long
            StCh = 1 - StCh
            If StCh = 1 Then
               Dialog New hDlg, "Hello", , , 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
            Else
               Dialog End sdlg
            End If
          End Function
          Function PbMain
             Dialog New 0, "Centering", , , 400, 100, %WS_SYSMENU To hDlg
             Control Add Button, hDLg, 101, "Show/Hide", 10, 10, 60, 12, Call ButCB
             Dialog Show Modal hDlg
          End Function

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

          Comment


          • #6
            DienyduToit :

            You can Not use %WS_CHILD and %WS_POPUP together. As I described aboved, there are two types of Children Dialogs. (1) A real Child (uses %WS_CHILD) which is really a control (2) A Subordinate Dialog (uses %WS_POPUP).

            There are no other types of child Dialogs. It is one or the other. You cannot mix these particular styles.

            What you want to accomplish, requires you process the %WM_MOVE message for the Parent and that you manually move the Subordinate child window.



            ------------------
            Chris Boss
            Computer Workshop
            Developer of "EZGUI"
            http://cwsof.com
            http://twitter.com/EZGUIProGuy

            Comment


            • #7
              Chris, what you explained did the trick all right, thanks! I now have the parent dialog carrying its chilren along with it.

              Parent:

              Style = %WS_SYSMENU Or _
              %WS_MINIMIZEBOX Or _
              %DS_SETFOREGROUND Or _
              %WS_CAPTION
              Dialog New 0, "Quotation letter", 0, 32, 534, 320, Style, _ %WS_EX_CONTROLPARENT To pDlg&

              -- and displayed as modal, with the child dialogs as ---

              Style = %DS_SETFONT Or _
              %DS_NOFAILCREATE Or _
              %DS_MODALFRAME Or _
              %DS_3DLOOK Or _
              %DS_SETFOREGROUND Or _
              %WS_CHILD
              '%DS_CONTROL Or _
              '%WS_POPUP Or _
              Dialog New pDlg&, "", 0, 0, 423, 315, Style To hDlg& 'top was 63

              --- and ---

              Style = %WS_BORDER Or _
              %DS_NOFAILCREATE Or _
              %WS_CHILD
              ' Or _ %DS_CONTROL
              '%WS_POPUP Or _

              Dialog New pDlg&, "", 14, 60, 402, 252, Style To qDlg& 'top was 104

              --- and ---

              Style = %DS_SETFONT Or _
              %DS_NOFAILCREATE Or _
              %DS_MODALFRAME Or _
              %DS_SETFOREGROUND Or _
              %WS_CHILD
              'Or _ %DS_CONTROL '%WS_POPUP Or _

              Dialog New pDlg&, "", 430, 0, 98, 315, Style To fDlg& 'top was 63
              HOWEVER, the trapping of the enter key in the subclassed function for all textboxes on qDlg& as well as %WM_LBUTTONDOWN (all of which worked perfectly before) suddenly did not work any more.

              SO, with a bit of experimeting, I hit on the weird solution below:

              The GetKeyNameText give Return or Num Return as text for the ENTER keys; in these cases, I FORCE the wMsg& and wParam& to what they were before, and what I would expect them to still be. If that MsgBox is active, it gives the wMsg& as &H101 (%WM_KEYUP) but a Select Case for KeyUp fails. It does seem to fire three or four "ENTERs" when one presses the ENTER key. For the %WM_LBUTTONDOWN I have found no solution yet.

              But this can't be the proper way to do it. Any ideas?


              Function Keyboard (ByVal hWnd&, ByVal wMsg&, ByVal wParam&, ByVal lParam&) As Long

              Local lf As LogFont
              Local Cpos As POINTAPI
              Local Msg As tagMsg
              Local Bfr As Asciiz * 20

              GetKeyNameText lParam&, Bfr, 20
              If Instr(UCase$(bfr),"ENTER")>0 Then
              'MsgBox(Str$(wMsg&)+Hex$(wMsg&)+Str$(wParam&))
              wMsg&=%WM_KEYDOWN
              wParam&=13
              End If

              Select Case wMsg&

              Case %WM_LBUTTONDOWN
              n&=GetDlgCtrlID(hWnd&)
              CurrLine&=n&
              ScrPos&=n&-6
              If QLlines&>0 And CurrLine&=QLlines& Then ScrPos&=ScrollMax&
              If Currline&<7 Then ScrPos&=0
              Control Handle qDlg&, %QLScrBar To hCtl&
              Call SetScrollPos (hCtl&, %SB_CTL, ScrPos&, %TRUE)
              Control Set Focus qDlg&, n&

              Case %WM_KEYDOWN

              Control Handle qDlg&, %QLScrBar To hCtl&

              Select Case wParam&

              Case 13 (etc.)

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

              Comment

              Working...
              X
              😀
              🥰
              🤢
              😎
              😡
              👍
              👎