Announcement

Collapse
No announcement yet.

Tooltips, %WS_CHILD and %WM_NOTIFY

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

  • Tooltips, %WS_CHILD and %WM_NOTIFY

    Please can somebody give me a pointer (no pun intended) on the code
    below. I've created a dialog with tooltips that works fine with
    both DDT buttons and a static button created with CreateWindowEx.
    If I click on one of my buttons I create a child dialog with a
    second static button, again the tooltip works fine.

    If I remove the comment to make the static window have the style
    %WS_CHILD then the tooltips fail to work. Can anybody explain this
    for me? I'm sure that there are several other ways of doing this
    but this is just a small example of part of a major project and
    i'm not sure that I could change the way that project is written -
    he who pays the bills has designed it that way! I've also noticed
    that the parent dialog's tooltips don't work when the child is
    displayed - any way of getting them to work.

    Does anybody want to guess at how many posts are going to appear
    about "The Announcement" we all received?

    Regards

    Nick

    Code:
    #Compile Exe
    #Include "win32api.inc"
    #Include "commctrl.inc
    
    Global hChild    As Long
    Global hDlg      As Long
    Global hTTip     As Long
    Global hInstance As Long
    Declare Function ShowChild() As Long
    
    '=====================/ Enumeration callback /=================================
    
    Function EnumChildProc(ByVal CtrlDlg As Long, param As Long) As Long
      Local lTI As TOOLINFO, lZStr As Asciiz * 128
      GetClassName CtrlDlg, lzStr, SizeOf(lzStr)
      If lzStr <> "STATIC" Then
        lTI.cbSize  = SizeOf(lTI)
        lTI.uFlags  = %TTF_IDISHWND Or %TTF_SUBCLASS
        lTI.hwnd    = hDlg
        lTI.uID     = CtrlDlg
        lTI.hInst   = hInstance
        lTI.lpszText= %LPSTR_TEXTCALLBACK
        SendMessage hTTip, %TTM_ADDTOOL, 0, VarPtr(lTI)
      End If
      Function = 1
    End Function
    
    '==============================================================================
    Function AddToolTips (ByVal hDlg As Long) As Long
      hTTip = CreateWindowEx (0, _
                              "tooltips_class32", _
                              ByVal %NULL, _
                              %WS_POPUP Or %TTS_ALWAYSTIP, _
                              %CW_USEDEFAULT, _
                              %CW_USEDEFAULT, _
                              %CW_USEDEFAULT, _
                              %CW_USEDEFAULT, _
                              ByVal hDlg, _
                              ByVal %NULL, _
                              GetWindowLong (hDlg, %GWL_HINSTANCE), _
                              ByVal %NULL)
      If hTTip = %FALSE Then Function = 0 : Exit Function
    
      If (EnumChildWindows (hDlg, CodePtr(EnumChildProc), 0)) = 0 Then
        Function = %FALSE
      Else
        Function = %TRUE
      End If
    End Function
    
    '==============================================================================
    CallBack Function MainCb() As Long
      Local lTTptr As TOOLTIPTEXT Ptr, lZStr As Asciiz * 64
      
      If CbCtl = 104 Then
        ShowChild
        Exit Function
      ElseIf CbCtl = 105 Then
         Dialog End hChild
         Exit Function
      End If
    
      Select Case CbMsg
        Case %WM_NOTIFY
          lTTPtr = CbLparam
          If @lTTPtr.Hdr.Code = %TTN_NEEDTEXT Then
             lZStr = Time$
             @lTTPtr.lpszText = VarPtr(lZStr)
          End If
      End Select
    
    End Function
    
    '==============================================================================
    Function WinMain (ByVal CurInst&, ByVal PrvInst&, CmdLine As Asciiz Ptr, _
                      ByVal CmdShow&) Export As Long
      Local lRet As Long
      hInstance = CurInst&
      InitCommonControls
      Dialog New 0, "ToolTip",,,320,240,%WS_OVERLAPPED Or %WS_SYSMENU To hDlg
      Control Add Button, hDlg,101,"Button #1",10,10,40,14,%WS_TABSTOP
      ID%=102
      Style&=%WS_CHILD Or %WS_VISIBLE Or %WS_DLGFRAME Or %SS_NOTIFY
      hCTL& = CreateWindowEx(0,"STATIC","Static"+Chr$(0),Style&,15,50,60,24,hDlg,ID%,hInstance,ByVal %NULL)
      Control Add Button, hDlg,104,"Show Child",270,206,40,14,%WS_TABSTOP
      Control Handle hDlg,101 To lRet
      AddToolTips hDlg
      Dialog Show Modal hDlg Call MainCb
    End Function
    
    '==============================================================================
    Function ShowChild() As Long
      'Style&=%WS_CHILD
      Dialog New hDlg,"", 60, 60, 260, 180, Style& To hChild
      ID%=105
      Style&=%WS_CHILD Or %WS_VISIBLE Or %WS_DLGFRAME Or %SS_BITMAP Or %SS_CENTERIMAGE Or %SS_NOTIFY
      hCTL& = CreateWindowEx(0,"STATIC","Q-STRING"+Chr$(0),Style&,20,20,50,50,hChild,ID%,hInstance,ByVal %NULL)
      AddToolTips hChild
      Dialog Show Modal hChild Call MainCb
    End Function

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

  • #2
    Nick, the problem is that when the child dialog is assigned the WS_CHILD style and it is created as a modal dialog, the main dialog automatically becomes disabled and hence no tooltips work.

    In fact, nothing really works in this situation, as a WS_CHILD dialog is generally used as "part-of" a parent dialog, rather than a stand-alone dialog.

    One solution is to make the child dialog a MODELESS dialog (and give it the %DS_CONTROL style too, plus give the main dialog the extended style %WS_EX_CONTROLPARENT), but without knowing what you want the UI to do, that may not be the best answer.

    Can you describe what it is you are trying to achieve? (or is this just an experiment?).

    Thanks!


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

    Comment


    • #3
      Sorry Lance, I should have picked up that my dialogs were modal,
      changing them both to modeless with a doevents loop has sorted the
      problem on my test program.

      The question is related to a real problem. Our current released
      software is written using PBDK which we are in the process of
      re-writing to PBDLL after a bit of a shock trying to use VB. PBDLL
      is going great and is much much more stable than PBDK and obviously
      more powerful being 32-bit. The PBDK version consists of some
      standard code that is included into every program we create so
      that we have ended up with our different modules made up as one
      file containg all the code to do "stuff" and linking to the standard
      code includes. We're trying to move into PBDLL asap and have
      re-written the standard includes into PBDLL in such a way that the
      actual program modules that do "stuff" can almost be lifted
      direct into the PBDLL compiler and compiled with the minimum changes.

      Ok, thats the history. What I posted was a much trimmed down version
      of how these standard routines work, i.e. create a main window that
      is a background with a child in the bottom right corner that
      changes depending on what the application does. Think of it a bit
      like Internet explorer with a toolbar at the top, favourites on
      the left and the bottom right (largest) pane changing for whatever
      you are up to. Maybe we should be doing this with one dialog but
      thats not how the PBDK version works and speed to convert is the
      main criteria (had enough of PBDK!). Once its up and running then
      we can look to change it but for now it's got to be done & quickly.

      By adding modeless into my test program (as per my main project)
      I have cured the test program so that tooltips work ok but I
      still have the problem with my project. There must be something else
      in the project that is stopping the tooltips from working - I dont
      get the %WM_NOTIFY message at all. I'll look into it.

      Out of interest what do the %DS styles you mentioned do?

      Thanks for your help, a few months ago I was one of your cases
      for "Get a proper Windows programming book". Now I feel much
      happier with it all but some things can be hard to fathom or I
      make silly mistakes like this. The forums are great and such a
      help in understanding the change from DOS to Windows. Thanks again.

      Nick



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

      Comment


      • #4
        Helping where we can is our pleasure!

        Ok, just to be clear, the child dialog is to form "part" of the main dialog (and assuming you must have two dialogs for some undisclosed reason).

        If my interpretation of your requirements are correct, then I would to it this way:

        Main dialog:
        * Uses %WS_EX_CONTROLPARENT <U>extended</U> style, in addition to any other normal and extended styles
        * Main dialog will be a MODAL dialog.

        Child dialog:
        * Uses %WS_CHILD and %DS_CONTROL styles (Use 'OR' to mix these together - standard DDT stuff).
        * Child dialog will be a MODELESS dialog.

        This way, the message pump that the Modal dialog [automatically] provides by itself will also serve the modeless dialog too.

        As far as the dialog styles go, I suggest that you download and install the WIN32.HLP file from http://www.powerbasic.com/files/pub/mstools/win32.zip - it covers many of these kinds of questions but you may have to dig through it a little.

        If you have yet to buy an API "bible", I would recommend the Rector/Newcomer title for you here.


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

        Comment


        • #5
          Thanks for the tips. I've got my tooltips working perfectly now,
          the problem was down to pasting some helpful code from the forums
          and missing a handle that was incorrect on my main program. Something
          I should have found for myself basically!

          The undisclosed reason for the parent & child dialogs goes back
          to PBDK really. Our software is mainly data input, normally with
          more fields than can be displayed in one screen at a time, up to
          60 edit boxes with a label each in the worst case but generally
          20 edits & labels. One program alone may contain up to 17 screens
          of data input! We don't use a tab control to do this and ended up
          making our own form of a tab control using a child window that
          is created and then destroyed for each separate tab. It was also
          convenient to place all the controls on a child window and then
          show it so that they were all displayed at the same time and could
          also be deleted easily be deleting the child window. Bear in mind
          that PBDK stuttered a bit sometimes, you could see the controls
          being built one by one!

          Possibly we should be doing this with just one window now provided
          that we can display & delete the contents of what is currently our
          child in one go. As I said in the last post, speed into PBDLL is
          our main criteria and there's an element of "if it ain't broke,
          don't fix it"!

          Cheers

          Nick



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

          Comment

          Working...
          X