[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Launch application inside dialog window

Posted on 2003-11-01
5
Medium Priority
?
430 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
[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
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 1500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

656 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