Oxygen Basic

Programming => Problems & Solutions => Topic started by: Aurel on December 22, 2012, 12:56:58 PM

Title: Toolbar problem
Post by: Aurel on December 22, 2012, 12:56:58 PM
I am really puzzled what might be wrong with creating standard toolbar.
Infact toolbar is (so called created) visble but is not leyerd to parent window.
And not respond on xpmanifest at all( i mean on hot tracking).
Button added to toolbar respond on click but styles are messed.
I have try same way in many other compilers /interpreters and in all work properly
so why not work in oxygen  ???

here is function:
Code: [Select]
'toolbar32
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
% TBSTYLES = WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT
  If _tbflag=0
    _tbflag= TBSTYLES | _tbflag
 
  End If
 hTBControl = CreateWindowEx(_ex,"ToolBarWindow32","",_tbflag,_tx,_ty,_tw,_th,_tbhwnd,cID,0,0)
_hfont = GetStockObject(17)
 SendMessage hTBControl,WM_SETFONT,_hfont,0
INT lngStyle=0
'lngStyle = SendMessage hTBControl, TB_GETSTYLE, 0, 0
'lngStyle = lngStyle |  CCS_NODIVIDER | TBSTYLE_TOOLTIPS
'SendMessage hTBControl, TB_SETSTYLE, 0, lngStyle
'UpdateWindow _tbhwnd

Function = hTBControl

End Function
Title: Re: Toolbar problem
Post by: Charles Pegge on December 22, 2012, 02:00:27 PM

I don't really understand manifests, Aurel. Are they patched in as a resource?
Title: Re: Toolbar problem
Post by: Aurel on December 22, 2012, 02:45:47 PM
No.
Is added as separate xml file like
myprog.exe.manifest
Title: Re: Toolbar problem
Post by: Charles Pegge on December 22, 2012, 03:18:14 PM
Does it have to be linked into the exe file as a resource?
Title: Re: Toolbar problem
Post by: Aurel on December 22, 2012, 11:11:36 PM
Charles...
manifest can be added as resource but in my case is external file.
For example in FreeBasic i use example toolbar.bas which is by default without
manifest,ok.
Then i add manifest file toolbar.exe.manifest and everything work as espected
but same program not respond and not work properly in oxygen.
I really dont get it why?
Title: Re: Toolbar problem
Post by: Charles Pegge on December 23, 2012, 03:44:32 AM

Do you normally put the manifest in the same folder as the exe?. You may need to execute your application outside the IDE so it can locate the manifiest.

Charles
Title: Re: Toolbar problem
Post by: Aurel on December 23, 2012, 04:38:46 AM
Quote
Do you normally put the manifest in the same folder as the exe?
Of course Charles i do this.
As i say something is wrong and i can't figured what is  ::)

You have FreeBasic ,right?
Try example toolbar.bas, then add manifest in same folder where is compiled exe
and you will see that manifest work.
I look into many many examples and seems that creating toolbar work fine.

Title: Re: Toolbar problem
Post by: Aurel on December 23, 2012, 10:09:37 AM
Hmm
It looks that toolbar will be real nightmare.
I think before that tabcontrol will be tuff but is piece of cacke
comparing to toolbar.
Title: Re: Toolbar problem
Post by: JRS on December 23, 2012, 02:19:12 PM
I can confirm that the manifest file method of providing the theme doesn't work with my O2 IUP example but does work fine with SB.

Title: Re: Toolbar problem
Post by: Charles Pegge on December 23, 2012, 05:24:06 PM
Could you post the manifest file please. I have downloaded FB .24 and I do not see any manifest file connected with examples/windows/gui/toolbar.


PS: I am modifying Oxygen source code to compile with FB version 0.24 (was 0.21)

Title: Re: Toolbar problem
Post by: JRS on December 23, 2012, 08:38:58 PM
Quote
PS: I am modifying Oxygen source code to compile with FB version 0.24 (was 0.21)

I thought O2 was self compiling at this point.  :'(

Title: Re: Toolbar problem
Post by: Charles Pegge on December 23, 2012, 09:28:16 PM
Not while I am changing the architecture so much. Oxygen would need to be frozen for several months to make that transition. FB actually does a very good job. I use it in a simple procedural way and it is fast and rock solid.

is this the correct manifest to use? for Toolbar?.

Code: [Select]
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">

  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
      <application>
        <!--This Id value indicates the application supports Windows Vista functionality -->
          <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
        <!--This Id value indicates the application supports Windows 7 functionality-->
          <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
      </application>
  </compatibility>

  <assemblyIdentity type="win32"
                    name="myOrganization.myDivision.mySampleApp"
                    version="6.0.0.0"
                    processorArchitecture="x86"
                    publicKeyToken="0000000000000000"
  />
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32"
                        name="Proseware.Research.SampleAssembly"
                        version="6.0.0.0"
                        processorArchitecture="X86"
                        publicKeyToken="0000000000000000"
                        language="*"
      />
    </dependentAssembly>
  </dependency>
</assembly>
Title: Re: Toolbar problem
Post by: JRS on December 23, 2012, 09:44:54 PM
Quote
FB actually does a very good job. I use it in a simple procedural way and it is fast and rock solid.

I'm totally confused why the FreeBASIC group didn't jump all over O2 as their compiler of the future seeing that it was written in FB legacy. Even their author has gone MIA on the development front. Good thing the janitor is still around to cleanup the minor messes users find.

Title: Re: Toolbar problem
Post by: Aurel on December 23, 2012, 10:38:27 PM
Charles ...
It is not problem in manifest ( i use 0.21 to ) ,i just download 0.24 to test Vanya PureBasic like
wrapper.
It is problem in toolbar butttons which must be added in different way then standard button
class "button".
Toolbar buttons need to be defined as array.
Second thing...this buttons must be part of TOOLINFO structure.
That is main problem,so when i would be capable to addbutton i think that then manifest would work.
sorry for confusion...
Title: Re: Toolbar problem
Post by: Aurel on December 24, 2012, 03:14:11 PM
So i tray create TBBUTTON structure.
Code: [Select]
TOOLBAR constants (styles) <<<<<<<<<<<<<<<<<<<<<<<<<<<<
% TBSTYLE_BUTTON = &H0
% TBSTYLE_SEP = &H1
% TBSTYLE_TOOLTIPS = &H100
% TBSTYLE_FLAT = &H800
% TB_ENABLEBUTTON         = (WM_USER + 1)

% TB_ADDBUTTONS = (WM_USER + 20)
% TB_INSERTBUTTON = (WM_USER + 21)
% TB_SETBITMAPSIZE = (WM_USER + 32)
% TB_SETBUTTONWIDTH = (WM_USER + 59)
% TB_SETBUTTONSIZE = (WM_USER + 31)
% TB_SETSTYLE = WM_USER + 56
% TB_GETSTYLE = WM_USER + 57
% TBSTYLE_WRAPABLE = &H200
% CCS_ADJUSTABLE   = &H0000020
% TBSTYLE_LIST = &H1000
% TBSTYLE_BUTTON =&H0
% CCS_NODIVIDER = 0x00000040

% TB_BUTTONSTRUCTSIZE     = (WM_USER + 30)
% TB_ADDBUTTONS           = (WM_USER + 20)
% TB_INSERTBUTTON         = (WM_USER + 21)
% TB_DELETEBUTTON         = (WM_USER + 22)

'tollbar structure..............................
TYPE TBBUTTON
    INT      iBitmap
    INT      idCommand
    BYTE     fsState
    BYTE     fsStyle
    DWORD   dwData
    SYS     iString

END TYPE
and then in main code try fill this :
Code: [Select]
'toolbar control ------------------------------------------------
INT hToolBar
hToolbar = SetToolbar(win,0,0,0,0, 0 , 0 ,tbID)
'----------------------------------------------------------------
'def toolbar array
Dim tbb[3] as TBBUTTON
'add toolbar button
 tbb[0].iBitmap  = 0                'no bitmap
 tbb[0].idCommand = 4            ' toolbar ID
 tbb[0].fsState   = 8 ' tb state
 tbb[0].fsStyle   = TBSTYLE_BUTTON  ' tb style
 tbb[0].dwData    = 0
 tbb[0].iString   = strPtr "New"

SendMessage hToolBar,TB_ADDBUTTONS,1,&tbb
Updatewindow htoolbar

And still nothing...
It looks that something missing..
i suspect on bReserwed[]... ::)
Title: Re: Toolbar problem
Post by: Charles Pegge 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
Title: Re: Toolbar problem
Post by: Aurel 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
Title: Re: Toolbar problem
Post by: Aurel 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()
Title: Re: Toolbar problem
Post by: Aurel 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