(Please don't change the issue and tell me I should be doing this "programmatically" unless can you tell me how, because I have not found a way to do so.)
To see what I am doing, make these changes to my script: 1. Change the fileid to a .JPG file you have. 2. Change the DETX and DETY (detailsX and detailsY) values to match coordinates of the approximate center of the DETAILS tab when you open a PROPERTIES window for your .JPG.
If things go the same for you as me, you will get error 24, msgid 607e. In the script I try two methods to get the position of the RatingsControl1 control. Neither works for me. Errormsg 607E shows the variables which have not been set as expected.
While the error msgbox is being displayed, you can start WinSpy and validate that indeed the position and size of the RatingsControl1 control can be determined.
Why does my ControlGetPos command not work while WinSpy can get the information I want?
Code: Select all
irf_fileid := "C:\Users\Joey\Documents\my photos\Other people's pics\544963.jpg"
a := FileAddRating(Irf_fileid,3)
msgbox % a
exitapp
FileAddRating(fileid,rating="0")
{
global
DetX := 155 ; Change This value to match position of DETAILS tabs in PROPERTIES window
DetY := 20 ; Change This value to match position of DETAILS tabs in PROPERTIES window
Run, Properties %fileid%,, UseErrorLevel, PropPIDd
If (ErrorLevel = "ERROR")
return "20 - 603E Error running properties for file " fileid ". Opsys getlasterror() value is " A_lastError
SetTitleMatchMode, 2 ; 2- anywhere
Coordmode, Mouse, Client
sleep 1000
WinWait, %OutFilename% Properties,,10
If (ErrorLevel = 1)
return "2 - 604E Timeout (10 sec.) waiting for window " OutFilename "Properties"
WinActivate, %OutFilename% Properties
WinWaitActive, %OutFilename% Properties
sleep 500
MouseMove, %DetX% , %DetY% ; move over Details tab
sleep 20
MouseGetPos, , , MouseWin , MouseCtrl
if (MouseCtrl not = "SysTabControl321")
return "16 - 608E No SysTabControl321 control under mouse after move to (" DetX DetY "). Window=" %MouseWin%
MouseClick, Left, %DetX%, %DetY% ; click Details tab
sleep 300
WinGetText, wintext, A
det := substr(wintext,1,7)
if (det != "Details")
return "16 - 605E Oops! window has NO DETAILS tab or it is not where expected. Filetype= " lowExt " Window=" %MouseWin%
WinActivate, %OutFilename% Properties
WinWaitActive, %OutFilename% Properties ,,5
If ErrorLevel
return "2 - Timeout (5 sec.) waiting for window '" %OutFilename% "Properties' to activate"
; The following assumes the RATINGS control contains n stars, each of which occupies
; 1/n the total width of the RATINGS control.
;
stars = 5
WinActivate, %OutFilename% Properties
WinWaitActive, %OutFilename% Properties ,,5
;
; Method 1 : get position of RatingsControl1 control using ControlGetPos
; and window title
;
ControlGetPos, RtX, RtY, RtW, RtH, RatingsControl1, %OutFilename% Properties
; Method 2 : get position of RatingsControl1 control using ControlGetPos
; and Control's handle
;
ControlGet, hCtl, Hwnd,, RatingsControl1, %OutFilename% Properties
WinGetPos, xpos, ypos,,, % "ahk_id " hCtl
if (RtX = "")
return "24 - 607E No RatingsControl1 control found.`nRtx=" rtx "`nxpos="xpos "`nhCtl="hCtl
RtHC := RtY + .5 * RtH
StarX := RtX + (RtW / stars) * (rating - .5)
MouseMove, %StarX%, %RtCH% ; move over Star
sleep 20
msgbox Over star at %starx% %RtCH%
MouseGetPos, , , MouseWin , MouseCtrl
if (MouseCtrl != "RatingsControl1")
{
WinGetTitle, MouseTitle, ahk_id %MouseWin%
return "16 - 609E No RatingsControl1 control under mouse after move.`n found control= " MouseCtrl "`nWindow=" MouseTitle "`nFiletype " lowExt " probably does not support comments."
}
Click, left
sleep, 100
send, !a ; apply
sleep 200
send, {enter} ; closes Properties window (presses OK button)
return "0"
}