c# how to get handle over a specific mainmenu using coredll.dll

喜欢而已 提交于 2019-12-12 01:14:21

问题


I am using an application that copies text from a textbox of another running application. I do this through working with coredll.dll. But the problem is the running application's mainMenu should be clicked in order to return a text that I need to copy. How can i get the handle over a specific mainmenu using coredll.dll? I used remote Spy++ to view handlers but I cant distinguish which one is it. The handlers just contains handlers for controls such as textboxes and labels and not for mainmenus. I am a newbie in working windows CE c#.

Thanks a lot :)


回答1:


I do not have any c# code ready, as this would require a lot of p/invokes, but to give you an idea on how to 'automate' foreign apps on windows CE/Mobile take a look at tscDialog.cpp at https://code.google.com/p/rdp-auto-login/source/browse/trunk/rdp-auto-login/tscDialog.cpp?r=20.

tscDialog.cpp is the code to identify and change the Remote Desktop Mobile (RDM) Dialog on windows mobile. But first I must say that you may not get the handle of a menu of a foreign window in Windows Mobile (may work on Windows CE), as the menu is not part of the window hierarchy of the foreign window but part of the desktop.

If you look at tscdialog.cpp you find the function scanTscWindow. This one enumerates all window elements of RDM to know the elements for later automated login (was used for debug and during development).

After filling and changing the RDM dialog, a click has to be performed on the Connect menu item. This is done in starTSC() function by simulating a mouse click:

                    //Solution two with mouse_event, click at 13,306. The 13 comes from the assumption that hight of
                    //menu bar is 26 pixel and I want to click in the mid
                    //this solution does work as keyb_event does work
                    //      normalized coordinates:
                    //      (0,0) = upper left corner
                    //      (0xFFFF,0xFFFF) = lower right corner
                    DWORD dX = (0xFFFF / iScreenWidth) * (80); // changed from 13 to width=240, 1/3=80
                    DWORD dY = (0xFFFF / iScreenHeight) * (iScreenHeight - 13);
                    DEBUGMSG(1, (L"mouse click at: %u, %u\n", dX * 0xFFFFFFFF / 240, dY * 0xFFFFFFFF / 320));
                    //SetForegroundWindow(hTscDialog); //dont mess with windows z-order

                    //this will make a cursor visible
                    mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN, dX, dY, 0, 0);
                    Sleep(5);
                    mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTUP, dX, dY, 0, 0);
                    Sleep(30);
                    /*
                    //this is what happens, if you tap the screen
                    mouse_event(MOUSEEVENTF_TOUCH | MOUSEEVENTF_LEFTDOWN, dX, dY, 0, 0);
                    mouse_event(MOUSEEVENTF_TOUCH | MOUSEEVENTF_LEFTUP, dX, dY, 0, 0);
                    //Sleep(3000);
                    */

To get the text of a window (or input field) you have to use GetWindowText with the right window handle.

So the simplest way to execute a menu is to simulate a mouse click on the menu.

To get a closer look at the windows on a windos ce/mobile device I use a modified version (smaller screens) of http://www.codeproject.com/Articles/9549/Capturing-Window-Controls-and-Modifying-their-prop called zDump: http://www.hjgode.de/wp/2009/06/11/zdump-take-a-look-inside-windows-ce/

You will see that it is impossible to get the menu handle of a foreign window. AFAIK there is no way for an external process. Possibly one can inject an DLL and get the window handle by code that runs inside the foreign process.



来源:https://stackoverflow.com/questions/26143216/c-sharp-how-to-get-handle-over-a-specific-mainmenu-using-coredll-dll

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