home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / d / d020_1_4 / 6.ddi / TTY / WSTDIO.TXT < prev   
Encoding:
Text File  |  1990-06-01  |  5.3 KB  |  135 lines

  1. WSTDIO.C
  2.  
  3. Functions for managing a stdio window
  4.  
  5. The routines in this module provide a set of functions to enable the easy
  6. creation and use of a "standard i/o" window. The idea is to provide an
  7. easy way to display debugging, or other types of simple textual,
  8. information in a window. They could also be used for the initial porting
  9. of some simple utilities to Windows.
  10.  
  11. To use this library of routines:
  12.  
  13.  1. Link this module with your application.
  14.  2. At the start of your application, call stdioInit(). This registers
  15.     the stdio window class.
  16.  3.a. [optional] Call CreateStdioWindow() to create a stdio window. This
  17.       can be an overlapped window, popup, or child window.
  18.  3.b. [optional] Call wopen() to create a stdio window. This creates an
  19.       overlapped window for stdio output.
  20.  4. Call wputs(),..., to display text in the stdio window. If the stdio
  21.     window hasn't been created already, using 3.a or 3.b, then wputs()
  22.     will call wopen() to create the window.
  23.  
  24. Notes:
  25. The stdio library is currently written to only allow one stdio window
  26. in a given instance of an application. It could be modified to allow for
  27. more, but that would entail some additional complexity for the programmer
  28. to create the window. The intent here is to provide the ability to very
  29. easily send some text to a window for debugging, etc.
  30. Obviously, this isn't a full emplementation. It could use a wprintf, putchar,
  31. etc. It could also use some input functions, ie. wgets, wgetchar, wscanf, etc.,
  32. but this is a start.
  33.  
  34.  
  35. The API:
  36.  
  37. BOOL stdioInit(hInstance)   - Registers the stdio window class.
  38.  
  39.     HANDLE hInstance        - The instance handle of the application.
  40.  
  41.     return value:   TRUE if the class registered successfully,
  42.                     FALSE otherwise.
  43.  
  44. HWND wopen(hWndParent,bQuit)- Create a default overlapped stdio window.
  45.  
  46.     HWND hWndParent         - The handle of the parent window.
  47.     BOOL bQuit              - TRUE: quit application on stdio window close
  48.                             - FALSE: just close stdio window
  49.  
  50.     return value:   A window handle if the window is created successfully,
  51.                     NULL if a window couldn't be created.
  52.     Comments:
  53.         A Windows application must call PostQuitMessage() to tell Windows
  54.         it is going to be quiting. If it doesn't, memory and resources that
  55.         are associated with the application may not be freed, even though
  56.         all of the windows have been closed and the application has quit.
  57.         Be sure that you have a main window that calls PostQuitMessage when
  58.         it ends. If the stdio window is the only window, then set bQuit to
  59.         TRUE.
  60.  
  61. HWND CreateStdioWindow(LPSTR,DWORD,int,int,int,int,HWND,HANDLE,BOOL)
  62.     LPSTR lpWindowName      - String to display at the top of the window.
  63.     DWORD dwStyle           - Styles to use for the window.
  64.     int X                   - X window position.
  65.     int Y                   - Y window position.
  66.     int nWidth              - Window width.
  67.     int nHeight             - Window height.
  68.     HWND hWndParent         - Handle of parent window.
  69.     HANDLE hInstance        - Instance handle.
  70.     BOOL bQuit              - TRUE: quit application on stdio window close.
  71.                             - FALSE: just close stdio window.
  72.     return value:   A window handle if the window is created successfully,
  73.                     NULL if a window couldn't be created.
  74.     Comments:
  75.         See comments for wopen().
  76.         Except bQuit, the parameters are a subset of the parameters for the
  77.         standard Windows CreateWindow() function. See the Windows SDK 
  78.         Programmer's Reference for more information.
  79.  
  80. BOOL wputs(lpString)        - Displays the string in the stdio window.
  81.  
  82.     LPSTR lpString          - A long pointer to the string to be displayed.
  83.  
  84.     return value:   TRUE if the text was successfully displayed,
  85.                     FALSE if the text couldn't be displayed - this means
  86.                     the stdio window doesn't exist.
  87.     Comments:
  88.         wputs() will call wopen() if the stdio window doesn't yet exist. It
  89.         calls: wopen(NULL,FALSE); See the note about PostQuitMessage below 
  90.         the description of wopen(). If your application doesn't have a main
  91.         window, ie. the stdio window is the only window, create the window
  92.         using: wopen(NULL,TRUE); or CreateStdioWindow(...,TRUE);
  93.         wputs() doesn't currently handle '\n' the same as normal stdio
  94.         puts() and printf() functions. '\n' normally behaves as '\r\n'.
  95.         '\r\n' should be sent explicitely to wputs().
  96.  
  97. The following is the "Hello World!" program using these functions:
  98.  
  99. // Test.c
  100. //
  101. // A simple test of the WSTDIO library
  102.  
  103. #include "win.h"
  104. #include "winexp.h"
  105. #include "wstdio.h"
  106. #include "test.h"
  107.  
  108. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  109. HANDLE hInstance, hPrevInstance;
  110. LPSTR lpszCmdLine;
  111. int cmdShow;
  112. {
  113.     if(!stdioInit(hInstance)) return FALSE;
  114.  
  115.     wopen(NULL, TRUE);
  116.  
  117.     wputs("Hello World!\r\n");
  118.  
  119.     return MsgLoop();
  120. }
  121.  
  122. int MsgLoop()
  123. {
  124.     MSG msg;
  125.  
  126.     /* Polling messages from event queue */
  127.     while (GetMessage((LPMSG)&msg, NULL, 0, 0)) {
  128.         TranslateMessage((LPMSG)&msg);
  129.         DispatchMessage((LPMSG)&msg);
  130.         }
  131.  
  132.     return (int)msg.wParam;
  133. }
  134.  
  135.