Click here to Skip to main content
15,883,825 members
Articles / Desktop Programming / MFC
Article

Three Windows Demo

Rate me:
Please Sign up or sign in to vote.
2.29/5 (8 votes)
18 Apr 20042 min read 36K   1K   15   1
Creates other processes (windows).

Image 1

Introduction

This demo shows how to create a process to open a second window and pass data and Windows messages to the second window. The CreateProcess() function can either start a module or start a command line module. You could, for example, open a new command line window "notepad.exe", and pass it command line arguments.

This demo uses both interfaces. The code for this can be found in: ConsoleDemo.cpp. It is constructed before the dialog box is opened. The module now has to be tied to a CWnd pointer, this is done with the "FindWindow()" function. FindWindow will try to point to a window that matches the window title of the module. Now that we have a pointer initialized, we can pass it data using WM_COPYDATA Windows message. MyWindow is a Win32 Application only because I needed a message handler, you could use a Win32 Console Application and pass it command line arguments only.

Command.exe is the third window, it's a simple application that processes only command line information and calls system() function. ConsoleDemo has four commands:

  1. "new" causes the other window to be redrawn using a custom WM_USER message.
  2. "exit" which first closes the other window and then closes itself.
  3. "dir" displays the current directory and,
  4. "ver" displays the Windows version which are command line arguments.

Command.exe waits for the user to press any key and closes itself. Note: when you drag or resize ConsoleDemo's dialog box, the other window is sent WM_ERASEBKGND message, then you can use the "new" command to invalidate its window. All three modules have a post-build step that copies its Release executable to the ConsoleDemo directory.

*** VERY IMPORTANT *** ConsoleDemo is looking for the other two windows to be in the same directory as ConsoleDemo, therefore you must do a Release Build of MyWindow and Command before running ConsoleDemo. Any comments are welcome.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Michael Haephrati25-Jan-13 5:09
professionalMichael Haephrati25-Jan-13 5:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.