Solved

Launch application inside dialog window

Posted on 2003-11-01
5
412 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
The code fails before it gets to the CreateProcess block.
0
 

Author Comment

by:lakers2003
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
bobThere java chalenge 45 82
Hibernate methods 2 58
countEvens challenge 2 57
sum13 challenge 24 77
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

13 Experts available now in Live!

Get 1:1 Help Now