Posts: 82
Threads: 31
Joined: Oct 2007
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
Posts: 11,926
Threads: 138
Joined: Dec 2002
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.
Posts: 82
Threads: 31
Joined: Oct 2007
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?
Posts: 11,926
Threads: 138
Joined: Dec 2002
Something similar.
Use this to run it.
Macro test dialog as attached toolbar
;/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
;\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
;/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
;/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.
Posts: 82
Threads: 31
Joined: Oct 2007
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!
Posts: 153
Threads: 33
Joined: Aug 2009
Usefull. How would u keep position of dialog relative to the "owner" window?
using timer ?
best regards
Posts: 11,926
Threads: 138
Joined: Dec 2002
Yes, using the same timer.
I updated the code.
Posts: 153
Threads: 33
Joined: Aug 2009
Thank you for updating this! works perfect!
Posts: 153
Threads: 33
Joined: Aug 2009
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
Posts: 11,926
Threads: 138
Joined: Dec 2002
hwndOwner is window.
You can replace
int hwndOwner=TriggerWindow
to
int hwndOwner=win("window name")
Posts: 153
Threads: 33
Joined: Aug 2009
ok great ! didnt think of that
thanks
Posts: 153
Threads: 33
Joined: Aug 2009
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
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?
Posts: 11,926
Threads: 138
Joined: Dec 2002
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.
Posts: 153
Threads: 33
Joined: Aug 2009
yes that's what i wanted to say...
thank you very much!
best regards
Posts: 133
Threads: 15
Joined: Jun 2014
Is it possible to hide the toolbar title?
Posts: 11,926
Threads: 138
Joined: Dec 2002
Open and run dlg_attached. It opens Dialog Editor. Remove style WS_CAPTION and resize dialog.
Posts: 133
Threads: 15
Joined: Jun 2014
It works perfectly!
Thanks a lot.
Posts: 133
Threads: 15
Joined: Jun 2014
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?
Posts: 11,926
Threads: 138
Joined: Dec 2002
Insert this in dlg_attached, above case WM_COMMAND:
,case WM_CONTEXTMENU
,sel ShowMenu("1About[]100Close" hDlg)
,,case 1 mes "About"
,,case 100 clo hDlg
,
Posts: 133
Threads: 15
Joined: Jun 2014
Posts: 133
Threads: 15
Joined: Jun 2014
What if I don't want to show the item text, just to see the icons only?
Posts: 11,926
Threads: 138
Joined: Dec 2002
,DA_InitToolbar id(3 hDlg) "[][][][]" "$qm$\il_qm.bmp" TBSTYLE_FLAT|TBSTYLE_TOOLTIPS|CCS_NODIVIDER
Posts: 133
Threads: 15
Joined: Jun 2014
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?
Posts: 11,926
Threads: 138
Joined: Dec 2002
Updated. Now DA_InitToolbar can create toolbar with tooltips, and also supports Unicode. Use flag 1 with DA_InitToolbar.
Posts: 133
Threads: 15
Joined: Jun 2014
Holy Molly!
You are the man!
Thank you very much for a job well done!
Posts: 133
Threads: 15
Joined: Jun 2014
Is it possible to change the text font, text size and text color of tooltip text?
Posts: 11,926
Threads: 138
Joined: Dec 2002
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.
Posts: 133
Threads: 15
Joined: Jun 2014
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.
Posts: 1,058
Threads: 367
Joined: Oct 2007
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.
Posts: 11,926
Threads: 138
Joined: Dec 2002
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
;\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)
|