I'm trying to do some automation of windows applications. To do whatever I want to do, I need the window handles of some controls.
Before, I would accomplish this with a combination EnumWindows, EnumChildWindows and GetWindowText. But now, some newer programs no longer have toolbar with buttons on it. Instead, they have a ribbon.
This didn't seem like much of a problem to me at first, but now I notice that the buttons on the ribbon don't show up in EnumChildWindows! Or at least GetWindowText does not return the same text as the one seen on the screen.
So to make a long story short: Can anybody tell me how I can programatically find the handle of a button on a ribbon?
Thanks. Regards, ldx
Okay,
So it was indeed not possible to get a handle on these buttons. I solved this by using SendKeys to send the keyboard-shortcut that activates the button. In my case it was the save button, so I used
INPUT inputs[4];
// press control
inputs[0].type = INPUT_KEYBOARD;
inputs[0].ki.wVk = 0x11; // "VK_Control"
inputs[0].ki.wScan = 0;
inputs[0].ki.dwFlags = 0;
inputs[0].ki.time = 0;
inputs[0].ki.dwExtraInfo = 0;
// press "s"
inputs[1].type = INPUT_KEYBOARD;
inputs[1].ki.wVk = 0x53; // "s"
inputs[1].ki.wScan = 0;
inputs[1].ki.dwFlags = 0;
inputs[1].ki.time = 0;
inputs[1].ki.dwExtraInfo = 0;
// release "s"
inputs[2].type = INPUT_KEYBOARD;
inputs[2].ki.wVk = 0x53; // "s"
inputs[2].ki.wScan = 0;
inputs[2].ki.dwFlags = KEYEVENTF_KEYUP;
inputs[2].ki.time = 0;
inputs[2].ki.dwExtraInfo = 0;
// release control
inputs[3].type = INPUT_KEYBOARD;
inputs[3].ki.wVk = 0x11; // "VK_Control"
inputs[3].ki.wScan = 0;
inputs[3].ki.dwFlags = KEYEVENTF_KEYUP;
inputs[3].ki.time = 0;
inputs[3].ki.dwExtraInfo = 0;
return SendInput(8, inputs, sizeof(INPUT)) == 8;
Maybe this can spawn ideas for other people with the same problem :)
Gr, ldx