October 21st, 2013, 11:49 AM
Sending keystrokes to IrfanView?
I have to update 1000+ JPG images by modifying the IPTC info stored inside the pictures.
One of the tools I can use to update this info is IrfanView. After opening the image, hitting Ctrl-i brings up the IPTC info screen.
I already have written the code (in VB6) that allows me to identify the pictures where the IPTC is missing or incomplete and also the code needed to start IrfanView en open the concerned picture automatically.
I now want to send a Ctrl-i (and later on also the 4 tabs following this key combination) so that it also opens the IPTC window and tabs to the correct field.
I tried to do this with the SendMessage function but IrfanView seems to ignore what I'm sending it.
The value returned is zero.
Checking the last error message reveals nothing special (normal completion).
I include some of the code I used below.
Anybody around having succeeded communicating with IrfanView through SendMessage?
' Load startupinfo control block
StrtInfo.cb = Len(StrtInfo)
StrtInfo.dwFlags = STARTF_USESHOWWINDOW
StrtInfo.wShowWindow = SW_SHOWMAXIMIZED
' Create process
iSts = CreateProcess(vbNullString, _
xProgramSpec + " " + xPictureSpec, _
ByVal 0&, _
ByVal 0&, _
ByVal 0&, _
Debug.Print "Status after CreateProcess = "; iSts
If iSts = 0 Then Exit Sub
' Wait for the process
iSts = WaitForInputIdle(ProcInfo.hProcess, INFINITE) ' consider replacing INFINITE by 5000 = 5 seconds (or less)
Debug.Print "Status after WaitForInputIdle = "; iSts
If iSts <> 0 Then Exit Sub ' SURPRISE! Status 0 means success in this case ...
' Use FindWindow to get a handle on the window
iWindowHandle = FindWindow(vbNullString, "depesseroey_antoon.jpg - IrfanView") ' hardcoded for test purposes
Debug.Print "Handle found with FindWindow = "; iWindowHandle
If iWindowHandle = 0 Then Exit Sub
' Send <Ctrl><i> to bring up the IPTC information window
' Testing RetVal has no sense. SendMessage returns whatever it gets from the window.
RetVal = SendMessage(iWindowHandle, WM_KEYDOWN, VK_CONTROL, 0)
RetVal = SendMessage(iWindowHandle, WM_KEYDOWN, Asc("i"), 0)
RetVal = SendMessage(iWindowHandle, WM_KEYUP, Asc("i"), 0)
RetVal = SendMessage(iWindowHandle, WM_KEYUP, VK_CONTROL, 0)
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!