Use Ctrl + v to Paste to Your Dialog

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Use Ctrl + v to Paste to Your Dialog

Post by JRL » Fri Dec 28, 2012 5:26 am

I've been looking for a method to paste an image to a dialog. This seems to work both in WinXP and Win7. Copy an image to the clipboard then start this script. Press ctrl + v and the image should soon appear in the dialog. If the clipboard contains text there is a method included to paste that to the dialog also. If the clipboard contains nothing or a file there will likely be a plain white box that appears in the dialog.

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

daa5417
Newbie
Posts: 10
Joined: Sun Dec 30, 2012 3:56 am
Location: New Orleans, LA

Macro Scheduler Beginner

Post by daa5417 » Sun Dec 30, 2012 4:00 am

At my job, sometimes we have to change a large amount of images because they don't work well with the 3D program we're using. It's easy to do it manually when it's 5-10 images, but when there's 30 or more images, it can be time consuming.

I want to write a macro where it looks in a folder, opens the images (one by one, I suppose) in MS Paint, goes to Save As, and saves the files as it's original name, but adds ".jpeg" to the end of it.

Can you help me with that?
D. Anderson

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Dec 31, 2012 3:39 am

Probably can help. What is the original file type?

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Mon Dec 31, 2012 3:46 am

What About IrfanView Batch Convert / Rename.

It Could Easily Be Done, Just Let Us Know What You Need.
FIREFIGHTER

daa5417
Newbie
Posts: 10
Joined: Sun Dec 30, 2012 3:56 am
Location: New Orleans, LA

Post by daa5417 » Mon Dec 31, 2012 5:12 am

JRL wrote:Probably can help. What is the original file type?

The original file type is usually .jpg. When you go into Windows Explorer, and change it to .jpeg, they does not fix the problem. And just re-saving it in Paint doesn't work. It has to be opened in Paint and add the .jpeg extension to it.
D. Anderson

daa5417
Newbie
Posts: 10
Joined: Sun Dec 30, 2012 3:56 am
Location: New Orleans, LA

Post by daa5417 » Mon Dec 31, 2012 5:14 am

CyberCitizen wrote:What About IrfanView Batch Convert / Rename.

It Could Easily Be Done, Just Let Us Know What You Need.
I've tried IrfanView to no avail. I don't know if there's a way to batch rename that reproduces what happens when you open it in Paint, but just adding the .jpeg extension in IrfranView doesn't work.
D. Anderson

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Mon Dec 31, 2012 6:10 am

I don't think there is anything fancy with the file name. I think the program is looking for a jpg image in a certain format, eg where are these images coming from.

http://www.pcreview.co.uk/forums/differ ... 42018.html

It looks like paint is just saving it to a proper image format.

What happens if you rename the file in explorer to jpeg then open in paint, then go file save as and save it with the jpg extension does that work? If so it might be the source of where you are getting these images are not saving them correctly.
FIREFIGHTER

daa5417
Newbie
Posts: 10
Joined: Sun Dec 30, 2012 3:56 am
Location: New Orleans, LA

Post by daa5417 » Mon Dec 31, 2012 6:13 am

CyberCitizen wrote:I don't think there is anything fancy with the file name. I think the program is looking for a jpg image in a certain format, eg where are these images coming from.

http://www.pcreview.co.uk/forums/differ ... 42018.html

It looks like paint is just saving it to a proper image format.

What happens if you rename the file in explorer to jpeg then open in paint, then go file save as and save it with the jpg extension does that work? If so it might be the source of where you are getting these images are not saving them correctly.
I know all about the differences and what not. I just need a way to rename them quickly. And yes the source is the problem, but at my job we fix them, so the source doesn't really matter.

Renaming it in the explorer and then opening it in Paint would be kind of backwards. It's not a better process than the current one.

I'm not trying to figure out what's wrong. I just want to write a macro that does what I explained in my original post.
D. Anderson

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Mon Dec 31, 2012 6:21 am

daa5417 wrote:at my job we fix them, so the source doesn't really matter.
Same
daa5417 wrote:Renaming it in the explorer and then opening it in Paint would be kind of backwards. It's not a better process than the current one.
This was purely to see if it needs to be a *.jpeg extension or if its just a way of telling mspaint to update the image.
daa5417 wrote:I'm not trying to figure out what's wrong. I just want to write a macro that does what I explained in my original post.
See thats where im different I want to know why its broken so I can provide a better fix / solution.

That being said, download PhotoResize.exe http://www.rw-designer.com/picture-resize

Rename the executable to PhotoResizeP100IOEQ100.exe

Select all the images & then drag and drop them onto the exe. Note this will re-save the images (overwriting the originals) with the same dimensions its not actually doing anything resize wise, just re-saving them.

If that works for your program then we can look at using a macro and calling the folder to be done via a batch.
FIREFIGHTER

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Dec 31, 2012 6:25 am

Hmmm, one more quick question. Are the files larger than the desktop on the computer you're displaying them on? I'm wondering if we could create a dialog, display the image in the dialog then do a Macro Scheduler ScreenCapture> and save the result to a jpg. Then rename the Macro Scheduler file to .jpeg if that is important. Just trying to come up with a method that would be faster than opening each file in Paint.

TRy this. Its untested so might not work but should be a close start for using Paint.

Code: Select all

Let>INPUT_BROWSE=2
InPut>vfolder,Select the folder where the jpgs live.

GetFileList>%vfolder%\*.jpg,vList,;
Separate>vList,;,vFile

Let>rp_wait=0

Let>kk=0
Repeat>kk
  Add>kk,1
  Let>value=vFile_%kk%
  ExtractFileName>value,vFileName
  ExtractFilePath>value,vPathName
  ExtractFileExt>value,vFileExt
  StringReplace>vFileName,vFileExt,,vFileName
  Run>msPaint %value%
  WaitWindowOpen>Paint*
  Wait>0.5
  SetFocus>Paint*
  Press ctrl
    Send>s
  Release ctrl
  WaitWindowOpen>Save As
  Wait>0.5
  Press Tab
  Wait>0.5
  Send>j
  Wait>0.5
  Press shift
    Press Tab
  Release shift
  Wait>0.5
  Send>%vPathName%\%vFileName%.JPEG
  Wait>0.5
  Press Enter
  WaitWindowClosed>Save As
  KillProcess>msPaint.exe
  WaitWindowClosed>Paint*
  Wait>0.5
  Until>kk=vFile_Count

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Mon Dec 31, 2012 6:34 am

Nice Script JRL,

That was also the way I was thinking about doing it if we had to use MSPaint. I think the issue is with a malformed jpg file. When your saving it again in paint with the jpeg file it is telling it to update the image.

In paint if you open the image, not make any changes & try to save it again with the same file name / extension paint knows nothing has changed therefore doesn't do anything. Where as if you select jpeg your telling it to re-create the file with the new filename / extension.

Sorry Deborah I didn't mean to sound harsh in my last post, just trying to find the cause of the problem so I can provide a better solution.

Having MSPaint opening and closing would be a real drag, hopefully photoresize does what is required and if so it could be scripted to monitor a directory for changes and as soon as it detects a new file run the rename / resize in the background. Should be a bit quicker than all the open and close MS paint windows.
FIREFIGHTER

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Mon Dec 31, 2012 6:36 am

PS JRL that script didn't work for my MSPaint in Windows 7.
FIREFIGHTER

daa5417
Newbie
Posts: 10
Joined: Sun Dec 30, 2012 3:56 am
Location: New Orleans, LA

Post by daa5417 » Mon Dec 31, 2012 6:36 am

JRL wrote:Hmmm, one more quick question. Are the files larger than the desktop on the computer you're displaying them on? I'm wondering if we could create a dialog, display the image in the dialog then do a Macro Scheduler ScreenCapture> and save the result to a jpg. Then rename the Macro Scheduler file to .jpeg if that is important. Just trying to come up with a method that would be faster than opening each file in Paint.

TRy this. Its untested so might not work but should be a close start for using Paint.

Code: Select all

Let>INPUT_BROWSE=2
InPut>vfolder,Select the folder where the jpgs live.

GetFileList>%vfolder%\*.jpg,vList,;
Separate>vList,;,vFile

Let>rp_wait=0

Let>kk=0
Repeat>kk
  Add>kk,1
  Let>value=vFile_%kk%
  ExtractFileName>value,vFileName
  ExtractFilePath>value,vPathName
  ExtractFileExt>value,vFileExt
  StringReplace>vFileName,vFileExt,,vFileName
  Run>msPaint %value%
  WaitWindowOpen>Paint*
  Wait>0.5
  SetFocus>Paint*
  Press ctrl
    Send>s
  Release ctrl
  WaitWindowOpen>Save As
  Wait>0.5
  Press Tab
  Wait>0.5
  Send>j
  Wait>0.5
  Press shift
    Press Tab
  Release shift
  Wait>0.5
  Send>%vPathName%\%vFileName%.JPEG
  Wait>0.5
  Press Enter
  WaitWindowClosed>Save As
  KillProcess>msPaint.exe
  WaitWindowClosed>Paint*
  Wait>0.5
  Until>kk=vFile_Count
The error that comes up is "C:\Users\Name\Documents\Animation\New.png was not found. This "not found" error is the same one that came up when I was trying to write a simple macro for just saving a blank Paint file, but I'm a novice, so I really don't know why it shows up.
D. Anderson

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Mon Dec 31, 2012 6:38 am

Hi Deb,

That is because the script JRL wrote is only looking for *.jpg files to re-save as *.jpeg files. Your now talking about a png file.

Is there more than one file type?
FIREFIGHTER

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Mon Dec 31, 2012 6:42 am

Also check out http://lifehacker.com/342308/batch-conv ... age-magick

This will allow you to batch convert images as well, might be another solution if PhotoResize doesn't work for you.
FIREFIGHTER

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts