Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>FindWindow - will get you close; you do want a window handle but you won't for sure know how to find it. </p> <p>Better would be do use EnumWindows.Here's an example of a routine you can run every second or two that will give you a ton of info about every single window on the system, then you can analyze it. You can check the type of window, the text in it, get the buttons, and send a click message to the right one. It will let you do everything you are hoping to be able to do. </p> <p>To get the text you send a wm_gettext and for the button you may get away with wm_click. </p> <p>Sorry for the C. the next best example I could find was in LISP. Take time to read the code, you will see what the idea is. The Matching functions help determine if the text is right without knowing it exactly.</p> <p>If you can manage to do this in c# I am betting you will get a lot shorter solution. (can you use LINQ on the output of EnumWindows?;-)</p> <pre><code>#include &lt;string.h&gt; #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;windows.h&gt; #include "resource.h" #define ET_STARTUP 1 #define ET_WINDOWOPEN 2 #define ET_RUNEND 3 #define ET_USEREVENT 4 #define M_STAR 1 #define M_QUESTION 2 typedef struct WindowList_s { int iScriptLine; HWND hwnd; char *stName; char *stTitle; char *stClassName; char *stParentName; struct WindowList_s *wlParentPtr; char *stChildName; struct WindowList_s *wlChildPtr; int bWarned; struct WindowList_s *next; } WindowList_t; //////////////// extern long g_runids[]; extern WindowList_t *g_windowlist; extern EventList_t *g_eventlist; char stWTx[2000]; char stWCl[200]; char stPTx[2500]; char stPCl[200]; int bEventEntry=0; // means we're inside of processing an event. HWND LogWinParent; void FixIt(char *buf,unsigned int siz) { int i,j,bump; int ir; char cr; char hex[10]; // keep special characters from screwing up script by // replacing w/ single-character wildcard for (i=0;buf[i];i++) { cr='\0'; ir=0; bump=1; switch(buf[i]) { case '\0':cr='0';break; case '\\':cr='\\';break; case '\n':cr='n';break; case '\t':cr='t';break; case '\a':cr='a';break; case '\b':cr='b';break; case '\f':cr='f';break; case '\r':cr='r';break; case M_STAR:cr='*';break; case M_QUESTION:cr='*';break; case '"':cr='"';break; default: if (buf[i]&lt;32 || buf[i]&gt;=127) { bump=2; ir=buf[i]; } else bump=0; } if (bump) { for (j=strlen(buf)+bump+1&gt;=siz-1?siz-1:strlen(buf)+1; j&gt;i;j--) buf[j+bump]=buf[j]; buf[siz-1]='\0'; if (cr) { buf[i++]='\\'; buf[i]=cr; } if (ir) { sprintf(hex,"\\x%00H",ir); memcpy(buf+i,hex,4); i+=4; } } } } void LogWin(HWND hw) { static long ParentNum=0,ChildNum=0; GetWindowText(hw,stWTx,sizeof(stWTx)-1); GetClassName(hw,stWCl,sizeof(stWCl)-1); FixIt(stWTx,sizeof(stWTx)); FixIt(stWCl,sizeof(stWCl)); if (GetParent(hw)==LogWinParent) { ChildNum++; sprintf(stPTx," WindowObject %ld.%ld \"%s\" \"%s\" " "Parent %ld",ParentNum,ChildNum,stWTx,stWCl,ParentNum); } else if (hw==LogWinParent) { ChildNum=0; ParentNum++; sprintf(stPTx," WindowObject %ld \"%s\" \"%s\"", ParentNum,stWTx,stWCl); } else { ChildNum++; sprintf(stPTx," WindowObject %ld.%ld \"%s\" \"%s\" GRANDCHILD", ParentNum,ChildNum,stWTx,stWCl); } log_it(stPTx); } BOOL CALLBACK EnumChildProc4Logging( HWND hwnd,LPARAM lParam ) { LogWin(hwnd); return 1; } void LogCurrentWindows(void) { static int bEntry=0; static HWND hwCurrentFocus = 0; if (bEntry) return; bEntry=1; LogWinParent=GetForegroundWindow(); if (LogWinParent!=hwCurrentFocus) { hwCurrentFocus=LogWinParent; LogWin(LogWinParent); EnumChildWindows(LogWinParent,EnumChildProc4Logging,0); } bEntry=0; } /******************************************************************/ /* match() - parse wildcard strings . */ /******************************************************************/ int match(char *pattern,char *str) { int patt,st; patt=0; st=0; while(pattern[patt] || str[st]) /* go until both at '\0' */ { if ((!pattern[patt] || !str[st]) &amp;&amp; pattern[patt]!=M_STAR) return 0; /* fail if one at '\0' */ if (pattern[patt]==M_STAR) { patt++; while (str[st] &amp;&amp; !match(pattern+patt,str+st)) st++; } else if (pattern[patt]!=M_QUESTION &amp;&amp; pattern[patt]!=str[st]) return 0; /* Oh, No!! no match. */ else { patt++; st++; } } return 1; /* successful match */ } void CheckWindowList(HWND hwnd) { WindowList_t *wl; HWND hwndParent,hwndTarget; static char buf[600]; // Get the window's class and text GetWindowText(hwnd,stWTx,sizeof(stWTx)-1); GetClassName(hwnd,stWCl,sizeof(stWCl)-1); // Get the Parent Window's class and text hwndParent=GetParent(hwnd); GetWindowText(hwndParent,stPTx,sizeof(stPTx)-1); GetClassName(hwndParent,stPCl,sizeof(stPCl)-1); // search thru window objects, fill in // matching hwnds as appropriate for (wl=g_windowlist;wl;wl=wl-&gt;next) { hwndTarget=NULL; // separate variable enables // warning on duplicate matches if (wl-&gt;wlChildPtr==NULL &amp;&amp; wl-&gt;wlParentPtr==NULL) { // no parent/child requirements if (match(wl-&gt;stClassName,stWCl) &amp;&amp; match(wl-&gt;stTitle,stWTx) ) hwndTarget=hwnd; } else if (wl-&gt;wlParentPtr) { // parent requirement - if I (hwnd) match the // wl's class/title and the parent (hwndParent) // matches the wl's parentptr's class/title then // set 'me' as the window that matches and has // the proper parent requirement. if (match(wl-&gt;stClassName,stWCl) &amp;&amp; match(wl-&gt;stTitle,stWTx) &amp;&amp; match(wl-&gt;wlParentPtr-&gt;stClassName,stPCl) &amp;&amp; match(wl-&gt;wlParentPtr-&gt;stTitle,stPTx) ) hwndTarget=hwnd; } else { // child requirement - if I (hwnd) match the child // requirement's stuff and the parent(hwndParent) // matches the wl's stuff then set the parent // as that wl's hwnd. if (match(wl-&gt;stClassName,stPCl) &amp;&amp; match(wl-&gt;stTitle,stPTx) &amp;&amp; match(wl-&gt;wlChildPtr-&gt;stClassName,stWCl) &amp;&amp; match(wl-&gt;wlChildPtr-&gt;stTitle,stWTx) ) hwndTarget=hwndParent; } if (hwndTarget) { if (wl-&gt;hwnd &amp;&amp; !wl-&gt;bWarned ) // log a warning on dup windows { sprintf(buf,"267.EnumChildProc4Search.10 " "Warning: more than one match for " "windowobject %s exists",wl-&gt;stName); log_it(buf); wl-&gt;bWarned =1; } else wl-&gt;hwnd=hwndTarget; } } } BOOL CALLBACK EnumChildProc4Search( HWND hwnd,LPARAM lParam ) { CheckWindowList(hwnd); // return value of 1 means continue with rest of enumeration. return 1; } // to enumerate all... enumchild w/ NULL hwnd don't work???! BOOL CALLBACK EnumWindowProc4Search( HWND hwnd,LPARAM lParam ) { CheckWindowList(hwnd); EnumChildWindows(hwnd,EnumChildProc4Search,0); return 1; } // Check thru all windows and runIDs to see if a run is done // or a window has opened. First emumerate the windows and running // programs and then see which events should be run. // this function must not run if blocked, 'once' countdown // has run out, or stopscript=1, or entry = 1 void RunEvents(void) { // Please keep in mind this program's error philosphoy when // extending it, namely, catch all possible script errors // when loading script, but do not display messageboxes for // even the most serious errors when doing events, because // the idea is to catch errors during development and avoid // errors at run time or in production!! static bEventEntry=0; WindowList_t *wl; EventList_t *el; ParmList_t *pl; char *st; int i; long lExitCode; // exit this routine if we shouldn't be here if (g_iStopScript || bEventEntry) return; bEventEntry=1; // clear all of the window handles in windowobject list for (wl=g_windowlist;wl;wl=wl-&gt;next) { wl-&gt;hwnd=NULL; wl-&gt;bWarned = 0; } // enumerate all windows in the system; repopulate all of // the window handles in the windowobject list EnumWindows(EnumWindowProc4Search,0); // go thru event list, calling any events that must // be called; windows handles for any subsequent actions // will have been set by above code. Check for runs ending // to process runend events and search the windowobject list // to process windowopen events. for (el=g_eventlist;g_eventlist &amp;&amp; el;el=el-&gt;next) { pl=MakeParms(el-&gt;stEventTypeSourceLine); st=ParmValue(pl,2); // event name // check for windowopen events if (el-&gt;iEventType==ET_WINDOWOPEN) { // search for their open windows!! for (wl=g_windowlist;wl;wl=wl-&gt;next) { if (0==_stricmp(wl-&gt;stName,st) &amp;&amp; wl-&gt;hwnd) RunActions(el); if (g_iStopScript) return; // quit doing actions/events ASAP. } } } if (el-&gt;iEventType==ET_RUNEND) { sscanf(st,"%ld",&amp;i); if (g_runids[i]!=-1 &amp;&amp; g_runids[i]!=0) { GetExitCodeProcess((HANDLE)g_runids[i],&amp;lExitCode); if (lExitCode != STILL_ACTIVE) { RunActions(el); g_runids[i]=0; } } } KillParms(pl); } bEventEntry=0; } void RunStartup(void) { EventList_t *el; if (bEventEntry) return; bEventEntry=1; // check stopscript in case of endscript in startup event! for (el=g_eventlist;g_eventlist &amp;&amp; el &amp;&amp; !g_iStopScript;el=el-&gt;next) { if (el-&gt;iEventType==ET_STARTUP) RunActions(el); } bEventEntry=0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload