Solved

Windows Desktop API - windows shortcuts on the correct Desktop ?

Posted on 2007-03-23
9
1,185 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: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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

630 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