/////////////////////////////////////////////////////////////// // testWin.cpp - test driver for win module // // ver 1.0 // // // // 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 // /////////////////////////////////////////////////////////////// #include #include "win.h" using namespace std; /////////////////////////////////////////////////////////////// // declaration for dWin, derived from win // // - shows how to override message handlers in win class // // to do what your application needs // /////////////////////////////////////////////////////////////// class dWin : public win { public: dWin( const string &title,int wd=600,int ht = 200,int x=200,int y=200 ); virtual void doLeftButtonDown(); virtual void doRightButtonDown(); virtual void doLeftButtonUp(); virtual void doRightButtonUp(); }; //----< constructor >------------------------------------------ dWin::dWin(const string &title, int wd, int ht, int x, int y) : win(title,wd,ht,x,y) {} // //----< handle rigth mouse button down >----------------------- void dWin::doLeftButtonDown() { _textOut = "derived - left button is down"; xOut = yOut = 60; InvalidateRect(hwnd,NULL,TRUE); } //----< handle rigth mouse button down >----------------------- void dWin::doRightButtonDown() { _textOut = "derived - right button is down"; xOut = yOut = 60; InvalidateRect(hwnd,NULL,TRUE); } //----< handle right mouse button Up >------------------------- void dWin::doLeftButtonUp() { _textOut = "derived - left button is up"; xOut = yOut = 60; InvalidateRect(hwnd,NULL,TRUE); } //----< handle right mouse button up >------------------------- void dWin::doRightButtonUp() { _textOut = "derived - right button is up"; xOut = yOut = 60; InvalidateRect(hwnd,NULL,TRUE); } // /////////////////////////////////////////////////////////////// // this is where the thread processing is defined // // for each window // /////////////////////////////////////////////////////////////// struct pArg { win* pWin; pArg() : pWin(NULL) {} }; //----< first window thread procedure >------------------------ unsigned int __stdcall thProc1(void *pArgs) { win win1("test window",450,150,400,200); pArg *ptr = (pArg*)pArgs; ptr->pWin = &win1; win1.run(); return 0; } //----< second window thread procedure >----------------------- unsigned int __stdcall thProc2(void *pArgs) { dWin win2("derived test window",450,150,450,400); pArg *ptr = (pArg*)pArgs; ptr->pWin = &win2; win2.run(); return 0; } // /////////////////////////////////////////////////////////////// // This is where application processing would defined. // // This is simply a demonstration of how to use win. // /////////////////////////////////////////////////////////////// //----< entry point >------------------------------------------ void main() { cout << "\n This is a console application that creates windows!\n\n"; // get pointers to windows from thread function arguments pArg thProcArg1, thProcArg2; win *pWin1 = NULL; // will point to window #1 win *pWin2 = NULL; // will point to window #2 // create threads to handle windows HANDLE th[2]; unsigned int thID[2]; th[0] = (HANDLE)_beginthreadex(NULL,0,thProc1,&thProcArg1,0,&thID[0]); th[1] = (HANDLE)_beginthreadex(NULL,0,thProc2,&thProcArg2,0,&thID[1]); // wait until window pointers have good addresses, set in thread procs while(!pWin1 || !pWin2) { pWin1 = thProcArg1.pWin; pWin2 = thProcArg2.pWin; } // demonstrate writing to the windows try { int i; for(i=0; i<100; i++) { pWin1->putText(60,40," ",FALSE); pWin2->putText(60,40," ",FALSE); Sleep(10); cout << "\n writing strings to each window"; pWin1->putText(60,40,"a string from main",FALSE); pWin2->putText(60,40,"another string from main",FALSE); win* temp = pWin1; pWin1 = pWin2; pWin2 = temp; Sleep(10+10*i); } } catch(...) { MessageBox( NULL, "exception thrown - window written to after closing", "debugging", MB_TOPMOST ); } WaitForMultipleObjects(2,th,TRUE,INFINITE); }