![]() |
How to indicate a dialog on the WSEV_EXIT event procedureThere is the case to need to save data indicate a dialog whether to finish the application, when the application is finished by closing the window. In such a case it is convenient to use the WSEV_EXIT event procedure of the WSCwindow/WSCmainWindow class.The WSCwindow/WSCmainWindow class generates the WSEV_EXIT trigger when the window is disappeared before finishing the application. At first set True to the property WSNexit of a WSCwindow/WSCmainWindow instance which is used as main window in the application, and put an event procedure to it with WSEV_EXIT trigger. We will try to make an event procedure to have the following facility. #include <WScom.h> #include <WSCfunctionList.h> #include <WSCbase.h> //---------------------------------------------------------- //Function for the event procedure //---------------------------------------------------------- #include <WSCmessageDialog.h> #include <WSDtimer.h> //The timer procedure which redisplay the window. void delayproc(unsigned char,void* ptr){ WSCbase* object = (WSCbase*)ptr; object->setVisible(True); } //EXIT event procedure //Indicates a dialog. void exit_ep(WSCbase* object){ if (object->getVisible() != False){ return; } WSCmessageDialog* msg = WSGIappMessageDialog(); //A msg->setProperty(WSNwidth,500); msg->setProperty(WSNno,True); msg->setProperty(WSNdefaultPosition,True); msg->setProperty(WSNlabelString, "Exit and save data?\n If you do not want to save and exit,push NO..."); //Indicates the dialog. long ret = msg->popup(); //B if (ret == WS_DIALOG_OK){ //When OK is selected.. C //saving some data ... exit(0); }else if (ret == WS_DIALOG_NO){ //When NO is selected.. D exit(0); }else if (ret == WS_DIALOG_CANCEL){ //When CANCEL is selected.. E WSGIappTimer()->addTriggerProc(delayproc,WS250MS,object); } } static WSCfunctionRegister op("exit_ep",(void*)exit_ep);Get the instance of the message dialog (A),indicate it (B). Check the result of the dialog (C)(D)(E). It need to execute delayed procedure to redisplay the window, because it is required that the exit event is done before the window be redisplayed. ![]() [The exit dialog] Document Release 3.0 For Use with Wide Studio Release 3.0, Summer 2002
|