Solved

Launch application inside dialog window

Posted on 2003-11-01
5
427 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 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

726 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