Solved

Windows Desktop API - windows shortcuts on the correct Desktop ?

Posted on 2007-03-23
9
1,180 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
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 11

Expert Comment

by:DeepuAbrahamK
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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:DeepuAbrahamK
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 500 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

773 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