Solved

Launch application inside dialog window

Posted on 2003-11-01
5
416 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
deburging in oracle form 12 88
fizzArray2 challenge 1 72
noX challenge 17 91
Message not shown 5 33
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…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now