NO

Author Topic: Toolbar  (Read 1771 times)

Grincheux

  • Guest
Toolbar
« on: May 09, 2021, 10:54:44 AM »
I try to set an toolbar with images in 24/32 bits.
The toolbar is well displayed except for the colors, they are in 16 colors mode!
I have taken others bitmaps that give good results an other programs, nothing change.
I am requesting for some help.

Offline John Z

  • Member
  • *
  • Posts: 790
Re: Toolbar
« Reply #1 on: May 09, 2021, 12:09:21 PM »
I had a similar issue.  Here is how I solved it in PellesC

this made 16 color toolbar
Code: [Select]
  himl = ImageList_LoadBitmap(tbab.hInst, MAKEINTRESOURCE(TB_Pict1), 32, 0, RGB(255,0,255));
this made 256 color toolbar
Code: [Select]
  himl = ImageList_LoadImage(tbab.hInst,MAKEINTRESOURCE(TB_Pict1),32,0,RGB(255,0,255 ),IMAGE_BITMAP,LR_CREATEDIBSECTION);
Cavet:  I have not looked at your code yet -


John Z

Update: downloaded, Hmmm - looks like you are doing it as above, I'll need to look further ….

Update 2: can you try using ToolBar_SetImageList(hToolbar, himl); rather than the SendMessage? It's the only thing I see right off that is different.  (but I've not looked at assembly for a long time)

Update 3: Try creating the toolbar without the extended version.  The extended version calls TB_ADDBITMAP internally  According to M$
Quote
Attempting to modify it with TB_SETIMAGELIST has unpredictable consequences.
Then you might use the suggestion in update 2...
« Last Edit: May 09, 2021, 01:11:36 PM by John Z »

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: Toolbar
« Reply #2 on: May 09, 2021, 05:20:41 PM »
I tried to check your code, but I haven't too much time to follow the assembler flow, so I made a quick&dirty example that you can find attached.
For me it works well, Your problem can be due to wrong header definitions, or whatever related. Try to implement a simple window that loads the toolbar, as my example, in assembler and work it out to find the problem.
I also have seen that you call InitControls() and InitControlsEx() in a row, this is not correct. I tried to comment out them one at time, but no luck.
Good luck to you.
« Last Edit: May 09, 2021, 11:29:56 PM by frankie »
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

Grincheux

  • Guest
Re: Toolbar
« Reply #3 on: May 09, 2021, 08:33:41 PM »
Thank You John & Frankie,
I applied all your advices, no success.
I wrote a C function and now... it's worst!

Code: [Select]
MYTBBUTTON      tbButtons[23]   =   {
                              { 0,IDM_ACTION_FILTERS,   TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,0,IDS_ACTION_FILTERS},
                              {10,IDM_ACTION_FIND,   TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,1,IDS_ACTION_FIND},
                              { 7,IDM_ACTION_REFRESH,   TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,2,IDS_ACTION_REFRESH},
                              { 9,IDM_ACTION_SAVE,   TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,3,IDS_ACTION_SAVE},
                              { 0,0,               0,            TBSTYLE_SEP               ,0,0},
                              { 1,IDM_WINDOW_VIEW,   TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,4,IDS_WINDOW_VIEW},
                              { 6,IDM_WINDOW_DUMP,   TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,4,IDS_WINDOW_DUMP},
                              {14,IDM_WINDOW_DSM,      TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,4,IDS_WINDOW_DSM},
                              { 0,0,               0,            TBSTYLE_SEP               ,0,0},
                              { 5,IDM_FUNCTIONS_EXPORT,TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,5,IDS_FUNCTIONS_EXPORT},
                              { 4,IDM_FUNCTIONS_IMPORT,TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,6,IDS_FUNCTIONS_IMPORT},
                              { 0,0,               0                                 ,TBSTYLE_SEP,0,0},
                              {12,IDM_HOOK_AFTER,      TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,7,IDS_HOOK_AFTER},
                              {11,IDM_HOOK_BEFORE,   TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,8,IDS_HOOK_BEFORE},
                              { 0,0,               0,            TBSTYLE_SEP               ,0,0},
                              { 2,IDM_HOOK_FUNCTIONS,   TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,9,IDS_HOOK_FUNCTIONS},
                              { 3,IDM_HOOK_MESSAGES,   TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,10,IDS_HOOK_MESSAGES},
                              { 0,0,               0,            TBSTYLE_SEP               ,0,0},
                              { 8,IDM_ACTION_SETTINGS,TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,11,IDS_ACTION_SETTINGS},
                              { 0,0,               0,            TBSTYLE_SEP               ,0,0},
                              {13,IDM_PGM_ABOUT,      TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,12,IDS_PGM_ABOUT},
                              { 0,0,               0,            TBSTYLE_SEP               ,0,0},
                              {15,IDM_PGM_EXIT,      TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,13,IDS_PGM_EXIT},
                           } ;

TBADDBITMAP      TbAddBitmap      =   {NULL,IDB_TOOLBAR} ;

//   __________________________________________________________________________________
//   _______________________ CreateSimpleToolbar ______________________________________
//   __________________________________________________________________________________


void CreateSimpleToolbar(HWND hParent)
{
   hToolbar = CreateWindowEx(0,TOOLBARCLASSNAME,NULL,WS_CHILD,0,0,500,500,hParent,(HMENU) IDC_TOOLBAR_01,hInstance,NULL) ;

   TbAddBitmap.hInst = hInstance ;

   SendMessage(hToolbar,TB_BUTTONSTRUCTSIZE,(WPARAM) sizeof(TBBUTTON),0) ;
   SendMessage(hToolbar,TB_SETBITMAPSIZE,0,MAKELONG(32,32)) ;
   SendMessage(hToolbar,TB_SETBUTTONSIZE,0,MAKELONG(34,34)) ;
   SendMessage(hToolbar,TB_SETEXTENDEDSTYLE,0,(LPARAM) TBSTYLE_EX_DOUBLEBUFFER) ;
   SendMessage(hToolbar,TB_ADDBITMAP,NUMBER_OF_ICONS,(LPARAM) &TbAddBitmap) ;
   SendMessage(hToolbar,TB_ADDBUTTONS,NUMBER_OF_BUTTONS,(LPARAM) (LPTBBUTTON) tbButtons) ;
   SendMessage(hToolbar,TB_AUTOSIZE,0,0) ;

   return ;
}
TB_ADDBITMAP crashes!

If I don't find a solution, I will remove it.

Grincheux

  • Guest
Re: Toolbar
« Reply #4 on: May 09, 2021, 08:42:28 PM »
I have re-installed Pelle's C Compiler
I have launched ADWCLEANER, WISECARE365, CCLEANER and ADWARE !
Nothing !


What is there?

Offline John Z

  • Member
  • *
  • Posts: 790
Re: Toolbar
« Reply #5 on: May 09, 2021, 09:00:30 PM »
I'll try your ASM code later but for now here is C code that I know works. It is directly out of my vCardz_i program.
 
Code: [Select]
//-----------------------------------------------------------------------
// Function : FillToolbar
// Task     : Load the toolbarimages
// Returns : nothing
// Input:
// hWndDlg : Handle to main
// iCtl : control id (could eb fixed in ths case..
//-----------------------------------------------------------------------
void FillToolbar(HWND hWndDlg, int iCtl)
{
 TBADDBITMAP tbab;
 ZeroMemory(&tbab, sizeof(TBADDBITMAP));

 HIMAGELIST himl;

TBBUTTON tbb[] = {
{TD_FILEOPEN, ID_MF_FILE, TBSTATE_ENABLED, (BYTE)(TBSTYLE_BUTTON|TBSTYLE_TOOLTIPS|TBSTYLE_TRANSPARENT) , {0}, 0L, (INT_PTR)L"Open a File"},
{TD_DIROPEN, ID_MFILE, TBSTATE_ENABLED, (BYTE)(TBSTYLE_BUTTON|TBSTYLE_TOOLTIPS |TBSTYLE_TRANSPARENT) , {0}, 0L, (INT_PTR) L"Load a Directory"},
{TD_FILESAVE, ID_MF_SAVEAS, TBSTATE_ENABLED, (BYTE)(TBSTYLE_BUTTON|TBSTYLE_TOOLTIPS| TBSTYLE_TRANSPARENT) , {0}, 0L, (INT_PTR)L"SaveAs"},
{0, 0, 0, TBSTYLE_SEP},
{TD_PRINT, ID_MF_PRINT, TBSTATE_ENABLED, (BYTE)(TBSTYLE_BUTTON|TBSTYLE_TOOLTIPS), {0}, 0L, (INT_PTR)L"Print Address"},
{TD_CLIPCOPY, ID_ME_COPY, TBSTATE_ENABLED, (BYTE)(TBSTYLE_BUTTON|TBSTYLE_TOOLTIPS), {0}, 0L, (INT_PTR)L"Address to Clipboard"},
{0, 0, 0, TBSTYLE_SEP},
{TD_PASTE, ID_ME_PASTE, TBSTATE_ENABLED, (BYTE)(TBSTYLE_BUTTON|TBSTYLE_TOOLTIPS|TBSTYLE_TRANSPARENT), {0}, 0L, (INT_PTR)L"Copy to New"},
{0, 0, 0, TBSTYLE_SEP},
{TD_HELP, ID_CS_F1_Help, TBSTATE_ENABLED, (BYTE)(TBSTYLE_BUTTON|TBSTYLE_TOOLTIPS), {0}, 0L, (INT_PTR)L"Context Help"},
{0, 0, 0, TBSTYLE_SEP},
{0, 0, 0, TBSTYLE_SEP},
{0, 0, 0, TBSTYLE_SEP},
{TD_PREV, ID_MV_PREVIOUS, TBSTATE_ENABLED, (BYTE)(TBSTYLE_BUTTON|TBSTYLE_TOOLTIPS), {0}, 0L, (INT_PTR)L"Prior card in a multicard file (Ctrl-L)"},
{TD_NEXT, ID_MV_NEXT, TBSTATE_ENABLED, (BYTE)(TBSTYLE_BUTTON|TBSTYLE_TOOLTIPS), {0}, 0L, (INT_PTR)L"Next card in a multicard file (Ctrl-U)"},
{0, 0, 0, TBSTYLE_SEP},
{TD_EXTRACT, ID_MF_EXTRACT, TBSTATE_ENABLED, (BYTE)(TBSTYLE_BUTTON|TBSTYLE_TOOLTIPS), {0}, 0L, (INT_PTR)L"Extract this card to a new file"},
{0, 0, 0, TBSTYLE_SEP},
{TD_SEARCH, ID_MV_SEARCH, TBSTATE_ENABLED, (BYTE)(TBSTYLE_BUTTON|TBSTYLE_TOOLTIPS), {0}, 0L, (INT_PTR)L"Search"},
{0, 0, 0, TBSTYLE_SEP},
{TD_EXITED, ID_ME_EXIT, TBSTATE_ENABLED, (BYTE)(TBSTYLE_BUTTON|TBSTYLE_TOOLTIPS), {0}, 0L, (INT_PTR)L"Exit Edit"},
};

    HWND hToolbar = GetDlgItem(hWndDlg, iCtl);
if (hToolbar)
{ghToolBar = (HWND)hToolbar;
         tbab.hInst = (HINSTANCE)GetWindowLong(hToolbar, GWL_HINSTANCE);
// need to change to the following to all >256 colors
if (StartUp.NewToolBar == 0)
          {himl = ImageList_LoadImage(tbab.hInst,MAKEINTRESOURCE(TB_Pict1),32,0,RGB(255,0,255 ),IMAGE_BITMAP,LR_CREATEDIBSECTION);}
else
          {himl = ImageList_LoadImage(tbab.hInst,MAKEINTRESOURCE(TB_Pict2),32,0,RGB(255,0,255 ),IMAGE_BITMAP,LR_CREATEDIBSECTION);}
         ToolBar_SetImageList(hToolbar, himl);
SendMessage(hToolbar, TB_ADDBUTTONS, (WPARAM)NELEMS(tbb), (LPARAM)&tbb);
SendMessage(hToolbar, TB_SETMAXTEXTROWS, 0, 0);//for tips
    }
else
{/*need error trap action */
  MessageBoxA(gHWND,"No toolbar created", "Win Main",MB_ICONERROR);
}

     // Set the initial toolbar button states for those hidden
   SendMessage(ghToolBar, TB_HIDEBUTTON, ID_MV_PREVIOUS, TRUE);
   SendMessage(ghToolBar, TB_HIDEBUTTON, ID_MV_NEXT, TRUE);
   SendMessage(ghToolBar, TB_HIDEBUTTON, ID_MF_EXTRACT, TRUE);
   SendMessage(ghToolBar, TB_HIDEBUTTON, ID_MV_SEARCH, TRUE);
   SendMessage(ghToolBar, TB_HIDEBUTTON, ID_ME_EXIT, TRUE);

// TB_HIDEBUTTON TB_SETSTATE
    // here is how to change bitmap used on toolbar button
    // SetToolbarImage(hToolbar,ID_MV_PREVIOUS,9);


}/* end filltoolbar */

The most difficult to find error is usually the most obvious -
Quote
Galileo Galilei Quotes
All truths are easy to understand once they are discovered; the point is to discover them.


John Z

Grincheux

  • Guest
Re: Toolbar
« Reply #6 on: May 09, 2021, 10:13:18 PM »
Code: [Select]
   hImageList = ImageList_LoadImage(hInstance,MAKEINTRESOURCE(IDB_TOOLBAR),NUMBER_OF_ICONS,1,CLR_DEFAULT,IMAGE_BITMAP,LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADTRANSPARENT) ;
   SendMessage(hToolbar,TB_SETIMAGELIST,0,(LPARAM) hImageList) ;


TB_SETIMAGELIST fails
GetLastError returns 6 (Bad Handle)
ERROR_INVALID_HANDLE[/size]6 (0x6)The handle is invalid.[/color]
« Last Edit: May 09, 2021, 10:17:21 PM by Grincheux »

Grincheux

  • Guest
Re: Toolbar
« Reply #7 on: May 09, 2021, 10:57:37 PM »
NOW IT IS GOOD

Here is my code
Code: [Select]
extern   HINSTANCE   hInstance ;

#define   NUMBER_OF_ICONS      16
#define   NUMBER_OF_BUTTONS   23

typedef   unsigned long long QWORD ;

HWND         hToolbar ;
HIMAGELIST      hImageList ;

typedef struct _MYTBBUTTON
{
   int      iBitmap ;
   int      idCommand ;
   BYTE   fsState ;
   BYTE   fsStyle ;
   BYTE   bReserved[2] ;
   QWORD   dwData ;
   QWORD   dwString ;
} MYTBBUTTON, *LPMYTBBUTTON ;

MYTBBUTTON      tbButtons[23]   =   {
                              { 0,IDM_ACTION_FILTERS,   TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,0,IDS_ACTION_FILTERS},
                              {10,IDM_ACTION_FIND,   TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,1,IDS_ACTION_FIND},
                              { 7,IDM_ACTION_REFRESH,   TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,2,IDS_ACTION_REFRESH},
                              { 9,IDM_ACTION_SAVE,   TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,3,IDS_ACTION_SAVE},
                              { 0,0,               0,            TBSTYLE_SEP               ,0,0},
                              { 1,IDM_WINDOW_VIEW,   TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,4,IDS_WINDOW_VIEW},
                              { 6,IDM_WINDOW_DUMP,   TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,4,IDS_WINDOW_DUMP},
                              {14,IDM_WINDOW_DSM,      TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,4,IDS_WINDOW_DSM},
                              { 0,0,               0,            TBSTYLE_SEP               ,0,0},
                              { 5,IDM_FUNCTIONS_EXPORT,TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,5,IDS_FUNCTIONS_EXPORT},
                              { 4,IDM_FUNCTIONS_IMPORT,TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,6,IDS_FUNCTIONS_IMPORT},
                              { 0,0,               0                                 ,TBSTYLE_SEP,0,0},
                              {12,IDM_HOOK_AFTER,      TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,7,IDS_HOOK_AFTER},
                              {11,IDM_HOOK_BEFORE,   TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,8,IDS_HOOK_BEFORE},
                              { 0,0,               0,            TBSTYLE_SEP               ,0,0},
                              { 2,IDM_HOOK_FUNCTIONS,   TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,9,IDS_HOOK_FUNCTIONS},
                              { 3,IDM_HOOK_MESSAGES,   TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,10,IDS_HOOK_MESSAGES},
                              { 0,0,               0,            TBSTYLE_SEP               ,0,0},
                              { 8,IDM_ACTION_SETTINGS,TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,11,IDS_ACTION_SETTINGS},
                              { 0,0,               0,            TBSTYLE_SEP               ,0,0},
                              {13,IDM_PGM_ABOUT,      TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,12,IDS_PGM_ABOUT},
                              { 0,0,               0,            TBSTYLE_SEP               ,0,0},
                              {15,IDM_PGM_EXIT,      TBSTATE_ENABLED,BTNS_AUTOSIZE|TBSTYLE_BUTTON,0,0,13,IDS_PGM_EXIT},
                           } ;

TBADDBITMAP      TbAddBitmap      =   {NULL,IDB_TOOLBAR} ;

//   __________________________________________________________________________________
//   _______________________ CreateSimpleToolbar ______________________________________
//   __________________________________________________________________________________

void CreateSimpleToolbar(HWND hParent)
{
   hToolbar = CreateWindowEx(0,TOOLBARCLASSNAME,NULL,WS_CHILD|WS_VISIBLE|TBSTYLE_FLAT|TBSTYLE_TOOLTIPS|TBSTYLE_TRANSPARENT|TBSTYLE_WRAPABLE,0,0,500,500,hParent,(HMENU) IDC_TOOLBAR_01,hInstance,NULL) ;

   TbAddBitmap.hInst = hInstance ;

   SendMessage(hToolbar,TB_SETBITMAPSIZE,0,MAKELONG(32,32)) ;
   SendMessage(hToolbar,TB_SETBUTTONSIZE,0,MAKELONG(34,34)) ;
   SendMessage(hToolbar,TB_SETEXTENDEDSTYLE,0,(LPARAM) TBSTYLE_EX_DOUBLEBUFFER) ;
   hImageList = ImageList_LoadImage(hInstance,MAKEINTRESOURCE(IDB_TOOLBAR),32,1,CLR_DEFAULT,IMAGE_BITMAP,LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADTRANSPARENT) ;
   SendMessage(hToolbar,TB_SETIMAGELIST,1,(LPARAM) hImageList) ;
   SendMessage(hToolbar,TB_BUTTONSTRUCTSIZE,(WPARAM) sizeof(TBBUTTON),0) ;
   SendMessage(hToolbar,TB_ADDBUTTONS,NUMBER_OF_BUTTONS,(LPARAM) (LPTBBUTTON) tbButtons) ;
   SendMessage(hToolbar,TB_AUTOSIZE,0,0) ;

   return ;
}

The problem was made by the toolbar styles in the CreateWindowEx.

Thank You for your help.
Merci

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: Toolbar
« Reply #8 on: May 09, 2021, 11:01:28 PM »
I found an error in "Win_Structures.inc":
Code: [Select]
TBBUTTON STRUCT
iBitmap DWORD ?
idCommand DWORD ?
fsState BYTE ?
fsStyle BYTE ?
bReserved BYTE 6 dup(?)
dwData QWORD ?
; iString DWORD ?  ;This is wrong iString is defined as INT_PTR
iString QWORD ?
TBBUTTON ENDS

C definition:
Code: [Select]
typedef struct _TBBUTTON {
    int iBitmap;
    int idCommand;
    BYTE fsState;
    BYTE fsStyle;
#ifdef _WIN64
    BYTE bReserved[6];
#elif defined(_WIN32)
    BYTE bReserved[2];
#endif
    DWORD_PTR dwData;
    INT_PTR iString;
} TBBUTTON, NEAR* PTBBUTTON, *LPTBBUTTON;

I fixed it, but still don't work, but I suspect that there are other errors like this. Maybe someone is also the reason of your crash.
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

Grincheux

  • Guest
Re: Toolbar
« Reply #9 on: May 10, 2021, 04:05:57 AM »
Yes I have seen.
I have corrected bugs where I initialized R8D and R9D rather than R8 and R9.
I don't explain that in changing styles that solves the problem!
Thank You

Offline John Z

  • Member
  • *
  • Posts: 790
Re: Toolbar
« Reply #10 on: May 11, 2021, 02:44:52 PM »

I found an error in "Win_Structures.inc":

Good catch Frankie!

John Z