Dear Rooters' The following test macro can produce a frame with three popup menus: Test, Cancel, Help. I failed to connect them with commands that can be activated by a mouse click. For example, when click "Close", it would not print: "deleteing the windows". I'v tried to use the function "Associate(this)" but it make no sense. Could you tell me what is the problem ? Many thanks Xie ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ * The test macro *: ^^^^^^^^^^^^^^^^^^^ //name: test.c // when running, please do the following steps: // .L test.c // new TestMainFrame(gClient->GetRoot(),400,300); enum values {M_FILE_OPEN, M_FILE_CLOSE, M_FILE_CANCEL, M_FILE_HELP_COMMAND }; class TestMainFrame : public TGMainFrame { private: TGPopupMenu *menuTest, *menuHelp, *menuCancel; TGMenuBar *menubar; public: TestMainFrame(const TGWindow *pp, Uint_t w, Uint_t h); ~TestMainFrame(); Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long parm2); }; TestMainFrame:: ~TestMainFrame() { printf("Deleting those objects ...wait a moment, please ...\n"); delete menuTest; delete menuHelp; delete menuCancel; delete menubar; } TestMainFrame::TestMainFrame(const TGWindow *pp, int w, int h) : TGMainFrame(pp,w,h) { menuTest = new TGPopupMenu(gClient->GetRoot()); menuTest->AddLabel("This is to open the window !!"); menuTest->AddEntry("&Close file ", M_FILE_CLOSE); menuCancel = new TGPopupMenu(gClient->GetRoot()); menuCancel->AddLabel("This is to cancel the window !!"); menuCancel->AddEntry("&cancel ",M_FILE_CANCEL); menuHelp = new TGPopupMenu(gClient->GetRoot()); menuHelp->AddEntry("&help ", M_FILE_HELP_COMMAND); menuHelp->Associate(this); menuCancel->Associate(this); menuTest->Associate(this); TGLayoutHints *barLayout = new TGLayoutHints(kLHintsTop|kLHintsLeft |kLHintsExpandX,0,0,1,1); TGLayoutHints *TestCancel = new TGLayoutHints(kLHintsTop|kLHintsLeft,0,4,0,0); TGLayoutHints *help = new TGLayoutHints(kLHintsTop|kLHintsRight); menubar = new TGMenuBar(this, 1,1, kHorizontalFrame); menubar->AddPopup("&Test ", menuTest, TestCancel); menubar->AddPopup("&Cancel ", menuCancel, TestCancel); menubar->AddPopup("&Help ",menuHelp, help); AddFrame(menubar, barLayout); //----------------------------------------------------------------- MapSubwindows(); Resize(GetDefaultSize()); MapWindow(); } Bool_t TestMainFrame:: ProcessMessage(Long_t msg, Long_t parm1, Long parm2) { switch(GET_MSG(msg)) { case KC_COMMAND: switch(GET_SUBMSG(msg)) { case KCM_MENU: switch(parm1) { case M_FILE_CLOSE: printf("deleteing the windows\n"); delete this; break; default: break; } default: break; } default: break; } return kTRUE; }
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:33 MET