CB_SELECTSTRING ignored on some machines

梦想的初衷 提交于 2019-12-11 19:57:41

问题


I am using user32 library to automate some out of browser clicks on Windows, IE - "save as" dialog in particular. My solution works fine on my box however on other computers not really.

The problem is when I am setting download path in a combobox, the file name I am passing in is just ignored and the original value is used. Other messages are accepted just fine on both environment, this includes clicking buttons, getting handles to windows, iterating windows, you name it.

I know it is quite broad question, but any idea what could influence such behaviour ? I believe my code is correct, so I am searching the cause elsewhere, like permissions, different user32 versions, ... ??

Following will display the text in the combobox, select string will succeed, but once the save button is clicked, original value is used.

 User32.SendMessage(combobox, User32Constants.CB_ADDSTRING, 0, DownloadAsFileName);
 var selected = User32.SendMessage(pointerToParent, User32Constants.CB_SELECTSTRING, -1, DownloadAsFileName);

I tried different techniques of getting the destination path into the combobox, however same results. Works on my box only, I can see then sendmessages are returning expected results, but the default value is used instead.

User32.SendMessage(editPartOfCB, User32Constants.WM_SETTEXT, DownloadAsFileName.Length, DownloadAsFileName);
User32.SendMessage(combobox, User32Constants.CB_SETCURSEL, 0, IntPtr.Zero);

Any help appreciated !


回答1:


Depending on the method you use for changing the file name, send an appropriate WM_COMMAND notification to the parent of the ComboBox (CBN_SELCHANGE or CBN_EDITCHANGE)




回答2:


Wild guess: The application that you are targeting is a higher privilege application and Windows is blocking your messages.

Try running your process as Administrator and see if that effects the results.



来源:https://stackoverflow.com/questions/19290914/cb-selectstring-ignored-on-some-machines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!