I want to resize and/or move some external windows from my application, mainly the On-Screen keyboardwindow. Here is the code:
[DllImport(\"user32.dll\"
The on screen keyboard runs at a high integrity level. This means that you need your process also to run at that integrity level. The first thing to do is to execute your program as admin. That will run your process at a high integrity level.
Of course, you are unlikely to find the prospect of running your app elevated, and so presenting its users with UAC dialogs, very appealing. But that's just a consequence of the system design.
Do note that your error handling is incorrect. Only check the error code if the API functions fails. Which means checking the return value of the function. And your p/invoke for SetWindowPos
is flawed. It fails to set SetLastError
. These details really do matter and you must take great care. The compiler cannot check interop code for correctness.