home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / WTJ9403.ZIP / VBX / WINIO.H < prev   
C/C++ Source or Header  |  1993-10-24  |  8KB  |  225 lines

  1. #pragma warning ( disable : 4001 )
  2. /*
  3. WINIO.H
  4. Stdio (e.g. printf) functionality for Windows - definition
  5.  
  6. from "Undocumented Windows" (Addison-Wesley, 1992)
  7. by Andrew Schulman, Dave Maxey and Matt Pietrek.
  8.  
  9. Copyright (c) Dave Maxey and Andrew Schulman 1991-1992. All rights reserved.
  10. */
  11.  
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. /* ==== STDIO.H for Windows ==== */
  16. #include <stdarg.h>
  17. #ifdef __BORLANDC__
  18. /* Borland C++ STDIO.H doesn't do gets, etc. #if defined(_Windows) */
  19. #undef _Windows
  20. #include <stdio.h>
  21. #define _Windows
  22. #else
  23. #include <stdio.h>
  24. #endif
  25.  
  26. #if defined(_MSC_VER) && (_MSC_VER >= 700)
  27. #define main    winio_main
  28. #endif
  29.  
  30. #ifndef MK_FP
  31. #define MK_FP(s,o) ((void far *) (((DWORD) (s) << 16) | (o)))
  32. #endif
  33.  
  34. #undef putchar
  35. #define putchar fputchar
  36. #undef getchar
  37. #define getchar fgetchar
  38. BOOL kbhit(void);
  39.  
  40. /* these were missing from original MSJ version, which assumes inclusion
  41.    of WINDOWS.H as well as WINIO.H.  #ifndef PASCAL is a semi-unreliable
  42.    way to check for inclusion of any vendor's WINDOWS.H */
  43. #ifndef PASCAL
  44. typedef unsigned HANDLE;
  45. typedef unsigned char BYTE;
  46. typedef unsigned WORD;
  47. typedef unsigned BOOL;
  48. typedef unsigned long DWORD;
  49. typedef unsigned HWND;
  50. typedef long LONG;
  51. #define PASCAL pascal
  52. #define FAR far
  53. #endif
  54.  
  55. /* winio_init() must be called before any of the above listed
  56. functions to introduce the app to WINIO. This function should only be
  57. called from WinMain before main() is invoked */
  58. int winio_init(void);
  59.  
  60. /* Signals WINIO that the task is terminating. Makes all windows for the 
  61. task inactive, and allows the user to view and play with
  62. them until double-clicking on the system menu of each to close. Will
  63. only be called from WinMain() upon return from main() */
  64. void winio_end(void);
  65.  
  66. /* closes a window and frees up buffers */
  67. void winio_close(HWND hWnd);
  68.  
  69. /* closes all windows for the app and frees up all buffers. Will usually
  70. only be called by winio_app_exit() which itself is registered via atexit() */
  71. void winio_closeall(void);
  72.  
  73. #define     WW_HASMENU          0x0001 // new window has standard menu
  74. #define     WW_EXITALLOWED      0x0002 // ignored unless WW_HASMENU
  75. #define     WW_STAYSONTOP       0x0004 // window will always overlay parent
  76. #define     WW_OUTPUTONLY       0x0008 // window will not take input
  77.  
  78. /* Creates a new window. strTitle is the initial title. The bufsize
  79. parameter if 0 means default (16k). wFlags are one or more of the
  80. above flags ORed together */
  81. HWND winio_window(LPSTR strTitle, WORD wBufSize, WORD wFlags);
  82.  
  83. /* Tells an app how many windows are still open */
  84. int winio_openwindows(void);
  85.  
  86. /* Sets the current window. This is the window that will be the target
  87. for STDIO calls. Returns the previous current. */
  88. HWND winio_setcurrent(HWND);
  89.  
  90. /* Resizes the output buffer for the specified window. If the BOOL
  91. parameter is FALSE, the buffer cannot be shrunk to smaller than the amount
  92. currently in use. If the BOOL parameter is TRUE, the buffer will be
  93. cleared, and the new size can be anything over 4K. The return value is
  94. the new actual buffer size. */
  95. WORD winio_setbufsize(HWND, WORD, BOOL);
  96.  
  97. /* Sets the default window size (height in high order WORD, width
  98. in low order, both in chars) to have an effect in future
  99. winio_window calls. Returns previous in effect. */
  100. DWORD winio_defwindowsize(DWORD);
  101.  
  102. /* Return the window's output buffer size */
  103. WORD winio_bufsize(HWND);
  104.  
  105. /* Sets the text for the Help About... box which is only present
  106. on the main window - truncated to a maximum of 512 chars. */
  107. void winio_about(char *);
  108.  
  109. /* Sets the text for the specified window. This is here only for consistency
  110. since it is a direct cover on SetWindowText().... */
  111. void winio_settitle(HWND, char *);
  112.  
  113. /* May be SYSTEM_FIXED_FONT (default), ANSI_FIXED_FONT, or OEM_FIXED_FONT */
  114. WORD winio_setfont(HWND, WORD);
  115.  
  116. typedef void (* LINEHANDLER)(HWND, LPSTR, int);
  117.  
  118. /* Sets up a handler for a user double-click. May be cancelled using
  119.     winio_linefn(hwnd, NULL). Returns previous handler...  */
  120. LINEHANDLER winio_setlinefn(HWND, LINEHANDLER);
  121.  
  122. /* To turn automatic updating of window off and on */
  123. BOOL winio_setpaint(HWND, BOOL);
  124.  
  125. /* Goes to top left of window buffer */
  126. void winio_home(HWND);
  127.  
  128. /* Captures the cursor and turns it into an hourglass. Calling this
  129. function repeatedly increments a counter. */
  130. void winio_setbusy(void);
  131.  
  132. /* Decrements the counter incremented above. Returns the cursor to the
  133. arrow when the counter reaches 0. */
  134. void winio_resetbusy(void);
  135.  
  136. /* To change the behavior of getchar(). Note. This is a task global,
  137. because console input is only ever coming from one Window at a time */
  138. BOOL winio_setecho(HWND, BOOL);
  139.  
  140. /* clear out the contents of the buffer and start over fresh */
  141. void winio_clear(HWND);
  142.  
  143. /* Returns the current WINIO window handle */
  144. HWND winio_current(void);
  145.  
  146. /* ==== User definable exit routine ==== */
  147.  
  148. typedef void (* DESTROY_FUNC)(HWND);
  149.  
  150. /* Optional notification function; without it, there is no way for your
  151. application to know if the user has double-clicked the system menu box */
  152. void winio_onclose(HWND, DESTROY_FUNC);
  153.  
  154. /* ==== User definable paint involvement routines ==== */
  155.  
  156. typedef struct {
  157.     POINT dimChar;          // dimensions of a character cell
  158.     POINT posCurr;          // curr pos from top of buffer in chars.
  159.     RECT rectView;          // frame in view from top of buffer in chars.
  160.     long cDiscarded;        // lines discarded from buffer so far
  161.     }   WINIOINFO,
  162.         * PWINIOINFO,
  163.         FAR * LPWINIOINFO;
  164.  
  165.  
  166. typedef BOOL (* PAINT_FUNC)(HWND, HDC, PAINTSTRUCT *, PWINIOINFO);
  167.  
  168. /* Optional paint daemon installation functions; with these, it is
  169. possible to install routines that can prepare the DC on entry, or
  170. redraw some graphics on exit, or whatever. */
  171. PAINT_FUNC winio_onpaintentry(HWND, PAINT_FUNC);
  172. PAINT_FUNC winio_onpaintexit(HWND, PAINT_FUNC);
  173.  
  174. /* To obtain WINIOINFO at non-WM_PAINT times */
  175. void winio_getinfo(HWND, PWINIOINFO);
  176.  
  177.  
  178. /* ==== Utility functions built on message box ==== */
  179.  
  180. BOOL winio_warn(BOOL, char *, const char *, ...);
  181.  
  182. /* fail() is a format/var.args. dialog box and exit routine */
  183. void fail(const char *strFmt, ...);
  184.  
  185. /* ==== STDIO extension function ==== */
  186.  
  187. char *ungets(char *);
  188.  
  189.  
  190. typedef void (* MENU_FUNC)(HWND, int);
  191.  
  192.  
  193. /* The following functions allow submenus to be added to a window's
  194. existing menu, and for handler functions to be registered against new
  195. options. winio_hmenumain returns the handle to the window's main
  196. menu, and winio_hmenufile returns the handle to the window's file
  197. popup menu. The application can then use AppendMenu/InsertMenu to add
  198. additional menus/choices. winio_setmenufunc allows a handler function
  199. to be registered for a menu option id. NOTE that if a menu option id
  200. is not registered with a handler in this way, the app will never know
  201. that the option has been selected... NOTE ALSO that application menu
  202. option IDs must be allocated from 1 thru 32 (giving a total of 32
  203. possible additional menu options per window). */
  204.  
  205. HMENU winio_hmenumain(HWND);
  206.  
  207. HMENU winio_hmenufile(HWND);
  208.  
  209. HMENU winio_hmenuhelp(HWND);
  210.  
  211. MENU_FUNC winio_setmenufunc(HWND, int, MENU_FUNC);
  212.  
  213. // The following are defined in argcargv.c 
  214. extern HANDLE __hInst;
  215. extern HANDLE __hPrevInst;
  216. extern LPSTR __lpCmdLine;
  217. extern int __nCmdShow;
  218. extern HWND __hMainWnd;
  219. extern UINT __hAppTimer;
  220. extern char __szModule[];
  221.  
  222. #ifdef __cplusplus
  223. }
  224. #endif
  225.