c# - Check if a Winform CheckBox is checked through WINAPI only -


my problem goes : need check if winform checkbox different program checked or not winapi only.

here how catch underlyined c# hwnd: first hwnd's of desktop enumwindows , enumchildwindows , go on each 1 , getwindowtext compares wanted text window text , if there match - return it.

just make things clear - can catch underlying hwnd. if print text , class name winform checkbox wanted.

now, checkbox want check has windowsform.10.button.app.0.33c0d9d5 class name. function ask if valid checkbox:

bool isvalid(){     if(!handletocontrol) return false;     long_ptr styles = getwindowlongptr(handletocontrol, gwl_style);     bool ischeckbox = ((styles & bs_auto3state) == bs_auto3state);     ischeckbox = ischeckbox || ((styles & bs_autocheckbox) == bs_autocheckbox);     ischeckbox = ischeckbox || ((styles & bs_checkbox) == bs_checkbox);     return ischeckbox; } 

now, function work (i checked on many native checkboxes , winform checkboxes) , can validate if it's valid checkbox or not (including checkbox want check)

then , try see if winform checkbox checked or not function:

bool ischecked(){     lresult _ischecked = sendmessage(handletocontrol, bm_getcheck, 0, 0);     bool ic = !(_ischecked == bst_unchecked);     if (ic)         return ic;     ic = ((button_getstate(handletocontrol) & bst_checked) == bst_checked);     if (ic)         return ic;      return false; } 

but fail miserably. can see what's wrong idea / code or suggest different solution?

is using iaccessibility option?

e.g.

(taken http://bytes.com/topic/net/answers/637107-how-find-out-if-check-box-checked)

[dllimport("oleacc.dll")] internal static extern int accessibleobjectfromwindow(intptr hwnd, uint id, ref guid iid, [in, out, marshalas(unmanagedtype.iunknown)] ref object ppvobject);   internal enum objid : uint {     window = 0x00000000,     sysmenu = 0xffffffff,     titlebar = 0xfffffffe,     menu = 0xfffffffd,     client = 0xfffffffc,     vscroll = 0xfffffffb,     hscroll = 0xfffffffa,     sizegrip = 0xfffffff9,     caret = 0xfffffff8,     cursor = 0xfffffff7,     alert = 0xfffffff6,     sound = 0xfffffff5, }  public const long unchecked = 1048576; public const long checked = 1048592; public const long unchecked_focused = 1048580; // if control focused public const long checked_focused = 1048596; // if control focused  private static bool ischecked(intptr handle) {     guid guid = new guid("{618736e0-3c3d-11cf-810c-00aa00389b71}");     object obj = null;     int retvalue = accessibleobjectfromwindow(handle, (uint) objid.client, ref guid, ref obj);      if (obj iaccessible) {         iaccessible accobj = (iaccessible) obj;         object result = accobj.get_accstate(0);         if (result int) {             int state = (int) result;             return (state == checked || state == checked_focused);         }     }     return false; } 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -