Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Controlling Looping Macro from Tray
#1
Dear ALL,

I'm new to quick macros which I bought last week.

My code for monitoring popups windows & closes it automatically:

Code:
Copy      Help
str Icon = "C:\ProgramData\Microsoft\Windows\DeviceMetadataCache\dmrccache\en-US\43345e90-d918-4991-a540-b395c5cf86ff\DeviceInfo\S2240_S2340.ico"
int count = 0
str s = 0
MES m
m.style="YNCn"
m.x=100
m.y=1
m.timeout=1
m.default='C'
Tray t.AddIcon(Icon "0")
rep
    wait 0 WC win("Security Alert")
    int w1=win("Security Alert" "#32770") ;;get window handle
    act w1
    clo w1
    count = count + 1
    s = count
    t.AddIcon(Icon s)

Trying to figure out how to build a macro that monitors open windows (which I have figured out & working), but exiting it with the (complicated) code below so I can control it from the tray ?

Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

if(!ShowDialog("dialog_tray_icon" &dialog_tray_icon 0)) ret

BEGIN DIALOG
0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
2 Button 0x54030000 0x4 120 116 48 14 "Hide"
3 Button 0x54032000 0x0 172 116 48 14 "Exit"
END DIALOG
DIALOG EDITOR: "" 0x2030300 "*" "" ""

ret
messages
sel message
    case WM_INITDIALOG
    Tray-- t_ti
    t_ti.AddIcon("$qm$\copy.ico" "tooltip" 5 hDlg)
     clo hDlg ;;hide
    
    case WM_DESTROY
    t_ti.Delete
    
    case WM_USER+101
    sel lParam
        case WM_LBUTTONUP ;;on left click tray icon
         gShow
        act hDlg; err
        
        case WM_RBUTTONUP ;;on right click tray icon
        sel ShowMenu("1 Show[]2 Exit" hDlg)
            case 1 goto gShow
            case 2 goto gExit
    
    case WM_COMMAND goto messages2
ret
messages2
sel wParam
    case IDCANCEL ;;Hide, X
    min hDlg; hid hDlg; ret
    
    case 3 ;;Exit
     gExit
    DT_Cancel hDlg
ret 1
#2
Exits the rep loop when the tray icon left-clicked. The test window here is a Notepad message box.

Macro Macro274
Code:
Copy      Help
str Icon = "$qm$\paste.ico"
int count = 0
str s = 0
int stop
Tray t.AddIcon(Icon "0" 0 &sub.Callback_Tray_AddIcon)
rep
,0.1
,if(stop) break
,int w1=win("Notepad" "#32770")
,if(w1=0) continue
,clo w1
,count + 1
,s = count
,t.AddIcon(Icon s)


#sub Callback_Tray_AddIcon v
function Tray&x message

;Callback function for Tray.AddIcon.
;Called for each received message - when tray icon clicked, or mouse moved.

;x - reference to this object.
;message - mouse message (WM_MOUSEMOVE, WM_LBUTTONDOWN, etc).


;OutWinMsg message 0 0 ;;uncomment to see received messages

sel message
,case WM_LBUTTONUP
,out "left click"
,;out x.param
,
,;exit the above rep loop
,stop=1
,
,case WM_RBUTTONUP
,out "right click"
,
,case WM_MBUTTONUP
,out "middle click"
,

Or Ctrl+click the tray icon to end the macro. Then don't need all this, just use your first posted macro without changes.
#3
Thank you very much Gintaras Big Grin
#4
Just trying to compile now, but not seeing the icon in the tray:

Code:
Copy      Help
str Icon = "$qm$\paste.ico"
int count = 0
str s = 0
int stop
Tray t.AddIcon(Icon "0" 0 &sub.Callback_Tray_AddIcon)
rep
    0.1
    if(stop) break
    int w1=win("Security Alert" "#32770")
    if(w1=0) continue
    clo w1
    count + 1
    s = count
    t.AddIcon(Icon s)


#sub Callback_Tray_AddIcon v
function Tray&x message

Callback function for Tray.AddIcon.
Called for each received message - when tray icon clicked, or mouse moved.

x - reference to this object.
message - mouse message (WM_MOUSEMOVE, WM_LBUTTONDOWN, etc).


;tOutWinMsg message 0 0 ;;uncomment to see received messages

sel message
    case WM_LBUTTONUP
    out "left click"
     out x.param
    
     exit the above rep loop
    stop=1
    
    case WM_RBUTTONUP
    out "right click"
    
    case WM_MBUTTONUP
    out "middle click"
BEGIN PROJECT
main_function  Outlook Clicker
exe_file  $desktop$\OutlookClicker.exe
icon  $qm$\paste.ico
manifest  $qm$\default.exe.manifest
flags  6
guid  {6781CFBB-32A1-4E99-ACF9-950DC05864EB}
END PROJECT
#5
Probably there is no paste.ico file in exe folder.
$qm$ in exe means "exe folder" not "QM folder".
#6
Ok understood, I copied it to the exe folder & working, but can't you add an option to copy the icon to the exe folder by itself when compiling to exe ?
#7
There are two similar options - macro resources and exe resources. When creating exe, QM adds the files to exe as resouces, instead of copying to exe folder. You can read more in QM help topics "Macro resources" and "Make exe" (read about resources).

To use macro resources:
Open the macro to which you want to add the resource. In the Resources dialog click the Add link and import the icon file.
Then use the resource in macro like

str Icon = "resource:58166 paste.ico"

To use exe resources:
In the "Make exe" dialog check "Auto add files...".
Add a resource id to the file path like this:

str Icon = ":100 $qm$\paste.ico"
#8
Thank you Gintaras - Quick Macros is quite a learning curve to it, but still easy to learn Big Grin


Forum Jump:


Users browsing this thread: 1 Guest(s)