I am trying to write a program that finds the "Save As" window when a user clicks save as. Then automatically type in the file name and hit enter. This is what I have so far
/* HWND = "Window Handle" */
HWND saveWindow = FindWindow(0, "Save Workspace As");
/* This is a function to simplify usage of sending keys */
void GenerateKey(int vk, BOOL bExtended) {
return;
}
int main() {
SetForegroundWindow(saveWindow);
GenerateKey(VK_CAPITAL, TRUE);
GenerateKey('T', FALSE);
GenerateKey(VK_CAPITAL, TRUE);
GenerateKey('E', FALSE);
GenerateKey('S', FALSE);
GenerateKey('T', FALSE);
GenerateKey('1', FALSE);
//Enter key
GenerateKey(0x0D, TRUE);
return 0;
But this finds the window, but doesn't enter anything in nor press enter. What am I doing wrong?
"This function is subject to UIPI. Applications are permitted to inject input only into applications that are at an equal or lesser integrity level."
"This function fails when it is blocked by UIPI. Note that neither GetLastError nor the return value will indicate the failure was caused by UIPI blocking."
Maybe that's your problem.
Have you tried SendMessage() or PostMessage() ?
Since you already have the window handle that shouldn't be too hard.
BTW: you shouldn't execute FindWindow() outside any function. It's executed BEFORE main() which makes me cringe (somehow).