0

Using ShellExecute, I can open specify file then i get a system dialog like this:

enter image description here

Can I use the code to activate to the 3rd tab? (something like sendkey (ctrl+tab))?

the reason is i want to open this button:

enter image description here

Update: I used the code from this post, however it doesn't work :

void SendKey(HWND hWndTargetWindow, BYTE virtualKey)
{
    keybd_event(virtualKey, 0, 0, 0);
    keybd_event(virtualKey, 0, KEYEVENTF_KEYUP, 0);
}

ShellExecute(0, 0, L"myfile.xxx", 0, 0, SW_SHOW);
HWND mywindow = FindWindow(0,L"caption.xxx");
//SetForegroundWindow(mywindow );   
std::this_thread::sleep_for(std::chrono::milliseconds(500));
SendKey(mywindow , VK_CONTROL);
SendKey(mywindow , VK_TAB);

but this work, :

ShellExecute(0, 0, L"myfile.xxx", 0, 0, SW_SHOW);
HWND mywindow = FindWindow(0,L"caption.xxx");
//SetForegroundWindow(mywindow );   
std::this_thread::sleep_for(std::chrono::milliseconds(500));
SendKey(mywindow , 'A');
SendKey(mywindow , 'B');

enter image description here

Did I miss something?

Yen Dang
  • 268
  • 2
  • 9
  • This is a winapi question, much more than c++ – Jeffrey Jun 19 '21 at 17:15
  • 1
    You can use SHOpenPropSheetW (although it's marked as deprecated, it's not that easy to reproduce what it does...) https://learn.microsoft.com/en-us/windows/win32/api/shlobj/nf-shlobj-shopenpropsheetw the optional last parameter is tab's name – Simon Mourier Jun 19 '21 at 17:38
  • Hi @SimonMourier, I have updated the post, maybe it is very close. I tried searching for SHOpenPropSheetW from your suggestion but couldn't find a sample to mimic because I'm unfamiliar with its arguments. can you give me an example? – Yen Dang Jun 19 '21 at 18:26
  • 1
    Something like this https://pastebin.com/raw/Y6ukWcVz – Simon Mourier Jun 19 '21 at 20:01
  • Hi @SimonMourier, your code works fine. my problem is need to run the file before activating the tab, Is it possible to use `SHCreateItemFromParsingName to trigger an open dialog`? (this file has been assigned default app to open). so can I use it like this? `SHCreateItemFromParsingName(L"c:\\temp\\zzz.txt", 1, IID_PPV_ARGS(&item));` then 1 argument will automatically run file by default app and bind to IShellItem – Yen Dang Jun 19 '21 at 20:37
  • Hi @SimonMourier, think I still need ShellExecute or ShellExecuteInfo but don't know how to link the dialog to your sample code . – Yen Dang Jun 19 '21 at 20:55
  • 1
    I don't understand what you're trying to do. You want to start an app and then, what's the relation with this "system dialog". what is this? If you want to automate an application, then use UI automation, for ex: https://stackoverflow.com/questions/30875408/get-titlebar-caption-of-any-application-using-microsoft-ui-automation – Simon Mourier Jun 20 '21 at 06:55
  • Hi @SimonMourier, Thanks you for your time. I will investigate this further. – Yen Dang Jun 20 '21 at 07:13

0 Answers0