#ifndef WIN_H #define WIN_H /////////////////////////////////////////////////////////////// // win.h - simple window utility // // ver 1.0 builds generic windows with little effort // // // // Language: Visual C++, ver 6.0 // // Platform: Micron Dual Pentium Pro 200, WinNT 4.0 // // Application: CSE691 - Software Modeling and Analysis // // Author: Jim Fawcett, CST 2-187, Syracuse Univ. // // (315) 443-3948, fawcett@ecs.syr.edu // /////////////////////////////////////////////////////////////// /* Class Operations: ================= This is a work in progress. It is intended to be a very simple way to create windows from either a console or Win32 application. Right now it is fairly easy to use but you don't have too many options about what goes in a window and how it is displayed. win allows you to put text at fixed pixel locations. You can also write a stream of lines without specifying their locations. win will place them and display all that will fit in the given window. If they all don't fit then just the last ones written are show. In any case, win keeps only a fixed number of lines, determined by setMaxLines function. The default is 35 lines. Each window is create with a static create function (see below) and spawns its own thread. This allows the main thread to con- tinue to service a console window. Public Interface: ================= win *pWin = create("a title",height,width,xCor,yCor); pWin->putText(20,20,"a string to display at (20,20)",false); pWin->putText("a string to display, placed by win"); pWin->setTopMargin(35); // used by putText(const string &s) pWin->setLeftMargin(25); // used by putText(const string &s) int lmarg = pWin->getLeftMargin(); int top = pWin->getTopMargin(); */ // /////////////////////////////////////////////////////////////// // build process // /////////////////////////////////////////////////////////////// // Required files: // // win.h, win.cpp // // // // compiler command: // // cl /GX /MTd /DTEST_WIN win.cpp // /////////////////////////////////////////////////////////////// /* Maintenance History: ==================== ver 1.0 : 19 Apr 2000 - first release */ // #pragma warning(disable : 4786) #include #include #include #include #include #include "resource.h" /////////////////////////////////////////////////////////////// // windows class class win { friend LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam); public: win(const std::string &title="win class", int wd=600,int ht=200,int x=200,int y=200 ); virtual ~win(); static win* create( const std::string &title, int width, int height, int x, int y ); /////////////////////////////////////////////////// // control window void sleep(); // called by client to slow down display HANDLE getHandle(); // usually called only by win functions void run(); // " " " " " static void lock(); // " " " " " static void unlock(); // " " " " " /////////////////////////////////////////////////// // message handlers virtual int handleMenu(WPARAM wParam); virtual void doMouseDisplay(POINT pt); virtual void doPaint(RECT rect); virtual void doLeftButtonDown(); virtual void doRightButtonDown(); virtual void doLeftButtonUp(); virtual void doRightButtonUp(); // /////////////////////////////////////////////////// // mouse and screen stuff RECT& rect(); // save client area POINT& point(); // mouse coordinates std::string& title(); // get/set window title std::string& mouseDisplay(); // display mouse coordinates /////////////////////////////////////////////////// // text functions virtual void putText( int x,int y,const std::string &str,BOOL erase=TRUE ); virtual void putText(const std::string &str); void setTopMargin (int t); void setLeftMargin(int l); int getTopMargin (); int getLeftMargin(); void setMaxLines (unsigned long max); protected: static std::vector _winPtrs; std::deque textBlock; unsigned long maxLines; struct dataItem { std::string text; int x; int y; }; std::vector fixedTextBlock; int _winIndex; HWND hwnd; MSG msg; std::string _title; std::string _mouseDisplay; RECT _rect; POINT _point; int _top, _left, _currY; int sleepTime; private: static CRITICAL_SECTION _winSynch; }; // ///////////////////////////////////////////////////////////////////////// // inline memeber functions inline RECT& win::rect() { return _rect; } inline POINT& win::point() { return _point; } inline std::string& win::title() { return _title; } inline std::string& win::mouseDisplay() { return _mouseDisplay; } inline void win::setTopMargin (int t) { _top = t; } inline int win::getTopMargin() { return _top; } inline void win::setLeftMargin(int l) { _left = l; } inline int win::getLeftMargin() { return _left; } inline void win::setMaxLines(unsigned long max) { maxLines = max; } inline HANDLE win::getHandle() { return hwnd; } inline void win::sleep() { Sleep(sleepTime); } inline void win::lock() { EnterCriticalSection(&_winSynch); } inline void win::unlock() { LeaveCriticalSection(&_winSynch); } #endif