vb.net - How to detect and get text from win32 popup in .net -


i've looked through several examples of trying listed on stackoverflow, haven't found lists how .net coding. need detect popup, , once found popup pull title of window, , text inside popup.

i tried using post: how-can-i-change-text-on-a-win32-window

but had no luck trying find how "get text" how see if popup exists. window i'm trying text standard windows error window (#32770) a.k.a win32 critical popup window (one red x). know title of error window going "tlp2011"

i need able read title, text, , click "ok" on error button.

reason? there's software run , cut on inbound call costs want write program detects errors popup, once been detected close error window , tell user error automatically fixed. (my new program have able read text error window in order determine how automatically fix error error doesn't show again)

----------edited show latest finds------------

thanks gx posting following link how can functionality similar spy++ in c# app?

now have determined need following:

dim pprocess() process = process.getprocessesbyname("tlp2011")      each p process in pprocess         each threadinfo processthread in p.threads              ' uncomment dump thread handles             'console.writeline("\tthread {0:x}", threadinfo.id);             dim windows intptr() = getwindowhandlesforthread(threadinfo.id)             if windows isnot nothing andalso windows.length > 0                 each hwnd intptr in windows                     console.writeline(vbtab & "window {0:x} text:{1} caption:{2}", hwnd.toint32(), gettext(hwnd), getedittext(hwnd))                 next             end if         next     next 

now lists on actual program itself. every piece of text , everything. know trick single out popup box?

here example of displays

window 3d21aa text:select package caption: window 551176 text: caption: window e8147c text:do not auto show  caption:do not auto show  window 8e21c6 text:&select caption:&select window 2300e10 text:&help caption:&help window 762164 text:cancel caption:cancel window 330f0e text:ok caption:ok window e8147c text:do not auto show  caption:do not auto show  window 8e21c6 text:&select caption:&select window 2300e10 text:&help caption:&help window 762164 text:cancel caption:cancel window 330f0e text:ok caption:ok window 10f20a6 text: caption: window 5f122ce text: caption: window 1824e2 text: caption: window 1824e2 text: caption: window 5f122ce text: caption: window 1824e2 text: caption: window 1824e2 text: caption: window 6e1be4 text: caption: window 342162 text: caption: window 1c1b92 text: caption: window 65105a text: caption:admin window 291f72 text: caption: window 375104e text: caption: window 375104e text: caption: window 1c1b92 text: caption: window 65105a text: caption:admin window 291f72 text: caption: window 375104e text: caption: window 375104e text: caption: window 242308 text:form filter caption: window 9ee294e text: caption: window 8ff0f54 text: caption:all status window 468273c text: caption: window 1d110c text: caption: window 1d110c text: caption: window 8ff0f54 text: caption:all status window 468273c text: caption: window 1d110c text: caption: window 1d110c text: caption: window b90bea text:cbengine caption: window 5b17b0 text: caption: window ee24c6 text: caption: window ee24c6 text: caption: window fc1ae0 text: caption: window 141cfc text:tlp2011 caption: window d51928 text:ok caption:ok window 2c1223c text: caption: window 100f08 text:access violation @ address 6cabc667 in module 'tlpcore.dll'. write of address f8ffff86. caption:access violation @ address 6cabc667 in module 'tlpcore.dll'. write of address f8ffff86. window b2a214e text: caption: 

anyone know better way try , find error box? don't think doing search "tlp2011" using next 3 lines try , determine msgbox text "reliable" method. know how single out more?

----added more thoughts----

doing check through of different threads every 10 seconds seems put huge drain on system. logical way go doing this?

gaetano got correct response

static void main(string[] args) {     foreach (process procesinfo in process.getprocesses())     {         console.writeline("process {0} {1:x}", procesinfo.processname, procesinfo.id);         foreach (processthread threadinfo in procesinfo.threads)         {             // uncomment dump thread handles             //console.writeline("\tthread {0:x}", threadinfo.id);             intptr[] windows = getwindowhandlesforthread(threadinfo.id);             if (windows != null && windows.length > 0)                 foreach (intptr hwnd in windows)                     console.writeline("\twindow {0:x} text:{1} caption:{2}",                         hwnd.toint32(), gettext(hwnd), getedittext(hwnd));         }     }     console.readline(); }  private static intptr[] getwindowhandlesforthread(int threadhandle) {     _results.clear();     enumwindows(windowenum, threadhandle);     return _results.toarray(); }  // enum windows  private delegate int enumwindowsproc(intptr hwnd, int lparam);  [dllimport("user32.dll")] private static extern int enumwindows(enumwindowsproc x, int y); [dllimport("user32")] private static extern bool enumchildwindows(intptr window, enumwindowsproc callback, int lparam); [dllimport("user32.dll")] public static extern int getwindowthreadprocessid(intptr handle, out int processid);  private static list<intptr> _results = new list<intptr>();  private static int windowenum(intptr hwnd, int lparam) {     int processid = 0;     int threadid = getwindowthreadprocessid(hwnd, out processid);     if (threadid == lparam)     {         _results.add(hwnd);         enumchildwindows(hwnd, windowenum, threadid);     }     return 1; }  // window text  [dllimport("user32.dll", charset = charset.auto, setlasterror = true)] static extern int getwindowtext(intptr hwnd, stringbuilder lpstring, int nmaxcount); [dllimport("user32.dll", setlasterror = true, charset = charset.auto)] static extern int getwindowtextlength(intptr hwnd);  private static string gettext(intptr hwnd) {     int length = getwindowtextlength(hwnd);     stringbuilder sb = new stringbuilder(length + 1);     getwindowtext(hwnd, sb, sb.capacity);     return sb.tostring(); }  // richedit text   public const int gwl_id = -12; public const int wm_gettext = 0x000d;  [dllimport("user32.dll")] public static extern int getwindowlong(intptr hwnd, int index); [dllimport("user32.dll")] public static extern intptr senddlgitemmessage(intptr hwnd, int iddlgitem, int umsg, int nmaxcount, stringbuilder lpstring); [dllimport("user32.dll")] public static extern intptr getparent(intptr hwnd);  private static stringbuilder getedittext(intptr hwnd) {     int32 dwid = getwindowlong(hwnd, gwl_id);     intptr hwndparent = getparent(hwnd);     stringbuilder title = new stringbuilder(128);     senddlgitemmessage(hwndparent, dwid, wm_gettext, 128, title);     return title; } 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -