News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

toolbar

Started by Slugsnack, July 20, 2009, 09:37:57 PM

Previous topic - Next topic

Slugsnack

hi

i'm using resed to make my GUI as usual but this time i'm trying to make a toolbar. is it possible to add them in the resource file ? and if so how can i do so in resed ? otherwise do i have to do it at runtime ?

fearless

This is a sample from a project i was working on for a toolbar. I have a graphic that is a strip of images which has each image as 48x32 in size. In my dialog i add a ToolBar item and define it in my .inc file as IDC_MAINTOOLBAR. In my resource of my project i add the graphic and define it as IDC_MAINTOOLBAR_BMP48x32   equ 2104. Then all i do is add call to InitToolBar in WM_INITDIALOG and it handles the rest

In CONST section this is defined:
IDC_MAINTOOLBAR equ 2001
IDC_MAINTOOLBAR_BMP48x32 equ 2104


In WM_INITDIALOG place a call to:
Invoke InitToolBar, hWin, 48, 32, IDC_MAINTOOLBAR_BMP48x32

In main window handler WM_COMMAND part you check for the defined buttons as shown in the ToolBar.asm
; Toolbar IDs
TB_NEW equ 50
TB_OPEN equ 51
TB_ADD equ 52
TB_EXTRACT equ 53
TB_VIEW equ 54
TB_INFO equ 55
TB_EXIT equ 56
TB_HELP equ 57


and to show tooltips i call this under the WM_NOTIFY part:

.elseif eax==WM_NOTIFY

; Tooltips from string table for toolbar buttons
Invoke ToolBarTips, lParam


Not sure if that will help you are not. Hopefully it does.

[attachment deleted by admin]
ƒearless

Slugsnack

thanks for that i think it's helpful even though i am adding mine one at a time. also do you know whether there is any 'standard' size the images should be in a toolbar ?

fearless

The standard size is whatever you define the image as. So in the attached example if i have a strip of images with each image being 48x32. In my project i have other sizes, so i could play around and see what looks the best. If you want small images 16x16 or 32x32 would do. Larger images could be 48x32, 48x48 or 64x64 for example.
ƒearless

donkey

The default size for a toolbar button is 24x22 pixels, the default size for a toolbar graphic is 16x16. Generally it is recommended that you include at least 16x16 graphics but you can also include a "large" buttons one that can be any size you like.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Slugsnack

just got round to working on this for about half an hour but having a bit of a problem..

it seems the call to sendmessage :

invoke SendMessage, hToolbar, TB_ADDBITMAP, 5, addr TBABStruct

is failing with invalid handle. no clue why since that same handle is used in the call just before it which works fine..

would love some help, otherwise i'll work on it tomorrow night ( having a job sucks when you have personal projects you want to do ! )

[attachment deleted by admin]

fearless

Replace:
invoke CreateMappedBitmap, hInstance, BMP_TBR, 0, NULL, 0
With:
Invoke LoadBitmap,hInstance,BitmapID ; Load bitmap from Resource ID of Bitmap
And add to your code:
invoke SendMessage, hToolbar, TB_BUTTONSTRUCTSIZE, sizeof TBBUTTON, 0 ; Set toolbar struct size
And after calculations of size, maybe store result in a var called bSize, and add:
mov ecx, nButtonX
mov eax, nButtonY
mov ToolbarHeight, eax
shl eax, 16
mov ax, cx
mov bSize, eax
invoke SendMessage, hToolbar, TB_SETBITMAPSIZE, 0, bSize ; Set bitmap size
invoke SendMessage, hToolbar, TB_SETBUTTONSIZE, 0, bSize


Hope that helps

[attachment deleted by admin]
ƒearless

Slugsnack

#7
omg i'm so stupid. it was a simple typo. you see where i had the first TB_SETBITMAPSIZE call.. it was supposed to be a TB_BUTTONSTRUCTSIZE. just had to change that then it worked fine

thanks bro

btw i stayed using createmappedbitmap since loadbitmap has been superseded by loadimage

thanks for all your help : )

gonna try to get it so the text is displayed now

mov tbab.fsStyle, TBSTYLE_BUTTON OR BTNS_SHOWTEXT OR TBSTYLE_EX_MIXEDBUTTONS

tried that and also changed the resource file so the toolbar control has TBSTYLE_FLAT but text is still not displaying. gonna keep trying..

had to edit resource.h to have TBSTYLE_FLAT o_O

//edit : works, had to add TBSTYLE_LIST to resource.h : )

//edit : no WM_COMMAND messages seems to be being sent when i select a button on the toolbar.. time to investigate ; )

Slugsnack

tried to use a different method but failed miserably..

check this out ; )

ps. i still have no idea why wm_command is not sent whenever i click a button on the method that i sort of ripped from yours

[attachment deleted by admin]

fearless

I tried with the attached project, but it kept crashing after the LoadToolbar proc, it would reach the end of it fine but for some reason would cause an exception. I pasted the original LoadToolbar function you had in the first toolbar project into this project and ran it, it worked fine. All you need to do is then check under WM_COMMAND for the TB_PING, TB_TRACE, TB_TELNET, TB_SSH and TB_RDC and then call whatever function required for each of these items, probably a seperate procedure for each button would be the handiest way to structure your program.
ƒearless

Slugsnack

i did find the reason for the crash. looks like a corrupt stack. it changes the ret address to 1. maybe a messed up function prototype ? will check that out later with some more debugging. simple way, just check at what point after a call the ret address is not the right one

but there is a more immediate problem. namely, that last call to sendmessage to add the buttons is returning false with invalid window handle if i remember correctly

btw with your method when i checked for WM_COMMAND it was sent to the window proc o_O i even used spy++ to hook the wndproc to read off all messages sent to that window. definitely no WM_COMMAND when toolbar buttons were clicked

will investigate more when i get home

Slugsnack

i did fix it in the end, turned out i had made a small typo which was why it wasn't working, will upload a screenshot later today : )

Slugsnack

pew pew pew



thanks ; )

Slugsnack

hmm 2 quick questions..



as you can see there are 2 problems there. first of all the toolbar has not resized itself when its parent window resizes. second problem is that the child windows of the main control are appearing under the toolbar. i have solutions to both problems already but wanted to see if there are 'better' solutions.

solution to toolbar resize problem is to handle WM_SIZE of the main window then set the size of the toolbar.. solution to the other problem is that at WM_INITDIALOG and WM_SIZE to change the client area to go down by the height of the toolbar..

just wanted to check there is no better way : |

dedndave

still, very cool - you'll get the bugs worked out