Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Floating toolbar difficulties (toolbars in exe)
#1
I have yet another problem that should be simple to do but can't quite seem to figure out. I've looked at all examples in QM, read the help file and looked through the whole forum and can't seem to figure this out.. I wan't to create a toolbar that attaches itself to a window (which I can do). Then I want the function to carry out many different actions (run program, do a few mouse clicks, type a few keys, etc..) then end, with the toolbar remaining attached to the window. I've tried a hundred different things and I can get it perfect while in QM, but when I try to compile get errors. Or get it so it will compile but runs continuously opening hundreds of the same window. Can anybody post an example for me please? How bout open Notepad, attach a toolbar to it (doesn't matter what the buttons do as I can figure that out), then let's say click or open Format then font, change anything then click ok. I just need to see how this is done and I can figure it out from there. I can't seem to find an example anywhere that does something like this..

Thanks
#2
Quote:I can get it perfect while in QM, but when I try to compile get errors

QM floating toolbars can be used only in QM. Unavailable in exe.
#3
Really? With all the reading I've done you think I would have saw that.. :oops: Is there anything similar I can do that can be compiled?
#4
Something similar.

Use this to run it.
Macro test dialog as attached toolbar
Code:
Copy      Help
;/exe

int w=win("Notepad")
if(!w) run "notepad.exe"; 1; w=win("Notepad")
;w=id(15 w) ;;can attach to controls too

mac "dlg_attached" w

#if EXE
mes "Exit exe."
#endif

Functions:

Function dlg_attached
Code:
Copy      Help
;\test dialog as attached toolbar
;\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

;Dialog that works like a QM toolbar attached to a window.
;Can be used in exe. QM toolbars can't.

;Edit this function: replace strings in the DA_InitToolbar line, add your code under case 1000 etc, edit the siz line.
;Create your imagelist with QM imagelist editor. Look in floating toolbar -> More Tools.
;If want to remove title bar, open this in Dialog Editor and remove style WS_CAPTION.

;To run, use mac() or a window trigger (not in exe). Don't call as function.
;In exe use mac(). The main exe thread must not exit until the toolbar is closed.


int-- hwndOwner=TriggerWindow
;int-- hwndOwner=win("Notepad" "Notepad")
;int-- hwndOwner=id(15 "Notepad")

hDlg=ShowDialog("dlg_attached" &dlg_attached 0 hwndOwner 1)

siz 200 46 hDlg
DA_Attach hDlg hwndOwner 100 0

MessageLoop

;BEGIN DIALOG
;0 "" 0x80C80040 0x8000180 0 0 223 15 "Toolbar"
;3 ToolbarWindow32 0x54010000 0x0 0 0 223 17 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030300 "" "" ""

ret
;messages
sel message
,case WM_INITDIALOG
,;DA_InitToolbar id(3 hDlg) "One[]Two[]Three" "$qm$\il_qm.bmp" TBSTYLE_FLAT|TBSTYLE_LIST|CCS_NODIVIDER ;;buttons with text at the right
,DA_InitToolbar id(3 hDlg) "One[][1]Two[]Three" "$qm$\il_qm.bmp" CCS_NODIVIDER 1 ;;buttons without text, with tooltips. Button "Two" is with text.
,SetTimer hDlg 30 500 0
,
,case WM_TIMER
,sel wParam
,,case 30
,,DA_Attach hDlg hwndOwner 100 0
,
,case WM_DESTROY
,PostQuitMessage 0
,
,case WM_MOUSEACTIVATE
,ret DT_Ret(hDlg MA_NOACTIVATE)
,
,case WM_CONTEXTMENU
,sel ShowMenu("1About[]100Close" hDlg)
,,case 1 mes "About"
,,case 100 clo hDlg
,
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 1000
,out "One" ;;replace these out with run, mac or other code
,case 1001
,out "Two"
,case 1002
,out "Three"
ret 1

Function DA_InitToolbar
Code:
Copy      Help
;/dlg_attached
function htb $buttons $imagelist tbStyle [flags] ;;flags: 1 tooltips instead of text

;Adds toolbar buttons.

;htb - child toolbar control.
;buttons - list of button labels. Multiline.
;imagelist - imagelist bitmap file. Create it with QM imagelist editor. Look in floating toolbar -> More Tools.
;tbStyle - styles to add to the child toolbar control. Documented in MSDN library.
;flags:
;;;1 - don't show button text, instead show a tooltip with the text.
;;;;;;Text can be displayed for some buttons by inserting character code 1 at the beginning of button text. Example: "Text in tooltip[][1]Text on button".
;;;;;;Also adds styles TBSTYLE_LIST|TBSTYLE_TOOLTIPS and sets extended style TBSTYLE_EX_MIXEDBUTTONS.


if(flags&1) tbStyle|TBSTYLE_LIST|TBSTYLE_TOOLTIPS
SetWinStyle htb tbStyle 1

__ImageList-- t_il.Load(imagelist)
SendMessage htb TB_SETIMAGELIST 0 t_il

ARRAY(str) as=buttons
ARRAY(TBBUTTON) a.create(as.len)
int i
for i 0 a.len
,TBBUTTON& t=a[i]
,t.idCommand=1000+i
,t.iBitmap=i
,lpstr s=as[i]; if(s[0]=1) s+1; t.fsStyle|BTNS_SHOWTEXT
,t.iString=SendMessage(htb TB_ADDSTRINGW 0 @_s.fromn(s -1 "" 1)) ;;note: the string must be terminated with two 0
,t.fsState=TBSTATE_ENABLED

SendMessage(htb TB_BUTTONSTRUCTSIZE sizeof(TBBUTTON) 0)
SendMessage(htb TB_ADDBUTTONS a.len &a[0])

if(flags&1) SendMessage(htb TB_SETEXTENDEDSTYLE 0 TBSTYLE_EX_MIXEDBUTTONS)

Function DA_Attach
Code:
Copy      Help
;/dlg_attached
function hDlg hwndOwner x y

;Attaches toolbar to owner window:
;;;If owner closed, closes toolbar.
;;;If owner hidden, hides toolbar.
;;;If owner unhidden, unhides toolbar.
;;;If owner moved, moves toolbar.

;hDlg - toolbar window.
;hwndOwner - owner window.
;x y - toolbar position relative to owner window.


if !IsWindow(hwndOwner)
,clo hDlg
,ret

int h=GetAncestor(hwndOwner 2)

if !IsWindowVisible(h) or (hwndOwner!h and (!IsWindowVisible(hwndOwner) or IsIconic(hwndOwner)))
,if(IsWindowVisible(hDlg)) hid hDlg
else if !IsIconic(h)
,RECT ro rd; GetWindowRect hwndOwner &ro; GetWindowRect hDlg &rd
,x+ro.left; y+ro.top
,if(x!rd.left or y!rd.top) mov x y hDlg
,if(!IsWindowVisible(hDlg))
,,int wp(GetWindow(h GW_HWNDPREV)) fl(SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOOWNERZORDER)
,,if(wp=hDlg) wp=0; fl|SWP_NOZORDER
,,SetWindowPos hDlg wp 0 0 0 0 fl

Edit everything as you need.
#5
I can work with that. Thank you!

..I wonder if this is a challenge for your or if you ever struggle with trying to figure out how to do things like me..

Anyway, thanks again!
#6
Usefull. How would u keep position of dialog relative to the "owner" window?

using timer ?


best regards
#7
Yes, using the same timer.
I updated the code.
#8
Thank you for updating this! works perfect!
#9
Can function DA_Attach be modified so "hwndOwner" can be window or id of window?

i have tried it but cant get it to run without changing too much of your code.

thank you
#10
hwndOwner is window.

You can replace

int hwndOwner=TriggerWindow

to

int hwndOwner=win("window name")
#11
ok great ! didnt think of that

thanks
#12
sorry i didnt explain it claer enough and prolly took ur answer wrong...

my idea was to declare an id of the window as hwndOwner instead the window so it would keep the position even if the window got resized.

i did it like ; (below WM_TIMER)

Macro Macro
Code:
Copy      Help
int hwnd=win("" "Notepad")
RECT r xr rr
GetWindowRect(hwnd &r)
GetWindowRect(id(15 hwnd) &xr)
MoveWindow hDlg .....

i have tried to mix it up with your code but cant get it to work is there a way?
#13
When you say "window or id of window", you probably wanted to say "window or child window". I updated the code (dlg_attached and DA_Attach); now works with child windows too.
#14
yes that's what i wanted to say...

thank you very much!

best regards
#15
Is it possible to hide the toolbar title?
#16
Open and run dlg_attached. It opens Dialog Editor. Remove style WS_CAPTION and resize dialog.
#17
It works perfectly!
Thanks a lot.
#18
I would like to have a right click button to show a popup menu that has a close toolbar option item in it. How could I do that?
#19
Insert this in dlg_attached, above case WM_COMMAND:

Code:
Copy      Help
,case WM_CONTEXTMENU
,sel ShowMenu("1About[]100Close" hDlg)
,,case 1 mes "About"
,,case 100 clo hDlg
,
#20
Fantastic!
Thanks a lot.
#21
What if I don't want to show the item text, just to see the icons only?
#22
,DA_InitToolbar id(3 hDlg) "[][][][]" "$qm$\il_qm.bmp" TBSTYLE_FLAT|TBSTYLE_TOOLTIPS|CCS_NODIVIDER
#23
Wonderful!
Thanks a lot.
By the way, could you make it so that when the mouse pointer points to an icon it will show the tooltip for that icon?
#24
Updated. Now DA_InitToolbar can create toolbar with tooltips, and also supports Unicode. Use flag 1 with DA_InitToolbar.
#25
Holy Molly!
You are the man!
Thank you very much for a job well done!
#26
Is it possible to change the text font, text size and text color of tooltip text?
#27
Toolbar control uses standard tooltips. Something can be changed, eg added an icon, I don't remember. If you need something like tooltips but not attached to toolbar buttons, try function OnScreenDisplay.
#28
I've got it. I know the OnScreenDisplay function, but I just want something to enhance the attached toolbar only. I really happy with its functionalities right now.
#29
Excellent routine !

I would appreciate it if you could advice on the way to pass a parameter (string) to dlg_attached, which it is initiated in main by :

Quote:mac "dlg_attached" w

Many thanks in advance.
#30
Use this version. Everything is the same, just converted to the new dialog format with #sub. Delete the two DA_ functions.
To pass parameters, add parameters in the 'function' line and pass values with mac.

Function dlg_attached
Code:
Copy      Help
;\test dialog as attached toolbar
function

;Dialog that works like a QM toolbar attached to a window.
;Can be used in exe. QM toolbars can't.

;Edit this function: replace strings in the sub.InitToolbar line, add your code under case 1000 etc, edit the siz line.
;Create your imagelist with QM imagelist editor. Look in floating toolbar -> More Tools.
;If want to remove title bar, open this in Dialog Editor and remove style WS_CAPTION.

;To run, use mac() or a window trigger (not in exe). Don't call as function.
;In exe use mac(). The main exe thread must not exit until the toolbar is closed.


int hwndOwner=TriggerWindow
;int hwndOwner=win("Notepad" "Notepad")
;int hwndOwner=id(15 "Notepad")

str dd=
;BEGIN DIALOG
;0 "" 0x80C80040 0x8000180 0 0 223 15 "Toolbar"
;3 ToolbarWindow32 0x54010000 0x0 0 0 223 17 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2030300 "" "" ""

int hDlg=ShowDialog(dd &sub.DlgProc 0 hwndOwner 1)

siz 200 50 hDlg
sub.Attach hDlg hwndOwner 100 0

MessageLoop


#sub DlgProc
function# hDlg message wParam lParam
sel message
,case WM_INITDIALOG
,;sub.InitToolbar id(3 hDlg) "One[]Two[]Three" "$qm$\il_qm.bmp" TBSTYLE_FLAT|TBSTYLE_LIST|CCS_NODIVIDER ;;buttons with text at the right
,sub.InitToolbar id(3 hDlg) "One[][1]Two[]Three" "$qm$\il_qm.bmp" CCS_NODIVIDER 1 ;;buttons without text, with tooltips. Button "Two" is with text.
,SetTimer hDlg 30 500 0
,
,case WM_TIMER
,sel wParam
,,case 30
,,sub.Attach hDlg GetParent(hDlg) 100 0
,
,case WM_DESTROY
,PostQuitMessage 0
,
,case WM_MOUSEACTIVATE
,ret DT_Ret(hDlg MA_NOACTIVATE)
,
,case WM_CONTEXTMENU
,sel ShowMenu("1About[]100Close" hDlg)
,,case 1 mes "About"
,,case 100 clo hDlg
,
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 1000
,out "One" ;;replace these out with run, mac or other code
,case 1001
,out "Two"
,case 1002
,out "Three"
ret 1


#sub Attach
function hDlg hwndOwner x y

;Attaches toolbar to owner window:
;;;If owner closed, closes toolbar.
;;;If owner hidden, hides toolbar.
;;;If owner unhidden, unhides toolbar.
;;;If owner moved, moves toolbar.

;hDlg - toolbar window.
;hwndOwner - owner window.
;x y - toolbar position relative to owner window.


if !IsWindow(hwndOwner)
,clo hDlg
,ret

int h=GetAncestor(hwndOwner 2)

if !IsWindowVisible(h) or (hwndOwner!h and (!IsWindowVisible(hwndOwner) or IsIconic(hwndOwner)))
,if(IsWindowVisible(hDlg)) hid hDlg
else if !IsIconic(h)
,RECT ro rd; GetWindowRect hwndOwner &ro; GetWindowRect hDlg &rd
,x+ro.left; y+ro.top
,if(x!rd.left or y!rd.top) mov x y hDlg
,if(!IsWindowVisible(hDlg))
,,int wp(GetWindow(h GW_HWNDPREV)) fl(SWP_SHOWWINDOW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOOWNERZORDER)
,,if(wp=hDlg) wp=0; fl|SWP_NOZORDER
,,SetWindowPos hDlg wp 0 0 0 0 fl


#sub InitToolbar
function htb $buttons $imagelist tbStyle [flags] ;;flags: 1 tooltips instead of text

;Adds toolbar buttons.

;htb - child toolbar control.
;buttons - list of button labels. Multiline.
;imagelist - imagelist bitmap file. Create it with QM imagelist editor. Look in floating toolbar -> More Tools.
;tbStyle - styles to add to the child toolbar control. Documented in MSDN library.
;flags:
;;;1 - don't show button text, instead show a tooltip with the text.
;;;;;;Text can be displayed for some buttons by inserting character code 1 at the beginning of button text. Example: "Text in tooltip[][1]Text on button".
;;;;;;Also adds styles TBSTYLE_LIST|TBSTYLE_TOOLTIPS and sets extended style TBSTYLE_EX_MIXEDBUTTONS.


if(flags&1) tbStyle|TBSTYLE_LIST|TBSTYLE_TOOLTIPS
SetWinStyle htb tbStyle 1

__ImageList-- t_il.Load(imagelist)
SendMessage htb TB_SETIMAGELIST 0 t_il

ARRAY(str) as=buttons
ARRAY(TBBUTTON) a.create(as.len)
int i
for i 0 a.len
,TBBUTTON& t=a[i]
,t.idCommand=1000+i
,t.iBitmap=i
,lpstr s=as[i]; if(s[0]=1) s+1; t.fsStyle|BTNS_SHOWTEXT
,t.iString=SendMessage(htb TB_ADDSTRINGW 0 @_s.fromn(s -1 "" 1)) ;;note: the string must be terminated with two 0
,t.fsState=TBSTATE_ENABLED

SendMessage(htb TB_BUTTONSTRUCTSIZE sizeof(TBBUTTON) 0)
SendMessage(htb TB_ADDBUTTONS a.len &a[0])

if(flags&1) SendMessage(htb TB_SETEXTENDEDSTYLE 0 TBSTYLE_EX_MIXEDBUTTONS)


Forum Jump:


Users browsing this thread: 1 Guest(s)