Announcement

Collapse
No announcement yet.

%WS_EX_CONTEXTHELP - example use?

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

  • %WS_EX_CONTEXTHELP - example use?

    Does anyone have any examples on using dialogs with %WS_EX_CONTEXTHELP extended style? i searched POFFS and that came up with 4 results, i then searched using the forum and strangely that only returned 2 results, but none of them really helped
    I understand that the CBMsg is %WM_HELP but my attempts to implement it by guesswork have so far failed miserably
    Any help is much appreciated


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

  • #2
    take a look lance's sample
    note, ds_contexthelp is just a placeholder. when the dialog box is created, the system checks for ds_contexthelp and, if it is there, adds ws_ex_contexthelp to the extended style of the dialog box.
    of course, you can use ws_ex_contexthelp instead of ds_contexthelp.
    also, contexthelp doesn't like ws_maximizebox (minimizebox)


    ------------------
    e-mail: [email protected]

    Comment


    • #3
      Semen - thanks! That was exactly what I was looking for - a nice simple demo of the function and nothing more
      No wonder I couldn't find it using a search - it doesn't use %WS_EX_CONTEXTHELP
      Many thanks Lance for that demo!
      ------------------
      problem: If you add %WS_MINIMIZEBOX to the dialog style in Lance's demo, the Help Context button then becomes 'unclickable'! It's visible, but clicking on it doesn't have the normal push-down button effect, the mousecursor doesn't change, etc
      My dialog needs to have both a minimise button and a help context button - is this possible?
      Thanks again!


      [This message has been edited by Wayne Diamond (edited March 11, 2001).]
      -

      Comment


      • #4
        My dialog needs to have both a minimise button and a help context button - is this possible?
        This behaviour is, unfortunately, by design (thanks a lot MS ). See Knowledge Base article Q135787.

        [This message has been edited by Matthew Berg (edited June 04, 2001).]
        If you try to make something idiot-proof, someone will invent a better idiot.

        Comment


        • #5

          Wayne,

          >> My dialog needs to have both a minimise button and a help context button - is this possible?

          Most sizable-window programs use the right-click 'Whats this?' menu or 'Whats this?' help in the main help menu that changes the cursor to a context help cursor (then click on a control).


          ------------------
          Kev G Peel
          KGP Software, Bridgwater, UK.
          mailto:[email protected][email protected]</A> http://www.kgpsoftware.com
          kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

          Comment


          • #6
            Actually, not so difficult.
            I quickly modified old code (which you can find in Source Code section). Tested ubder Win2000 only, but should work everywhere.

            Code:
               #Compile Exe
               #Register None
               #Dim All
               #Include "win32api.INC"
            
               Global DlgProcOld As Long
            
               CallBack Function DlgProcOr
                  Static rcCaption As Rect, rcCaptionButtons() As RECT, _
                         StatusCaptionButtons() As Long, nCaptionButtons As Long
            
                  If CbMsg = %WM_USER + 999 Then ' Init
                     nCaptionButtons = CbWparam
                     ReDim rcCaptionButtons(1 To nCaptionButtons)
                     ReDim StatusCaptionButtons(1 To nCaptionButtons)
                     Exit Function
                  End If
            
                  Local hDC As Long, rc As RECT, dStyle As Long, dExStyle As Long
                  Local i As Long, j As Long,  k As Long
                  Local NeedToRefresh As Long, Pnt As POINTAPI, lResult As Long
                  Local cx As Long, cy As Long, cxBtn As Long, cyBtn As Long, dx As Long
            
                  lResult = CallWindowProc(DlgProcOld, CbHndl, CbMsg, CbWparam, CbLparam)
                  Select Case CbMsg
                     Case %WM_NCHITTEST
                        If (lResult = %HTCAPTION) Then k = 1
                     Case %WM_NCLBUTTONDOWN, %WM_NCLBUTTONUP, %WM_NCMOUSEMOVE, _
                          %WM_NCACTIVATE, %WM_NCPAINT, %WM_SETTEXT
                        k = 1
                   End Select
                   If k Then
                     GetWindowRect CbHndl, rc
                     Pnt.x = Cvi(Mkl$(CbLparam), 1) - rc.nLeft
                     Pnt.y = Cvi(Mkl$(CbLparam), 3) - rc.nTop
            
                     dStyle   = GetWindowLong(CbHndl, %GWL_STYLE)
                     dExStyle = GetWindowLong(CbHndl, %GWL_EXSTYLE)
            
                     If (dStyle And %WS_THICKFRAME) = %WS_THICKFRAME Then
                        cx = GetSystemMetrics(%SM_CXSIZEFRAME)
                        cy = GetSystemMetrics(%SM_CYSIZEFRAME)
                     Else
                        cx = GetSystemMetrics(%SM_CXFIXEDFRAME)
                        cy = GetSystemMetrics(%SM_CYFIXEDFRAME)
                     End If
            
                     GetWindowRect CbHndl, rcCaption
                     rcCaption.nBottom = rcCaption.nBottom - rcCaption.nTop
                     rcCaption.nRight  = rcCaption.nRight - rcCaption.nLeft
                     rcCaption.nTop    = cy
                     rcCaption.nLeft   = cx
                     rcCaption.nRight  = rcCaption.nRight - cx
                     rcCaption.nBottom = rcCaption.nTop + GetSystemMetrics(%SM_CYCAPTION) - _
                                                          GetSystemMetrics(%SM_CYBORDER)
                     cxBtn = GetSystemMetrics(%SM_CXSIZE)
                     cyBtn = GetSystemMetrics(%SM_CYSIZE)
            
                     dx = rcCaption.nRight
                     If (dStyle And %WS_SYSMENU) = %WS_SYSMENU Then
                        dx = dx - cxBtn - 2
                        If ((dStyle And %WS_MAXIMIZEBOX) = %WS_MAXIMIZEBOX) Or _
                           ((dStyle And %WS_MINIMIZEBOX) = %WS_MINIMIZEBOX) Then _
                           dx = dx - 2 * cxBtn - 2
                     End If
                     If (dExStyle And %WS_EX_CONTEXTHELP) = %WS_EX_CONTEXTHELP Then _
                        dx = dx - cxBtn - 2
                     For i = 1 To nCaptionButtons
                        rcCaptionButtons(i).nRight = dx - 2 - (nCaptionButtons - i) * cxBtn
                        rcCaptionButtons(i).nLeft = dx - 2 - (nCaptionButtons - i + 1) * cxBtn
                        rcCaptionButtons(i).nTop = rcCaption.nTop + 2
                        rcCaptionButtons(i).nBottom = rcCaption.nBottom - 2
                     Next
            
                     For i = 1 To nCaptionButtons
                        If PtInRect(rcCaptionButtons(i), Pnt.x, Pnt.y) Then j = i
                     Next
                  End If
            
                  Select Case CbMsg
                     Case %WM_DESTROY: SetWindowLong(CbHndl, %GWL_WNDPROC, DlgProcOld
                     Case %WM_NCHITTEST
                        If j <> 0 And (lResult = %HTCAPTION) Then lResult = 9999
                     Case %WM_NCMOUSEMOVE
                        For i = 1 To nCaptionButtons
                           If (i <> j) Then If (StatusCaptionButtons(i)) <> 0 Then _
                              StatusCaptionButtons(i) = 0: NeedToRefresh = %True
                        Next
                     Case %WM_NCLBUTTONDOWN
                        For i = 1 To nCaptionButtons
                           If j = i Then
                              If StatusCaptionButtons(i) = 0 Then _
                                 StatusCaptionButtons(i) = 1: NeedToRefresh = %True
                           Else
                              If StatusCaptionButtons(i) = 1 Then _
                                 StatusCaptionButtons(i) = 0: NeedToRefresh = %True
                           End If
                        Next
                     Case %WM_NCLBUTTONUP
                        For i = 1 To nCaptionButtons
                           If StatusCaptionButtons(i) = 1 Then
                              StatusCaptionButtons(i) = 0: NeedToRefresh = %True
                              If j = i Then PostMessage CbHndl, %WM_USER + 998, i, 0
                           End If
                        Next
                     Case %WM_NCACTIVATE, %WM_NCPAINT, %WM_SETTEXT
                        NeedToRefresh = %True
                  End Select
                  If NeedToRefresh Then
                     ' Draw - this is a sample only
                     hDc = GetWindowDC(CbHndl)
                     Local hFont As Long
                     hFont = CreateFont(cxBtn * 0.8, cyBtn - 2, 0, 0, %FW_NORMAL, 0, 0, 0, _
                               %ANSI_CHARSET, %OUT_TT_PRECIS, %CLIP_DEFAULT_PRECIS, _
                               %DEFAULT_QUALITY, %FF_DONTCARE, "Courier New")
                     SelectObject hDC, hFont
                     SetBkMode hDC, %Transparent
                     SetTextColor hDc, %Black
                     For i = 1 To nCaptionButtons
                        If StatusCaptionButtons(i) = %False Then j = 0 Else j = %DFCS_PUSHED
                        If i = nCaptionButtons Then
                           DrawFrameControl hDc, rcCaptionButtons(i), %DFC_CAPTION, %DFCS_CAPTIONHELP Or j
                        Else
                        DrawFrameControl hDc, rcCaptionButtons(i), %DFC_BUTTON, %DFCS_BUTTONPUSH Or j
                        
                        DrawText hDC, Mid$(Str$(i), 2), -1, rcCaptionButtons(i), _
                           %DT_SINGLELINE Or %DT_CENTER Or %DT_VCENTER
                        End If
                     Next
                     ReleaseDC CbHndl, hDC
                     DeleteObject hFont
                  End If
                  Function = lResult
               End Function
            
               CallBack Function DlgProc
                  Select Case CbMsg
                     Case %WM_INITDIALOG: SendMessage CbHndl, %WM_USER + 999, 5, 0 ' Init
                     Case %WM_USER + 998:
                          If CbWparam < 5 Then MsgBox "Button" + Str$(CbWparam) Else _
                             SendMessage CbHndl, %WM_SYSCOMMAND, %SC_CONTEXTHELP, 0
                     Case %WM_HELP
                         Dim lphi As HELPINFO Ptr
                         lphi = CbLparam
                         MsgBox "Help on control ID#" + Str$(@lphi.iCtrlId)
                     Case %WM_COMMAND: If CbCtl = %IDOK Then SetWindowText CbHndl, Time$
                   End Select
                End Function
            
                Function PbMain
                   Local hDlg As Long
                   Dialog New 0, " Own buttons", , , 200, 230, %WS_SYSMENU Or %WS_MINIMIZEBOX Or _
                      %WS_MAXIMIZEBOX Or %WS_CAPTION Or %WS_THICKFRAME To hDlg
                   Control Add ComboBox, hDlg, 101,, 10, 40, 170, 100, %CBS_DROPDOWNLIST Or %WS_TABSTOP
                   Control Add TextBox,  hDlg, 102, "This is an edit control", 10, 60, 170, 130, %ES_MULTILINE _
                       Or %ES_WANTRETURN Or %WS_BORDER Or %WS_HSCROLL Or %WS_VSCROLL Or %WS_TABSTOP, _
                       %WS_EX_CLIENTEDGE
                   ComboBox Add hDlg, 101, "This is a combo box!"
                   ComboBox Select hDlg, 101, 1
                      
                      
                   Control Add Button, hDlg, %IDOK, "&Change Title", 50, 5, 100, 14
                   DlgProcOld = SetWindowLong(hDlg, %GWL_WNDPROC, CodePtr(DlgProcOr))
                   Dialog Show Modal hDlg, Call DlgProc
                End Function
            ------------------
            E-MAIL: [email protected]

            Comment


            • #7
              Strewth! That's very very cool, I never knew it was possible to have other buttons up there too!
              You never cease to amaze me Semen

              Thankyou very much,
              Wayne


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

              Comment


              • #8
                Most sizable-window programs use the right-click 'Whats this?' menu or 'Whats this?' help in the main help menu that changes the cursor to a context help cursor (then click on a control).
                This is covered in the book Microsoft Windows User Experience.
                If you try to make something idiot-proof, someone will invent a better idiot.

                Comment

                Working...
                X