Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Windows Desktop API - windows shortcuts on the correct Desktop ?

Posted on 2007-03-23
9
Medium Priority
?
1,187 Views
Last Modified: 2013-12-04
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.

0
Comment
Question by:nrigaud
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 11

Expert Comment

by:Deepu Abraham
ID: 18778569
Do you want to disable windows hot keys while you are on your 'private desktop'/ new desktop created by CreateDesktop() API?
Best Regards,
DeepuAbrahamK
0
 

Author Comment

by:nrigaud
ID: 18778603
No, i want to make them work on any Desktop.
thx
0
 
LVL 86

Expert Comment

by:jkr
ID: 18780169
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.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:nrigaud
ID: 18780302
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.



0
 
LVL 86

Expert Comment

by:jkr
ID: 18780863
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...
0
 
LVL 11

Expert Comment

by:Deepu Abraham
ID: 18784736
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
0
 

Author Comment

by:nrigaud
ID: 18791187
I don't want different hotkeys.
0
 
LVL 10

Accepted Solution

by:
pjasnos earned 1500 total points
ID: 18952302
It seems to me that it would be relatively hard to do, as hotkeys are systemwide (according to Microsoft's documentation, in reality they are winstation-wide):

http://msdn2.microsoft.com/en-us/library/ms646309.aspx

(Ctrl+Alt+Delete is also registered using RegisterHotKey inside winlogon process, there is no magic connected with it, as microsoft docs claim). This means that when you spawn another explorer.exe, the first one has not freed the hotkeys (or terminated; termination closes the window with which the HotKey is associated), hence the second one would just silently fail to register them.

Your options:
-Guess/reverse engineer/auto-obtain the id of the hotkeys of explorer exe (a simple RegisterHotKey proxy dll injected into the newly spawned explorer and preferably any other processes on the new desktop) and then Unregister/reregister them when performing desktop switching.

-write a system-wide window message filtering hook and reroute WM_HOTKEYs to the apropriate windows (probably by using a proxy dll like in the above case to determine the proper hwnd; i don't know whether the window accepting hotkeys in explorer has specific class/window caption, if it does you may possibly avoid the need to use it, at least for explerer)

-{[mad scientist solution]} you could possibly do this without dll hassle through sessions or window stations, but granting input to something other than Winsta0 is veeeery tough and you would certainly need SE_TCB or probably inject something into winlogon and messup with winsta.dll undocumented apis
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question