Click here to Skip to main content
15,886,693 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am in Windows 7 and I need to be able to launch a control panel item from MFC. The path I'm interested in is:

"Control Panel\Programs\Default Programs\Set Default Programs"

I can launch the "Default Programs" ("Control Panel\Programs\Default Programs") page by using this code:

C++
CString sExe("control.exe");
CString sArg(" /name Microsoft.DefaultPrograms");
int nRetVal = (int) ::ShellExecute(this->m_hWnd, _T("open"), sExe, sArg, NULL, SW_SHOW);

But this requires user to click one more time to go to "Set Default Programs" page.
I would like to directly go to the "Set Default Programs" page. How can I do this?

Thank you.


--------------------------------------------------------------------------------

Mizan Rahman
Posted

I think you'll find that the page you're presented with is _a part_ of the Microsoft.DefaultPrograms applet. That is to say, I think for this to happen (in a non hackish way) you would
(a) need to be able to pass a command-line option to the applet
(b) for the applet to process these arguments
(c) for control.exe to correctly use it's argument "/name" in addition to passing the option to the applet.

In short, it doesn't seem likely, nor does there appear to be any reference for it that I can find.

I was going to suggest using spy++ to get the HWND of the static you need to click on to get to the page you want. Only problem is, the entire pane is a single HWND with the class of "DirectUIHWND"

You could (I suppose) measure the position of the link with a paint program, then use the mouse_event function to send (fake) mouse movement/click messages to the parent (DirectUIHWND)
This would be what I referred to earlier as a hackish way. Nasty, but the method does work in general, I've seen MineSweeper-playing programs before - get pos of window, get board dimensiobs, get data that represents bomb positions. Then, use mouse_event 3 times for each 'safe' square.
(1) Move to the centre of it
(2) Left button down
(3) Left button up

Oh! Just had a second look - the right-hand pane has the class I mentioned. BUT so does the entire 'client' area of the control-panel. I.e There's a window that contains the left pane and the right pane. The class of this window is DirectUIHWND. A _child_ of this window is the right pane. It's class is also DirectUIHWND.

So, you'd have to get all windows with that class name. You'd then have to discard the window that isn't the child of a window whose class name is also DirectUIHWND. Obviously, this approach relies on there only being 2 active instances of a window with said class-name.
 
Share this answer
 
Under Windows 7 you can call
C++
_tsystem (_T("control /name Microsoft.DefaultPrograms"));

For a full list of all control applets see:
http://pcsupport.about.com/od/tipstricks/tp/control-panel-applets-list.01.htm[^]
 
Share this answer
 
Comments
Mizan Rahman 25-Oct-13 6:26am    
I do call this. But this does not take me to the page I am interested in. Please read the original question.
Hi,

I got the solution from here:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/c11c1760-c72e-45f3-8d29-28c80b937d6f/how-can-i-launch-set-default-programs-from-mfc?forum=vclanguage[^]

Basically this what I needed:
C++
CString sExe("control.exe");
CString sArg(" /name Microsoft.DefaultPrograms /page pageDefaultProgram");
int nRetVal = (int) ::ShellExecute(this->m_hWnd, _T("open"), sExe, sArg, NULL, SW_SHOW);

The thing is that the pageDefaultProgram value is undocumented. Thanks to Microsoft I wasted many hours on this, because Microsoft decided not document it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900