0

so I have been trying to simulate a click on my file explorer window to get back from my open folder to the previous directory. Straight forward. So I used SpyXX to know the window's names, so I can simulate this click.

Here is my code:

int main(int argc, char *argv[])
{

HWND hwnd = FindWindowA("CabinetWClass", "SpyXX");
if(!hwnd) {
    std::cout << "Error: Cannot find window!" << std::endl;
}
else {
    std::cout << "Success! Window found!" << std::endl;
}

HWND hwnd2 = FindWindowExA(hwnd, NULL, "WorkerW", "");
if(!hwnd2) {
    std::cout << "Error: Cannot find child window!" << std::endl;
}
else {
    std::cout << "Success! Child window found!" << std::endl;
}

HWND hwnd3 = FindWindowExA(hwnd2, NULL, "ReBarWindow32", "");
if(!hwnd3) {
    std::cout << "Error: Cannot find child window!" << std::endl;
}
else {
    std::cout << "Success! Child window found!" << std::endl;
}

HWND hwnd4 = FindWindowExA(hwnd3, NULL, "UpBand", "");
if(!hwnd4) {
    std::cout << "Error: Cannot find child window!" << std::endl;
}
else {
    std::cout << "Success! Child window found!" << std::endl;
}

HWND hwnd5 = FindWindowExA(hwnd4, NULL, "ToolbarWindow32", "Nach-oben-Symbolleiste");
if(!hwnd5) {
    std::cout << "Error: Cannot find child window!" << std::endl;
}
else {
    std::cout << "Success! Child window found!" << std::endl;
}

SendMessageA(hwnd5, BM_CLICK, 0, 0);


return 1;
}

And my output shows that the window has been found:

  Success! Window found!
  Success! Child window found!
  Success! Child window found!
  Success! Child window found!
  Success! Child window found!

However the SendMessageA command doesn't do anything. The file explorer window doesn't change, meaning the 'back' button has not been pressed. Why is that? What am I doing wrong? I also used the SendMessageW and SendMessage commands to no avail.

Thanks alot in advance.

Bializm
  • 1
  • 4
  • 1
    Hacking windows that are not yours may or not work. The Shell has some API that can be used. Not sure what you're exactly trying to do so I can't be sure you could use it. Otherwise you could use UI Automation which was made exactly for that kind of purpose (UI manipulation, clicking on buttons, etc.): https://learn.microsoft.com/en-us/windows/win32/winauto/entry-uiauto-win32 – Simon Mourier May 10 '22 at 14:48

1 Answers1

-2

I suggest you could try the following code:

    SendMessage(hwnd5, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(0, 0));
    SendMessage(hwnd5, WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM(0, 0));
Jeaninez - MSFT
  • 3,210
  • 1
  • 5
  • 20
  • 2
    Do you realize that you *"- MSFT"* folks have gained yourself a reputation consistently low credibility? This is no exception with respect to quality. Please see what a *real* Microsoft engineer has to say: [You can't simulate keyboard input with PostMessage](https://devblogs.microsoft.com/oldnewthing/20050530-11/?p=35513). – IInspectable May 11 '22 at 10:06