logo
Main Page | Namespaces | Classes | Compounds | Files | Compound Members | Related

main.cpp

00001 //
00002 //  SYNTOPIA. See http://Syntopia.sourceforge.net for details and documentation.        
00003 //
00004 //      Author of this file: Mikael Hvidtfeldt Christensen (mikaelc@users.sourceforge.net)
00005 //
00006 
00007 
00008 
00009 #include <windows.h>
00010 #include "WinForm.h"
00011 #include <string>
00012 #include <math.h>
00013 #include "thread1.h"
00014 
00053 using namespace GUIToolkit;
00054 
00055 
00057 class Window : public EventHandler {
00058         public:
00059                 Window();
00060                 ~Window();
00061                 void MessageLoop();
00062                 void HandleEvents(event ev);
00063         private:
00064                 DWORD WINAPI myThread();
00065                 WinForm * myWindow;
00066                 TextBox * myText ;
00067                 TextBox * myText2 ;
00068                 Button * myButton ;
00069                 Button * myButton2 ;
00070                 Button * myButton3 ;
00071                 MCanvas * myCanvas;
00072 //              DXCanvas * myCanvas2;
00073                 ComboBox * myDropDown;
00074                 ComboBoxItem * i1;
00075                 ComboBoxItem * i2;
00076                 ComboBoxItem * i3;
00077                 ComboBoxItem * i4;
00078                 Label * myLab;
00079                 ScrollBar * myScroll;
00080                 //HINSTANCE hwdn;
00081                 int t;
00082                 bool threadRunning;
00083 };
00084 
00085 Window::Window() {
00086         t =0;
00087         myWindow = new WinForm(500,500,WinForm::standard);
00088         //hwdn = my_hInstance; //?
00089         myText = new TextBox();
00090         myText2 = new TextBox();
00091         myButton = new Button("Calls");
00092         myButton2 = new Button("Start/stop");
00093         myButton3 = new Button("DX JAM");
00094         myDropDown = new ComboBox();
00095         i1 = new ComboBoxItem("Hejsa");
00096         i2 = new ComboBoxItem("Hejsa2");
00097         i3 = new ComboBoxItem("Hejsa3");
00098         i4 = new ComboBoxItem("Hejsa4");
00099         
00100         myScroll = new ScrollBar(0,100,100);
00101 
00102         myLab = new Label("test");      
00103 
00104         myCanvas = new MCanvas();
00105         //myCanvas2 = new DXCanvas(myWindow, 105,130,305,330);
00106 
00107         myText->PutInWinForm(myWindow,0,0,290,100);
00108         myText2->PutInWinForm(myWindow,310,0,290,100);
00109         
00110         myCanvas->PutInWinForm(myWindow, 105,130,200,150);
00111         myButton->PutInWinForm(myWindow,0,120,100,140);
00112         myButton2->PutInWinForm(myWindow,310,120,100,140);
00113         myButton3->PutInWinForm(myWindow,410,120,100,140);
00114         myDropDown->PutInWinForm(myWindow,410,300,100,140);
00115         myScroll->PutInWinForm(myWindow,110,400,200,20);
00116         
00117         myLab->PutInWinForm(myWindow,110,360,200,20);
00118 
00119 
00120         GUIControl::GUIInstance->ErrorTextBox = myText2;
00121 
00122         myDropDown->add(i1);
00123         myDropDown->add(i2);
00124         myDropDown->add(i3);
00125         myDropDown->add(i4);
00126 
00127         myText->setEventHandler(this);
00128         myText2->setEventHandler(this);
00129         myButton->setEventHandler(this);
00130         myButton2->setEventHandler(this);
00131         myButton3->setEventHandler(this);
00132         myDropDown->setEventHandler(this);
00133         
00134         
00135 
00136         myWindow->show();
00137 
00138 }
00139 
00140 void Window::MessageLoop() {
00141         // Enter Loop until Exit.
00142         GUIControl::GUIInstance->MessageLoop();
00143 }
00144 
00145 Window::~Window() {
00146         // Clean Up.
00147         delete(myWindow);
00148 }
00149 
00150 DWORD WINAPI Window::myThread() {
00151         /*
00152         myText->setText( "Thread Started \r\n" +*myText->getText());
00153         while (threadRunning) 
00154         {       
00155                 int temp, temp2, temp3;
00156                 if (myWindow->special == myCanvas) {
00157                         myCanvas->clear();
00158                         for (int tt=1; tt<200; tt++)
00159                         for (int t2=1; t2<200; t2++)
00160                         {   temp = (int) (tt*(t2*t*t)/10000.0) % 255;
00161                                 temp2 = (int) (tt*(t2*t*t)/9000.0) % 250;
00162                                 temp3 = (int) (tt*(t2*t*t)/9500.0) % 200;
00163                                         
00164                                 myCanvas->setPixel(tt,t2, temp, temp2, temp3);
00165                         
00166                         }
00167                         myCanvas->update();
00168                 } else {
00169                         myCanvas2->clear();
00170                         myCanvas2->getDC();
00171 
00172                         //myCanvas2->init();
00173                         for (int tt=1; tt<200; tt++)
00174                         for (int t2=1; t2<200; t2++)
00175                         {   temp = (int) (tt*(t2*t*t)/10000.0) % 255;
00176                                 //temp2 = (int) (tt*(t2*t*t)/9000.0) % 250;
00177                                 //temp3 = (int) (tt*(t2*t*t)/9500.0) % 200;
00178                                         
00179                                 myCanvas2->setPixel(tt,t2, temp, temp, temp);
00180                         
00181                         }
00182                         myCanvas2->releaseDC();
00183                         myCanvas2->update();
00184                 
00185                 }
00186                 
00187                 //myCanvas->setPixel(tt,(int) (cos((tt+t)/50.0)*100.0)+100, 0,0,250);
00188                 //for (int t5=1; t5<200; t5++) myCanvas2->setPixel(t5,(int) (cos((t5+t)/50.0)*100.0)+100, 0,0,250);
00189                          
00190 
00191                  t++; 
00192                 //myCanvas2->update();
00193         }
00194         myText->setText( "Thread Dead \r\n" +*myText->getText());*/
00195         return 0;
00196         
00197 }
00198 
00199 void Window::HandleEvents(event ev) {
00200     if (ev.EventSource==myText2) myText->setText( "TextBox Pressed \r\n"+*myText->getText() );
00201         if (ev.EventSource==myText) myText->setText( "TextBox 2 Pressed \r\n"+*myText->getText() );
00202         if (ev.EventSource==myDropDown) {
00203                 ComboBoxItem * it = myDropDown->getSelected();
00204                 if (it!=0) myText->setText( "Drr Pressed"+ it->Label+ "\r\n"+*myText->getText() );
00205         }               
00206                 
00207         
00208         if (ev.EventSource==myButton) 
00209         {   //MessageBox(ev.hwnd, "a", "MyButton", MB_OK | MB_ICONERROR);
00210                 Window * mitVindue2 = new Window();
00211         /*
00212                   char buffer[33];
00213                 itoa(t,buffer,10);
00214                 std::string * s=new std::string(buffer);
00215                 myText2->setText( "WM PAINT:"+*s); t=0;
00216                 myText->setText( "Button Pressed \r\n" +*myText->getText());
00217                 myCanvas->update();*/
00218                 
00219         }
00220         /*
00221         if (ev.EventSource==myButton2) 
00222         {
00223                 
00224                 //MessageBox(ev.hwnd, myText->getText()->c_str(), "MyButton2", MB_OK | MB_ICONERROR);
00225                 //myCanvas->clear();
00226                 if (threadRunning) {
00227                         myText->setText( "Trying to kill... \r\n"+*myText->getText() );
00228                         threadRunning = false;
00229                 } else {
00230                         myText->setText( "Trying to start... \r\n"+*myText->getText() );
00231                         threadRunning = true;
00232                         MSVC::runInThread(*this, &Window::myThread);
00233                 }
00234                         
00235                 //for (int tt=1; tt<200; tt++) 
00236                 //{ myCanvas->setPixel(tt,50+(int) (50*cos((tt+t)/20.0)), 100, 0,0); }
00237                 //myCanvas->update();
00238                 
00239         }
00240 
00241         if (ev.EventSource==myButton3) 
00242         {
00243                 
00244                 //MessageBox(ev.hwnd, myText->getText()->c_str(), "MyButton2", MB_OK | MB_ICONERROR);
00245                 //myCanvas->clear();
00246                 if (myWindow->special == myCanvas) {
00247                         myText->setText( "Setting to dx... \r\n"+*myText->getText() );
00248                         myWindow->special = myCanvas2;
00249                 } else {
00250                         myText->setText( "Setting to GDI... \r\n"+*myText->getText() );
00251                         myWindow->special = myCanvas;
00252                 }
00253                         
00254                 //for (int tt=1; tt<200; tt++) 
00255                 //{ myCanvas->setPixel(tt,50+(int) (50*cos((tt+t)/20.0)), 100, 0,0); }
00256                 //myCanvas->update();
00257                 
00258         }
00259         
00260         if ((ev.msg == WM_CREATE) || (ev.msg == WM_PAINT))
00261         {       
00262                 //t++;
00263                 //char buffer[33];
00264                 //itoa(t++,buffer,10);
00265                 //std::string * s=new std::string(buffer);
00266                 //if (ev.msg == WM_CREATE) myText2->setText( "WM CREATE \r\n" );
00267                 //if ((ev.msg == WM_PAINT) && (t % 100 == 1)) myText2->setText( "WM PAINT:"+*s);
00268         }
00269         */
00270 }
00271 
00272 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
00273     LPSTR lpCmdLine, int nCmdShow)
00274 {
00275         GUIControl * myGUIControl = new GUIControl(hInstance, nCmdShow);
00276         Window * mitVindue = new Window();
00277         Window * mitVindue2 = new Window();
00278         
00279         myGUIControl->MessageLoop();
00280         delete(mitVindue);
00281         delete(myGUIControl);
00282         // Exit
00283         return 0;
00284 }
00285 

Syntopia Project. Visit the web page, or the SourceForge page.
Docs made by Doxygen. Email: Mikael Christensen