Новичок
Профиль
Группа: Участник
Сообщений: 47
Регистрация: 31.1.2008
Где: Москва
Репутация: нет Всего: нет
|
Как получить и обработать события дочернего окна (IdentificatorsOfWindows[1]): Код | //============================================================================================================================================================================================================================================================================================================================================================================================================= #include <iostream> #include <sstream> #include <fstream> #include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/Xos.h> #include <stdio.h> #include <stdlib.h> #include <ctime> #include <string> //============================================================================================================================================================================================================================================================================================================================================================================================================= using namespace std; //============================================================================================================================================================================================================================================================================================================================================================================================================= class TLengthUnit { //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- protected: //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- TLengthUnit *Base; string Title; //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- TLengthUnit (char *Title ); //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- public : //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- friend ostream &operator << (ostream &Stream , TLengthUnit &Unit ); //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- const static TLengthUnit Meter; //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- }; //============================================================================================================================================================================================================================================================================================================================================================================================================= const TLengthUnit TLengthUnit:: Meter ((char *)"м"); //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- TLengthUnit:: TLengthUnit (char *Title ) { this->Base=NULL; this->Title=Title; } //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ostream &operator << (ostream &Stream , TLengthUnit &Unit ) { Stream<<Unit.Title; return Stream; } //============================================================================================================================================================================================================================================================================================================================================================================================================= class TLength { //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- protected: //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- double Value; TLengthUnit *Unit; //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- public : //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- TLength ( ); //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- friend TLength operator * (double Value , const TLengthUnit &Unit ); //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- friend ostream &operator << (ostream &Stream , TLength &Length ); //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- }; //============================================================================================================================================================================================================================================================================================================================================================================================================= TLength :: TLength ( ) { Unit=NULL; } //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- TLength operator * (double Value , const TLengthUnit &Unit ) { TLength Result; Result.Value= Value; Result.Unit =(TLengthUnit *)&Unit; return Result; } //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ostream &operator << (ostream &Stream , TLength &Length ) { Stream<<Length.Value<<" "<<(*Length.Unit); return Stream; } //============================================================================================================================================================================================================================================================================================================================================================================================================= ofstream log("log.txt",ios::app); char ID[257]; TLength l=10.0*TLengthUnit::Meter; //============================================================================================================================================================================================================================================================================================================================================================================================================= bool InitWindow (Display *&PointToDisplay , int &NumberOfScreen , Window *IdentificatorsOfWindows , int Left , int Top , int Width , int Height ); //============================================================================================================================================================================================================================================================================================================================================================================================================= bool SetWindowManager(Display *PointToDisplay , char *ClassOfProgram , char *Arguments[] , int CountOfArguments , Window *IdentificatorsOfWindows , int Left , int Top , int Width , int Height , int MinWidth , int MinHeight , char *Title , char *TitleOfIcon , Pixmap Icon ); //============================================================================================================================================================================================================================================================================================================================================================================================================= void MainLoop (Display *PointToDisplay , Window *IdentificatorsOfWindows ); //============================================================================================================================================================================================================================================================================================================================================================================================================= void SetID ( ); //============================================================================================================================================================================================================================================================================================================================================================================================================= string MyNow ( ); //============================================================================================================================================================================================================================================================================================================================================================================================================= int main (int CountOfArguments , char *Arguments[] ) { Display *PointToDisplay; int NumberOfScreen; Window IdentificatorsOfWindows[2]; SetID(); MyNow(); if (InitWindow(PointToDisplay, NumberOfScreen, IdentificatorsOfWindows, 0 , 0 , 640 , 480)) { if (SetWindowManager(PointToDisplay, (char *)"cspm", Arguments, CountOfArguments, IdentificatorsOfWindows, 0 , 0, 640, 480, 320, 240, (char *)"Complex steel process mashine model", (char *)"Complex steel process mashine model", 0)) { log<<MyNow()<<": complex steel process mashine model (ID="<<ID<<") has started at "<<NumberOfScreen<<"s screen."<<endl; MainLoop (PointToDisplay, IdentificatorsOfWindows); log.close(); return 0; } log.close(); return -2; } log.close(); return -1; } //============================================================================================================================================================================================================================================================================================================================================================================================================= bool InitWindow (Display *&PointToDisplay , int &NumberOfScreen , Window *IdentificatorsOfWindows , int Left , int Top , int Width , int Height ) { PointToDisplay=XOpenDisplay (NULL); if (PointToDisplay) { NumberOfScreen=DefaultScreen(PointToDisplay); IdentificatorsOfWindows[0]=XCreateSimpleWindow (PointToDisplay, RootWindow(PointToDisplay, NumberOfScreen), Left, Top , Width, Height, 1, BlackPixel(PointToDisplay, NumberOfScreen), WhitePixel(PointToDisplay, NumberOfScreen)); IdentificatorsOfWindows[1]=XCreateSimpleWindow (PointToDisplay, IdentificatorsOfWindows[0], 0, Height-16 , Width, 16, 1, BlackPixel(PointToDisplay, NumberOfScreen), WhitePixel(PointToDisplay, NumberOfScreen)); return true; } log<<MyNow()<<": error: point to the display is null (ID="<<ID<<")."<<endl; return false; } //============================================================================================================================================================================================================================================================================================================================================================================================================= bool SetWindowManager(Display *PointToDisplay , char *ClassOfProgram , char *Arguments[] , int CountOfArguments , Window *IdentificatorsOfWindows , int Left , int Top , int Width , int Height , int MinWidth , int MinHeight , char *Title , char *TitleOfIcon , Pixmap Icon ) { XSizeHints SizeOfHints; XWMHints wmOfHints; XClassHint ClassOfHint; XTextProperty WindowName, IconName; if (!XStringListToTextProperty (&Title , 1, &WindowName)|| !XStringListToTextProperty (&TitleOfIcon, 1, &IconName )) { log<<MyNow()<<": memory error (ID="<<ID<<")."<<endl; return false; } SizeOfHints.flags = PPosition | PSize | PMinSize; SizeOfHints.min_width = MinWidth; SizeOfHints.min_height = MinHeight; wmOfHints.flags = StateHint | IconPixmapHint | InputHint; wmOfHints.initial_state = NormalState; wmOfHints.input = true; wmOfHints.icon_pixmap= Icon; ClassOfHint.res_name = Arguments[0]; ClassOfHint.res_class = ClassOfProgram; XSetWMProperties (PointToDisplay, IdentificatorsOfWindows[0], &WindowName, &IconName, Arguments, CountOfArguments, &SizeOfHints, &wmOfHints, &ClassOfHint); return true; } //============================================================================================================================================================================================================================================================================================================================================================================================================= void MainLoop (Display *PointToDisplay , Window *IdentificatorsOfWindows ) { XEvent Report; GC Context; XSelectInput (PointToDisplay, IdentificatorsOfWindows[0], ExposureMask | KeyPressMask); XMapWindow (PointToDisplay, IdentificatorsOfWindows[0]); XMapWindow (PointToDisplay, IdentificatorsOfWindows[1]); while (true) { XNextEvent (PointToDisplay, &Report); switch (Report.type) { case Expose: Context=XCreateGC (PointToDisplay, IdentificatorsOfWindows[0], 0 , NULL); XSetForeground(PointToDisplay, Context, BlackPixel(PointToDisplay, 0)); XFreeGC( PointToDisplay, Context); XFlush(PointToDisplay); break; case KeyPress : break; } } } //============================================================================================================================================================================================================================================================================================================================================================================================================= void SetID ( ) { char *c; char digits[17]="0123456789ABCDEF"; srand(time(NULL)); for (c=ID+255; c>=ID; --c) { *c=digits[rand()%16]; } ID[256]=0; } //============================================================================================================================================================================================================================================================================================================================================================================================================= string MyNow ( ) { char Vavilon[62][3]={"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61"}; time_t rawtime; tm * ptm; string strTime; stringstream out; time (&rawtime); ptm = gmtime (&rawtime); out<<(1900+ptm->tm_year)<<"/"<<(Vavilon[1+ptm->tm_mon])<<"/"<<Vavilon[ptm->tm_mday]<<", "<<Vavilon[ptm->tm_hour]<<":"<<Vavilon[ptm->tm_min]<<":"<<Vavilon[ptm->tm_sec]; getline(out, strTime); return strTime; } //=============================================================================================================================================================================================================================================================================================================================================================================================================
|
?
|