Link to home
Start Free TrialLog in
Avatar of nrigaud
nrigaud

asked on

Windows Desktop API - windows shortcuts on the correct Desktop ?

Hello,
I am writing a small application in C++ based on the Desktop API (CreateDesktop / OpenDesktop / SwitchDesktop)
I create a secondary desktop and i spawn explorer.exe into it.

Each time I use a windows shortcut from this secondary desktop (like WIN + E / CTRL + ALT + SUPP)
it creates the associated window into the first / primary default desktop.

How to make the windows shortcuts works correctly ?
What are the differents solutions to solve this problem ?

I don't like catching all keyboard combinaisons myself.

Avatar of Deepu Abraham
Deepu Abraham
Flag of United States of America image

Do you want to disable windows hot keys while you are on your 'private desktop'/ new desktop created by CreateDesktop() API?
Best Regards,
DeepuAbrahamK
Avatar of nrigaud
nrigaud

ASKER

No, i want to make them work on any Desktop.
thx
Check out the article at http://www.codeguru.com/Cpp/W-P/system/misc/article.php/c5695 ("Creating and Switching to Different Desktops") - the scoop is to specify the desktop name in the STARTUP_INFO struct when launching a process, e.g.

                  SECURITY_ATTRIBUTES saDesktop = { sizeof(saDesktop), NULL, TRUE };
                  hDesk =
                  CreateDesktop(szDesktop,
                        NULL,
                        NULL,
                        NULL,
                        DESKTOP_ALL_ACCESS,
                        &saDesktop);

                  STARTUPINFO startInfo1 = { 0 };
                  startInfo1.cb = sizeof(startInfo1);
                  startInfo1.lpDesktop = szDesktop;
                  PROCESS_INFORMATION psInfo1 = { NULL };

                  bRet =
                  CreateProcess(NULL,
                        szCommandLine,
                        NULL, //process security descriptor
                        NULL, //thread security descriptor
                        TRUE, //inherit handles
                        NORMAL_PRIORITY_CLASS, //creation flags
                        NULL, //environment block - use current
                        (LPCTSTR)szStartDir, //startup directory
                        &startInfo1,
                        &psInfo1);

                  if(bRet==FALSE)
                  {
                        Error();
                  }

                  if(hDesk!=NULL)
                  {
                        if(FALSE == CloseDesktop(hDesk))
                        {
                              Error();
                        }
                  }
                  return bRet;
            }

Also of interest: http://www.codeproject.com/system/RunUser.asp ("GUI-Based RunAsEx") which takes the whole thing one step further.
Avatar of nrigaud

ASKER

I know how to do that.

Am not creating these processes, the system is (in response to windows default hotkeys).
So i can' t apply this method.



Hmmm, rethinking that: When you launch a shell link, the shell calls 'ShellExecute()' or it's 'Ex' successor. Both do not support any parameters to specify a desktop, so when finally 'CreateProcess()' is called it uses a NULL parameter for 'lpDesktop', which in turn makes the process show up un the default desktop...
Don't think whether you can do this unless you create a different hotkeys to hanlde this inside your private desktop ! Is that a valid option to you?
Best Regards,
DeepuAbrahamK
Avatar of nrigaud

ASKER

I don't want different hotkeys.
ASKER CERTIFIED SOLUTION
Avatar of pjasnos
pjasnos
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial