SpFindWindowHandle

From EDM2
Revision as of 17:16, 26 February 2017 by Ak120 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This function returns the window handle of the first window found, which matches certain criteria.

Syntax: hwnd = spFindWindowHandle ( [ hwndParent ] , [ class ] , [ id ] , [ text ] , [ pid ] , [ filename ] )

Parameters: hwndParent – Window handle of the parent window. If ommited, the default desktop handle will be used (HWND_DESKTOP).

  • class – Window class name.
  • id – Window identifier.
  • text – Window text (title).
  • pid – Process identifier of window owner
  • filename – Substring of the full-qualified module filename of the process

owning the window.

Returns:

  • 0 – No window which matches the criteria has been found.
  • >0 – Window handle of the first window found, which matches the criteria.

Example Code:

/* scclock.cmd (spUtils Example Code) */
/* Switches the Smartcenter (aka WarpCenter or eComCenter) clock by */
/* simulating a button click on the clock */

CALL RXFUNCADD 'spLoadFuncs','spUtils','spLoadFuncs'
CALL spLoadFuncs
CALL spSetAutoSleep 0
focus=spQueryFocus()
PARSE VALUE spQueryPointerPos() WITH xptrpos yptrpos

hwnd=spFindWindowHandle(,,,'SmartCenter',,'\PMSHELL.EXE')
   IF hwnd=0 THEN DO
         SAY 'Smartcenter (WarpCenter or eComCenter) not found'
   RETURN
END

xoffset=spQueryWindowPos(hwnd,'x')
yoffset=spQueryWindowPos(hwnd,'y')
xpos=spQueryWindowPos(hwnd,'cx')-5
ypos=5

CALL spSetPointerPos xoffset+xpos,yoffset+ypos
CALL spPostMsg hwnd,'WM_BUTTON1DOWN',spMPFROM2SHORT(xpos,ypos)
CALL spPostMsg hwnd,'WM_BUTTON1UP',spMPFROM2SHORT(xpos,ypos)
CALL spPostMsg focus,'WM_BUTTON1DOWN',spMPFROM2SHORT(0,0)
CALL spPostMsg focus,'WM_BUTTON1UP',spMPFROM2SHORT(0,0)
CALL spSetPointerPos xptrpos,yptrpos