
'====================================================================
'' Toolbar demo, with tooltips, modeless dialog as main.
'====================================================================

#include "dialogs.bas"

'====================================================================

Function DialogProc( Byval hDlg As  HWND, _
                     Byval uMsg As UINT, _
                     Byval wParam As WPARAM, _
                     Byval lParam As LPARAM ) As Integer

  Static As HANDLE hTT
  Static As HWND hWndTB

  Select Case uMsg

    Case WM_INITDIALOG

      Dim As TBADDBITMAP tbab
      Dim As TBBUTTON tbb(0 To 6)

      hWndTB = GetDlgItem( hDlg, 100 )

      '' Specify the structure size so the system can determine
      '' which version of the common control DLL is being used.
      ''
      SendMessage( hWndTB,TB_BUTTONSTRUCTSIZE,sizeof(TBBUTTON),0 )

      '' Add the system-defined bitmap button images to the
      '' list of available images.
      ''
      tbab.hInst = HINST_COMMCTRL
      tbab.nID = IDB_STD_SMALL_COLOR
      SendMessage( hWndTB, TB_ADDBITMAP, 0, cast(LPARAM,@tbab) )

      '' For each button, specify the button image index,
      '' the associated command identifier, and the button
      '' state and style.
      ''
      tbb(0).iBitmap = STD_FILENEW
      tbb(0).idCommand = 1000
      tbb(0).fsState = TBSTATE_ENABLED
      tbb(0).fsStyle = TBSTYLE_BUTTON
      tbb(1).iBitmap = STD_FILEOPEN
      tbb(1).idCommand = 1001
      tbb(1).fsState = TBSTATE_ENABLED
      tbb(1).fsStyle = TBSTYLE_BUTTON
      tbb(2).iBitmap = STD_FILESAVE
      tbb(2).idCommand = 1002
      tbb(2).fsState = TBSTATE_ENABLED
      tbb(2).fsStyle = TBSTYLE_BUTTON
      tbb(3).iBitmap = 0
      tbb(3).fsState = TBSTATE_ENABLED
      tbb(3).fsStyle = TBSTYLE_SEP
      tbb(4).iBitmap = STD_CUT
      tbb(4).idCommand = 1003
      tbb(4).fsState = TBSTATE_ENABLED
      tbb(4).fsStyle = TBSTYLE_BUTTON
      tbb(5).iBitmap = STD_COPY
      tbb(5).idCommand = 1004
      tbb(5).fsState = TBSTATE_ENABLED
      tbb(5).fsStyle = TBSTYLE_BUTTON
      tbb(6).iBitmap = STD_PASTE
      tbb(6).idCommand = 1005
      tbb(6).fsState = TBSTATE_ENABLED
      tbb(6).fsStyle = TBSTYLE_BUTTON

      '' Add the buttons to the toolbar.
      ''
      SendMessage( hWndTB,TB_ADDBUTTONS,7,cast(LPARAM,@tbb(0)) )

      '' Get the handle to the ToolTip control associated
      '' with the toolbar (by the TBSTYLE_TOOLTIPS style).
      ''
      hTT = cast(HANDLE,SendMessage( hWndTB,TB_GETTOOLTIPS,0,0 ))

      Return true

    Case WM_COMMAND

      Select Case loword(wParam)
        Case 1000
          MessageBox( hDlg, "New", "", 0 )
        Case 1001
          MessageBox( hDlg, "Open", "", 0 )
        Case 1002
          MessageBox( hDlg, "Save", "", 0 )
        Case 1003
          MessageBox( hDlg, "Cut", "", 0 )
        Case 1004
          MessageBox( hDlg, "Copy", "", 0 )
        Case 1005
          MessageBox( hDlg, "Paste", "", 0 )
      End Select

    Case WM_NOTIFY

      Dim As LPNMHDR pnm

      '' This necessary because TTN_GETDISPINFO is not
      '' fully defined in commctrl.bi (0.16b stable).
      ''
      #define _TTN_GETDISPINFO -520

      pnm = cast(LPNMHDR,lParam)
      If pnm->hwndFrom = hTT Then
        If pnm->code = _TTN_GETDISPINFO Then

          Dim As LPNMTTDISPINFO pdi

          '' Now know that pnm is actually pdi, and the ToolTip
          '' control is requesting information that it needs to
          '' display a tooltip. Note that the hdr member of the
          '' NMTTDISPINFO structure is a NMHDR structure.
          ''
          pdi = cast(LPNMTTDISPINFO, pnm)
          Select Case pdi->hdr.idFrom
            Case 1000
              pdi->szText = "New"
            Case 1001
              pdi->szText = "Open"
            Case 1002
              pdi->szText = "Save"
            Case 1003
              pdi->szText = "Cut"
            Case 1004
              pdi->szText = "Copy"
            Case 1005
              pdi->szText = "Paste"
          End Select

          '' This causes the ToolTip control to retain
          '' the information after the first request.
          ''
          pdi->uFlags = pdi->uFlags Or TTF_DI_SETITEM

        End If
      End If

    Case WM_SIZE

      Dim As RECT rcTB

      GetWindowRect( hWndTB, @rcTB )

      MoveWindow( hWndTB, 0, 0, loword(lParam), _
                  rcTB.bottom - rcTB.top + 1, false )

    Case WM_CLOSE

      DestroyWindow( hDlg )

    Case WM_DESTROY

      PostQuitMessage( null )

  End Select

  Return 0

End Function

'====================================================================

Dim As LPDLGTEMPLATE lpdt
Dim As HWND hDlg
Dim As MSG wMsg

InitializeCommonControls

Dialog( 1, 0, 0, 120, 90, "Toolbar Demo", lpdt, _
        WS_OVERLAPPEDWINDOW Or DS_CENTER Or WS_VISIBLE )

'' Instead of trying to anticipate the position and/or size of
'' the controls, just use zeros and set the correct values in
'' the WM_SIZE handler.
''
Control( 100, 0, 0, 0, 0, "", 0, TOOLBARCLASSNAME, _
         TBSTYLE_TOOLTIPS Or TBSTYLE_FLAT )

hDlg = CreateModelessDialog( 0, @DialogProc, 0, lpdt )

Do While GetMessage( @wMsg, null, 0, 0 ) <> 0
  If IsDialogMessage( hDlg,  @wMsg ) = 0 Then
    TranslateMessage( @wMsg )
    DispatchMessage( @wMsg )
  End If
Loop

'====================================================================
 