65.9K
CodeProject is changing. Read more.
Home

Three Windows Demo

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.29/5 (8 votes)

Apr 19, 2004

2 min read

viewsIcon

36300

downloadIcon

1042

Creates other processes (windows).

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.