Macro Scheduler's forte is controlling other applications. The dialog image "paste" is accomplished by controlling msPaint. If msPaint is not found the script will fail. If msPaint is already running this script will kill the msPaint.exe process. Whatever work you have done will not be saved. Tests could be added to resolve these issues but I wanted to make the script as basic as possible.
Hope someone finds this useful.
Code: Select all
//Average wait period. If the script fails
//make this number larger and see if it helps.
Let>AveWait=0.4
//Set ctrl + v to be controlled by this macro
OnEvent>key_down,v,2,Paste
//Initialize "paste" limiter flag
Let>ImageFlag=0
//Clean up file if it exists
DeleteFile>%temp_dir%tempclipboardfile.png
//Dialog to paste into
Dialog>Dialog1
object Dialog1: TForm
Caption = 'Press "CTRL + v" to Paste Here'
object MSImage1: tMSImage
Left = 0
Top = 0
end
object MSMemo1: tMSMemo
Left = 0
Top = 0
Width = 800
Height = 600
ScrollBars = ssBoth
Visible = False
end
end
EndDialog>Dialog1
Show>Dialog1,
SRT>Paste
If>ImageFlag=0
GetActiveWindow>ActWinTitle,ActWinX,ActWinY
If>ActWinTitle=Press "CTRL + v" to Paste Here
BlockInput>1
GetClipBoard>ClipBoardData
//If the clipboard contains text this will display it
If>ClipBoardData<>{"ClipBoardData"}
SetDialogProperty>Dialog1,,Caption,Displaying Text
BlockInput>0
SetDialogProperty>Dialog1,MSMemo1,Visible,True
SetDialogProperty>Dialog1,MSMemo1,Text,ClipBoardData
SetDialogProperty>Dialog1,,AutoSize,True
Let>WIN_USEHANDLE=1
ResizeWindow>Dialog1.handle,0,0
Let>WIN_USEHANDLE=0
Goto>EndOfPasteSub
EndIf
//If the clipboard contains an image this will display it using msPaint.
//The script does nothing to check to see if msPaint.exe is unavailable
//or if Paint is already running. Neither of these conditions are good.
SetDialogProperty>Dialog1,,Caption,Displaying Image
Let>ImageFlag=1
Let>RP_Wait=0
Let>RP_Windowmode=0
Run>msPaint.exe
WaitWindowOpen>Paint*
Wait>0.1
GetWindowHandle>Paint*,HndWin
LibFunc>User32,SetParent,SPRes,HndWin,Dialog1.handle
Press ctrl
send>v
Release ctrl
Wait>%AveWait%
Press ctrl
Send>s
Release ctrl
WaitWindowOpen>Save As
GoSub>MakeOpaque,Save As,1
Wait>%AveWait%
Press Tab
Wait>%AveWait%
Send>p
Wait>%AveWait%
Press Shift
Press tab
Release Shift
Wait>%AveWait%
Send>%temp_dir%tempclipboardfile.png
Wait>%AveWait%
Press Enter
Let>PrevFSres=-1
Label>CheckFileComplete
FileSize>%temp_dir%tempclipboardfile.png,FSres
If>FSres=File Not Found
Goto>CheckFileComplete
Else
If>FSres>PrevFSres
Let>PrevFSres=FSres
Wait>%AveWait%
Goto>CheckFileComplete
Else
EndIf
EndIf
SetDialogProperty>Dialog1,msImage1,LoadImage,%temp_dir%tempclipboardfile.png
SetDialogProperty>Dialog1,msImage1,AutoSize,True
SetDialogProperty>Dialog1,,AutoSize,True
Wait>%AveWait%
Let>WIN_USEHANDLE=1
ResizeWindow>Dialog1.handle,0,0
Let>WIN_USEHANDLE=0
//Post process cleanup
KillProcess>mspaint.exe
//If further image processing is taking place
//You may not want to delete this file yet.
'DeleteFile>%temp_dir%tempclipboardfile.png
EndIf
EndIf
BlockInput>0
Label>EndOfPasteSub
END>Paste
//Usage:
//GoSub>MakeOpaque,Window Name,Opacity number (0-255) zero is invisible
//For Example
//GoSub>MakeOpaque,Notepad*,90
SRT>MakeOpaque
If>%MakeOpaque_var_2%=
Let>MakeOpaque_var_2=255
EndIf
If>MakeOpaque_var_1<>
GetWindowHandle>%MakeOpaque_var_1%,HndWin
//constants
Let>GWL_EXSTYLE=-20
Let>WS_EX_LAYERED=524288
Let>LWA_ALPHA=2
//get style attributes of window
LibFunc>user32,GetWindowLongA,attribs,%HndWin%,GWL_EXSTYLE
Let>attribs={%attribs% OR %WS_EX_LAYERED%}
//control window opacity
LibFunc>user32,SetWindowLongA,swl,%HndWin%,GWL_EXSTYLE,attribs
LibFunc>user32,SetLayeredWindowAttributes,res,%HndWin%,0,%MakeOpaque_var_2%,LWA_ALPHA
EndIf
END>MakeOpaque