Solved

Launch application inside dialog window

Posted on 2003-11-01
5
423 Views
Last Modified: 2013-11-20
I'm trying to preview a screensaver inside a dialog window (much like the preview inside the Display Properties).  I need to launch the Screensaver with the arguments "/p ####", where #### is the HWND of the window to launch in (I'm just wanting to launch it in an MFC text control).  I can do the provew with my own screensaver that I wrote (I've got the CWnd class), but I want to actually launch an executable in there.  I've tried ShellExecute and CreateProcess without luck, but I dont know how to translate the HWND to the command line.  Any help?
0
Comment
Question by:lakers2003
  • 3
5 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 9663583
You can use Format function to convert HWND to string:
CString s;
s.Format(_T("%x"), (int)hWnd);

Inside of screen saver, if you have, for example, command line parameter "A56B", you can extract it from string:

int n;
_stscanf(sParameter, _T("%x"), &n);
HWND hWnd = (HWND)(DWORD)n;
0
 
LVL 12

Accepted Solution

by:
migel earned 500 total points
ID: 9663587
Hi!
as MSDN say:
<HWND> is a HWND presented on the command line as an unsigned decimal number.
so you can just use wsprintf to get this:
for example
TCHAR tchCmdLine[_MAX_PATH];
wsprintf(tchCmdLine, _T("/p %u"), m_hWnd);
0
 

Author Comment

by:lakers2003
ID: 9663821
That doesn't seem to work, this is what I'm doing:

HWND prevHwnd=(HWND)::GetDlgItem((HWND)AfxGetMainWnd(),(int)GetDlgItem(IDC_PREVIEW));
      
CString s;
s.Format((_T("%x"), (int)prevHwnd));

CString m_ssProcess = "C:\\WINDOWS\\system32\\sspipes.scr /p ";
    BOOL cres=CreateProcess(m_ssProcess,NULL,0,0,FALSE,            CREATE_NEW_PROCESS_GROUP|CREATE_DEFAULT_ERROR_MODE,0,"C:\\WINDOWS\\system32",&si,&pi);
0
 

Author Comment

by:lakers2003
ID: 9663836
The code fails before it gets to the CreateProcess block.
0
 

Author Comment

by:lakers2003
ID: 9663912
Ok, I think migel's solution worked to get the HWND, but do I need to set any other parameters to preview the screen saver in the dialog window?  IDC_PREVIEW is the id of the TextControl I want the preview to appear in.  Now my CreateProcess is failing...

HWND prevHwnd=::GetDlgItem(this->GetSafeHwnd(), IDC_PREVIEW);

TCHAR tchCmdLine[_MAX_PATH];
wsprintf(tchCmdLine, _T("/p %u"),prevHwnd);
CString s(tchCmdLine);
CString m_ssProcess = "C:\\WINDOWS\\system32\\sspipes.scr " + s;

BOOL cres=CreateProcess(m_ssProcess,NULL,0,0,FALSE,
            NULL,0,"C:\\WINDOWS\\system32",&si,&pi);
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand to include initial dialog with two choices. 9 85
How to determine file rename from EventLog ? 2 57
scoreUp challenge 14 69
Message not shown 5 82
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

713 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