Author Topic: Toolbar problem  (Read 5746 times)

0 Members and 2 Guests are viewing this topic.

Charles Pegge

  • Guest
Re: Toolbar problem
« Reply #15 on: December 24, 2012, 09:24:27 PM »
Hi Aurel,

Complicated stuff. The FB original was a bit messy, so I went through it line by line, pulling in all the required definitions.

I got this working in examples/GUI

Code: [Select]


  includepath "../../inc/"
  $SimpleMessageLoop
  $FileName  "t.exe"
  #include   "RTL32.inc"
  #include   "WinUtil.inc"
  MainWindow 320,100,WS_OVERLAPPEDWINDOW

'#case captial

% ICC_BAR_CLASSES =  4

% TBSTYLE_BUTTON          0x0000  // obsolete; use BTNS_BUTTON instead
% TBSTYLE_SEP             0x0001  // obsolete; use BTNS_SEP instead
% TBSTYLE_CHECK           0x0002  // obsolete; use BTNS_CHECK instead
% TBSTYLE_GROUP           0x0004  // obsolete; use BTNS_GROUP instead
% TBSTYLE_CHECKGROUP      (TBSTYLE_GROUP | TBSTYLE_CHECK)     // obsolete; use BTNS_CHECKGROUP instead
% TBSTYLE_DROPDOWN        0x0008  // obsolete; use BTNS_DROPDOWN instead
% TBSTYLE_AUTOSIZE        0x0010  // obsolete; use BTNS_AUTOSIZE instead
% TBSTYLE_NOPREFIX        0x0020  // obsolete; use BTNS_NOPREFIX instead

% TBSTYLE_TOOLTIPS        0x0100
% TBSTYLE_WRAPABLE        0x0200
% TBSTYLE_ALTDRAG         0x0400
% TBSTYLE_FLAT            0x0800
% TBSTYLE_LIST            0x1000
% TBSTYLE_CUSTOMERASE     0x2000
% TBSTYLE_REGISTERDROP    0x4000
% TBSTYLE_TRANSPARENT     0x8000

% HINST_COMMCTRL          -1
% IDB_STD_SMALL_COLOR     0
% IDB_STD_LARGE_COLOR     1
% IDB_VIEW_SMALL_COLOR    4
% IDB_VIEW_LARGE_COLOR    5
% IDB_HIST_SMALL_COLOR    8
% IDB_HIST_LARGE_COLOR    9
% IDB_HIST_NORMAL         12
% IDB_HIST_HOT            13
% IDB_HIST_DISABLED       14
% IDB_HIST_PRESSED        15


% STD_CUT        = 0
% STD_COPY       = 1
% STD_PASTE      = 2
% STD_UNDO       = 3
% STD_REDOW      = 4
% STD_DELETE     = 5
% STD_FILENEW    = 6
% STD_FILEOPEN   = 7
% STD_FILESAVE   = 8
% STD_PRINTPRE   = 9
% STD_PROPERTIES = 10
% STD_HELP       = 11
% STD_FIND       = 12
% STD_REPLACE    = 13
% STD_PRINT      = 14


% TB_ENABLEBUTTON         (WM_USER + 1)
% TB_CHECKBUTTON          (WM_USER + 2)
% TB_PRESSBUTTON          (WM_USER + 3)
% TB_HIDEBUTTON           (WM_USER + 4)
% TB_INDETERMINATE        (WM_USER + 5)
% TB_MARKBUTTON           (WM_USER + 6)
% TB_ISBUTTONENABLED      (WM_USER + 9)
% TB_ISBUTTONCHECKED      (WM_USER + 10)
% TB_ISBUTTONPRESSED      (WM_USER + 11)
% TB_ISBUTTONHIDDEN       (WM_USER + 12)
% TB_ISBUTTONINDETERMINATE (WM_USER + 13)
% TB_ISBUTTONHIGHLIGHTED  (WM_USER + 14)
% TB_SETSTATE             (WM_USER + 17)
% TB_GETSTATE             (WM_USER + 18)
% TB_ADDBITMAP            (WM_USER + 19)
% TB_ADDBUTTONS           (WM_USER + 20)
% TB_INSERTBUTTON         (WM_USER + 21)
% TB_DELETEBUTTON         (WM_USER + 22)
% TB_GETBUTTON            (WM_USER + 23)
% TB_BUTTONCOUNT          (WM_USER + 24)
% TB_COMMANDTOINDEX       (WM_USER + 25)

% TB_BUTTONSTRUCTSIZE     (WM_USER + 30)

% CMB_MASKED              0x02
% TBSTATE_CHECKED         0x01
% TBSTATE_PRESSED         0x02
% TBSTATE_ENABLED         0x04
% TBSTATE_HIDDEN          0x08
% TBSTATE_INDETERMINATE   0x10
% TBSTATE_WRAP            0x20
% TBSTATE_ELLIPSES        0x40
% TBSTATE_MARKED          0x80


% WS_EX_DLGMODALFRAME 1

typedef byte  BYTE
typedef word  WORD
typedef dword DWORD

% _WIN32

typedef struct {
  sys     hInst;
  sys     nID;
} TBADDBITMAP, *LPTBADDBITMAP;

#ifdef _WIN32
 %n 2
#else
 %n 6
#endif

typedef struct {
  int       iBitmap;
  int       idCommand;
  BYTE      fsState;
  BYTE      fsStyle;
  BYTE      bReserved[n];
  sys   dwData;
  sys   iString;
} TBBUTTON, *PTBBUTTON, *LPTBBUTTON;

typedef struct tagINITCOMMONCONTROLSEX {
  DWORD dwSize;
  DWORD dwICC;
} INITCOMMONCONTROLSEXtype, *LPINITCOMMONCONTROLSEX;


declare InitCommonControlsEx lib "ComCtl32.dll" (INITCOMMONCONTROLSEXtype*ic) as sys

indexbase 0

  function WndProc(hWnd, wMsg, wParam,lparam) as sys callback
  ===========================================================
   
  static sys hdc, htools, hInstance

  static tbAddBmp as TBADDBITMAP
  static tbb      as TBBUTTON
  static iccx     as INITCOMMONCONTROLSEXtype


  '' bitmap for each button
  static tbBmp(7) as sys 'as BYTE



  static RECT r

  '==========
  select wMsg
  '==========
       
    case WM_CREATE
    '=============

    SetWindowText hwnd,"ToolBar Demo"
    '
    iccx.dwSize = sizeof( iccx )
    iccx.dwICC  = ICC_BAR_CLASSES
    tbBmp = {STD_FILENEW, STD_FILEOPEN, STD_FILESAVE, STD_CUT, STD_COPY, STD_PASTE }
    hInstance=GetModuleHandle null
    InitCommonControlsEx( iccx )

    % TBSTYLES TBSTYLE_FLAT% or WS_CHILD or WS_VISIBLE

    hTools =
    CreateWindowEx( WS_EX_DLGMODALFRAME, "ToolBarWindow32",
    null,WS_CHILD or WS_VISIBLE or TBSTYLES,
    0, 0, 0, 0, hWnd, null,hInstance, null )
    '
    ' paint toolbar buttons
    '
    if hTools <> null then
      SendMessage( hTools, TB_BUTTONSTRUCTSIZE, sizeof tbb, null )
      tbAddBmp.hInst = HINST_COMMCTRL
      tbAddBmp.nID   = IDB_STD_SMALL_COLOR
      SendMessage( hTools, TB_ADDBITMAP, 0, @tbAddBmp )
      '
      '' apply bitmap to toolbar buttons
      '
      dim i,k as LONG
      for i = 0 to 6
        if i=3 then k=TBSTYLE_SEP else k=TBSTYLE_BUTTON
        with tbb
        .iBitmap   = tbBmp(i)
        .fsState   = TBSTATE_ENABLED
        .fsStyle   = k
        .idCommand = -1
        .dwData    = 0
        end with
        SendMessage( hTools, TB_ADDBUTTONS, 1, @tbb)
      next
    end if


    case WM_DESTROY
    '===============
         
    PostQuitMessage 0
       
 
    case WM_KEYDOWN
    '==============

    if wParam=27 then SendMessage hwnd, WM_CLOSE, 0, 0      'ESCAPE

    case else
    '========
         
    function=DefWindowProc hWnd,wMsg,wParam,lParam
   
    end select
    '
  end function ' WndProc


Charles

X

Aurel

  • Guest
Re: Toolbar problem
« Reply #16 on: December 24, 2012, 11:24:41 PM »
Thank you Charles... ;)
Quote
Complicated stuff.
Yes..i almost think that something is wrong with my computer...grrr... ;D
And like i say i missed bReserved[] .
I will try modify this to awinh.inc...
Interesting thing is that i have found in DLib different way without typedef...

Aurel

Aurel

  • Guest
Re: Toolbar problem
« Reply #17 on: December 27, 2012, 04:34:08 AM »
Yes it works without typedef
Code: [Select]
' in awinh.inc
TYPE TBBUTTON
    INT      iBitmap
    INT      idCommand
    BYTE     fsState
    BYTE     fsStyle
    BYTE     bReserved[2]
    'BYTE     bReserved[1]
    DWORD   dwData
    SYS     iString
END TYPE

TYPE INITCOMMONCONTROLEX
  DWORD dwSize
  DWORD dwICC
END TYPE

TYPE TBADDBITMAP
   INT hInst
   INT nID   
END TYPE

Code: [Select]
'in awinh.inc
Function SetToolbar (byval _tbhwnd as INT,byval _tx as INT,byval _ty as INT,byval _tw as INT,byval _th as INT,byval _tbflag as INT,byval _ex as INT,byval cID as INT) As INT
INT _hfont,foreground
foreground = GetForegroundWindow()
% TBSTYLES = WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT
  If _tbflag=0
    _tbflag= 1342179328 | _tbflag
 
  End If
 hToolbar = CreateWindowEx(_ex,"ToolBarWindow32","",_tbflag,_tx,_ty,_tw,_th,_tbhwnd,cID,0,0)
_hfont = GetStockObject(17)
 SendMessage hToolbar,WM_SETFONT,_hfont,0
SetForegroundWindow(foreground)

Function = hToolbar

End Function

Then inside main program:
Code: [Select]

indexbase 0
'toolbar control
INT hToolBar
INT tbID = 800
INT tbb1 = 801
'create toolbar
hToolbar = SetToolbar (win,0,0,0,0, 0 , 0,tbID)

static tbb as TBBUTTON

with tbb
  .ibitmap  = tbBmp[0]
  .idcommand  = b0ID   
  .fsState   = TBSTATE_ENABLED
  .fsStyle   = TBSTYLE_BUTTON
  .dwData    = 0       
  .iString   = strptr("New")
end with

'important part
SendMessage( hToolbar, TB_BUTTONSTRUCTSIZE, sizeof tbb, NULL )

SendMessage (htoolbar,TB_ADDBUTTONS,1,&tbb)
'set button size
SendMessage hToolBar,TB_SETBUTTONSIZE, 24,24

On this way toolbar button is added and respond on xpmanifest... ;)
In charles example he use method for images one by one
and i will try with image list....
Of course i will try create function AddButton() inside awinh.inc
and SetImageList()

Aurel

  • Guest
Re: Toolbar problem
« Reply #18 on: January 17, 2013, 01:48:29 PM »
After so many mumbo-jumbo and research i found what is important if
you wish build toolbar with your own bitmap images.
Excellent example i have found on Jose Roca site written by Jose :)
This toolbar is created with ImageList().
All files are in attachment...

X