home *** CD-ROM | disk | FTP | other *** search
- WSTDIO.C
-
- Functions for managing a stdio window
-
- The routines in this module provide a set of functions to enable the easy
- creation and use of a "standard i/o" window. The idea is to provide an
- easy way to display debugging, or other types of simple textual,
- information in a window. They could also be used for the initial porting
- of some simple utilities to Windows.
-
- To use this library of routines:
-
- 1. Link this module with your application.
- 2. At the start of your application, call stdioInit(). This registers
- the stdio window class.
- 3.a. [optional] Call CreateStdioWindow() to create a stdio window. This
- can be an overlapped window, popup, or child window.
- 3.b. [optional] Call wopen() to create a stdio window. This creates an
- overlapped window for stdio output.
- 4. Call wputs(),..., to display text in the stdio window. If the stdio
- window hasn't been created already, using 3.a or 3.b, then wputs()
- will call wopen() to create the window.
-
- Notes:
- The stdio library is currently written to only allow one stdio window
- in a given instance of an application. It could be modified to allow for
- more, but that would entail some additional complexity for the programmer
- to create the window. The intent here is to provide the ability to very
- easily send some text to a window for debugging, etc.
- Obviously, this isn't a full emplementation. It could use a wprintf, putchar,
- etc. It could also use some input functions, ie. wgets, wgetchar, wscanf, etc.,
- but this is a start.
-
-
- The API:
-
- BOOL stdioInit(hInstance) - Registers the stdio window class.
-
- HANDLE hInstance - The instance handle of the application.
-
- return value: TRUE if the class registered successfully,
- FALSE otherwise.
-
- HWND wopen(hWndParent,bQuit)- Create a default overlapped stdio window.
-
- HWND hWndParent - The handle of the parent window.
- BOOL bQuit - TRUE: quit application on stdio window close
- - FALSE: just close stdio window
-
- return value: A window handle if the window is created successfully,
- NULL if a window couldn't be created.
- Comments:
- A Windows application must call PostQuitMessage() to tell Windows
- it is going to be quiting. If it doesn't, memory and resources that
- are associated with the application may not be freed, even though
- all of the windows have been closed and the application has quit.
- Be sure that you have a main window that calls PostQuitMessage when
- it ends. If the stdio window is the only window, then set bQuit to
- TRUE.
-
- HWND CreateStdioWindow(LPSTR,DWORD,int,int,int,int,HWND,HANDLE,BOOL)
- LPSTR lpWindowName - String to display at the top of the window.
- DWORD dwStyle - Styles to use for the window.
- int X - X window position.
- int Y - Y window position.
- int nWidth - Window width.
- int nHeight - Window height.
- HWND hWndParent - Handle of parent window.
- HANDLE hInstance - Instance handle.
- BOOL bQuit - TRUE: quit application on stdio window close.
- - FALSE: just close stdio window.
- return value: A window handle if the window is created successfully,
- NULL if a window couldn't be created.
- Comments:
- See comments for wopen().
- Except bQuit, the parameters are a subset of the parameters for the
- standard Windows CreateWindow() function. See the Windows SDK
- Programmer's Reference for more information.
-
- BOOL wputs(lpString) - Displays the string in the stdio window.
-
- LPSTR lpString - A long pointer to the string to be displayed.
-
- return value: TRUE if the text was successfully displayed,
- FALSE if the text couldn't be displayed - this means
- the stdio window doesn't exist.
- Comments:
- wputs() will call wopen() if the stdio window doesn't yet exist. It
- calls: wopen(NULL,FALSE); See the note about PostQuitMessage below
- the description of wopen(). If your application doesn't have a main
- window, ie. the stdio window is the only window, create the window
- using: wopen(NULL,TRUE); or CreateStdioWindow(...,TRUE);
- wputs() doesn't currently handle '\n' the same as normal stdio
- puts() and printf() functions. '\n' normally behaves as '\r\n'.
- '\r\n' should be sent explicitely to wputs().
-
- The following is the "Hello World!" program using these functions:
-
- // Test.c
- //
- // A simple test of the WSTDIO library
-
- #include "win.h"
- #include "winexp.h"
- #include "wstdio.h"
- #include "test.h"
-
- int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
- HANDLE hInstance, hPrevInstance;
- LPSTR lpszCmdLine;
- int cmdShow;
- {
- if(!stdioInit(hInstance)) return FALSE;
-
- wopen(NULL, TRUE);
-
- wputs("Hello World!\r\n");
-
- return MsgLoop();
- }
-
- int MsgLoop()
- {
- MSG msg;
-
- /* Polling messages from event queue */
- while (GetMessage((LPMSG)&msg, NULL, 0, 0)) {
- TranslateMessage((LPMSG)&msg);
- DispatchMessage((LPMSG)&msg);
- }
-
- return (int)msg.wParam;
- }
-
-