Author
|
Topic: Strange Modal form behaviour
|
Russ Srole Member
|
posted 01-14-2003 04:44 AM
Chris,I ran into an odd one today. I have a main form with a listview. I put in some code so that if the user clicks on a particular cell in the listview, I bring up a modal form with a rich text box, so they can edit a note. So far, so good - everyting works as I planned. Then, just for grins I added the same feature (to pull up the edit form) to a popup menu. I click on the popup menu & click on the "edit Note" item, which calls the same subroutine to display the form. The edit note form is displayed, the rich text box is filled with the correct info & then it's over. I can't close the edit note form with the little x, or move the form or anything else. It's ctrl/alt/del time to bring up the task manager & close the app down. If I change the form to modaless then the problem goes away, but I need it to be modal. I stumbled on a work around, but it's really ugly - code:
KeyBd_event %vk_esc, 0,0,0 SLEEP 1 KeyBd_event %vk_esc, 0,%KEYEVENTF_KEYUP,0 SLEEP 1 MsgBox "",,""
Why this works, I don't know, but it's way to nutty to leave it in. This is under Win98, I haven't had a chance to explore this under Win2k.Any thoughts? Thanks, Russ Srole |
Chris Boss Administrator
|
posted 01-14-2003 09:13 AM
Russ;It sounds like the PopUp Menu may be the problem ! PopUp Menus must take the mouse focus (capture) from the parent form and when you display a Modal form Windows may get confused as far as who has the mouse captured. Windows will want to return the focus back to the popup menus parent form, but your modal form is disabling it. This is the only thing I can think of. Maybe you should try to Post a Message to the Parent form which makes the modal form display by a direct call. This way Windows has a chance to clean things up as far as focus/mouse capture when the popup menu disappears, before the modal form is displayed. Use the PostMessage API function and send the parent form the %WM_COMMAND message to emulate a mouse click.
|
Russ Srole Member
|
posted 01-14-2003 12:09 PM
Chris,It sounds resonable to me. I'll give that a try. BTW, it does the same thing in Win2k. I'll report back later, Thanks, Russ |
Glen Martin Member
|
posted 01-14-2003 04:34 PM
RussI assume you must use the main form for the parent of the form with the rich edit control. Are you using the same parent when you call it from the menu? That would explain why it won't work. Glen |
Russ Srole Member
|
posted 01-15-2003 10:26 AM
Chris,I tried to post the wm_command w/ wParam = 0 and lParam = 0... No luck. Glen, The parent is always the main form. I guess I don't quite understand where you're going here. Should the parent be the popupmenu? And if that's the case, how do I do that, since there's no name for it? It would explain why my silly trick of sending an esc keypress works (I think). Thanks, Russ |
Chris Boss Administrator
|
posted 01-15-2003 12:45 PM
Russ;The parameters have to be set correctly for WM_COMMAND Here is how to do it: code:
PostMessage EZ_Handle("Form1",0), %WM_COMMAND, MKWRD(%Form1_Button1ID, %BN_CLICKED), EZ_Handle("Form1", %Form1_Button1ID)
This will post a message to a Button control which will generate an %EZ_Click event for the button.
|
Glen Martin Member
|
posted 01-15-2003 08:37 PM
RussSorry! I was thinking that you might be calling the procedure from a popup menu on another form. Glen |
Russ Srole Member
|
posted 01-16-2003 01:22 AM
Chris,I see now, but I don't have a button the the form for the function, it's either called by a right click on the popup menu or a double click on the listview. I suppose I could have it click on a label and have the click event do nothing, just to get rid of the popup menu. I'll give that a try. Glen - thanks for the thought. Thanks, Russ |
Eddy Van Esch Member
|
posted 01-16-2003 04:15 AM
Just an idea: - Let the click on the popup menu activate a timer of about 500ms, nothing more. - Popup menu disappears, - Intercept the timer event (after 500ms or so) and let THAT event create your modal edit box. By the time your edit box appears, the popup menu will be gone.. - Kill the timer ofcourse..Worth a try? Kind regards Eddy
|
Chris Boss Administrator
|
posted 01-16-2003 09:50 AM
Russ;You can use the following code to generate an %EZ_Click event for a non-existing control using: code:
MyCVal&=1 ' or any value you want PostMessage EZ_Handle("Form1",0), %WM_COMMAND, MKWRD(%Form1_Button1ID, MyCVal&), 0
The %EZ_Click event will be generated for whatever control ID you choose. There doesn't need to be a control in this case, since EZGUI checks the last parameter of the %WM_COMMAND message to see if a control handle is passed. If as in this case the value is zero, then EZGUI defaults to an %EZ_Click event for the ID. No control is needed. |
Russ Srole Member
|
posted 01-16-2003 10:10 AM
Guys,I'm sure one of these will work. I won't get to it till later today, but I'll give them a try. Thanks, Russ |
Russ Srole Member
|
posted 01-17-2003 10:15 AM
Hmmmmm, I tried all of the above, but the problem is still there. Over the weekend I'll make a small sample & post it.Thanks, Russ |
Frank Kelley Member
|
posted 06-08-2007 04:24 PM
Was a resolution of this issue ever found?I'm working on a small program that uses the same approach as Russ' original program. When a procedure is called from within a program via a button click, everything works fine. If the same procedure is called via a popup menu, the procedure locks up, requiring a visit to Task Manager to force the program to shut down. Specifically, the procedure being called displays a modal form for user input. After input is complete, the modal form freezes solid (nothing works) when it is called from the popup menu. I've tried variations on EZ_PostMessage, as outlined above, with no success. Very puzzling! ADDED: I did check the name of the parent form calling the problem dialog and the name is correct. It appears the problem arises when a "normal" form calls a modal form, which in turn calls another modal form via a right-click menu. [This message has been edited by Frank Kelley (edited 06-08-2007).] |
Chris Boss Administrator
|
posted 06-08-2007 05:04 PM
There must be more to this problem than meets the eye. The EZGUI Visual Designer displays modal forms via clicks on items in a popup menu (right click menu). It works perfectly and never locks up. It is possible that if you are attempting to display a popup menu via a click event (occurs when mouse button is down) that could cause some problems. The focus changes between the mouse button down and then up, which may make Windows a little confused. This is just a guess, but it is worth investigating. You could post an event during the click event and then display the popup menu in the %EZ_Post event. You could also subclass the control and process the %EZ_LButtonUp event, instead of the click event. Set a global variable in the click event to store the row number and then display the popup menu in the %EZ_LButtonUp event after it. The point is that popup menus should be displayed on the mouse button up action, rather than a mouse button down (which click events are).
|
Frank Kelley Member
|
posted 06-08-2007 06:49 PM
There's nothing quite as effective as a demonstration.The following code is a simple program that illustrates the problem with the popup menu. Compile and run the code and when the main form displays, click on the "Show Treeview" button. The Treeview is displayed on a modal dialog. On this second dialog, click the "Add an Item to the Treeview" button to display another modal dialog. Enter some text in the edit box on this dialog and click OK. The text you entered will be added to the Treeview. All is well. Now, right click on the Treeview to display the popup menu and select the only option, "Add Item to Treeview". The popup menu calls the very same code to add text to the Treeview...but you won't get that far. The program locks up tighter than a drum on both my Win XP desktop (SP2) and Win 2k laptop. You will have to resort to the Task Manager to shut down the program. Any fixes are gladly welcome. code:
' ************************************************************************************* ' Code Generated by EZGUI Visual Designer 4.0 ' Portions: Copyright Christopher R. Boss, 2003 to 2006 ' All Rights Reserved ! ' Registered EZGUI 4.0 users may use this code Royalty Free ! ' ************************************************************************************* ' ' -------------------------------------------------------- ' WARNING ! Do Not Modify any code WITHIN Protected Sections ! ' You can add code (Sub,Function,etc.) BEFORE any Protected Routine ' by using the following CODE TAGS: '<<SAVE>> '<<END>> ' and the Designer will not remove it. ' --------------------------------------------------------' ====================================== ' [PROTECTED CODE] Do NOT Edit ! ' ====================================== ' #COMPILE EXE #DIM ALL ' This is helpful to prevent errors in coding ' ------------------------------ ' Enable all constants below to ' customize maximums in EZGUI ' runtime. ' ------------------------------ ' %EZGUI_MaxColors = 800 ' %EZGUI_MaxFonts = 800 ' %EZGUI_MaxImages = 300 ' %EZGUI_MaxControls = 1500 ' %EZGUI_MaxForms = 150 ' %EZGUI_MaxMenus = 200 ' ------------------------------ ' -------------------- #INCLUDE "C:\ezgui40pro\includes\ezgui40.inc" ' EZGUI Include file for Declares ' -------------------- ' ************************************************************************************* ' ************************************************************************************* ' Code Generator Defined Constants and Declares ' ************************************************************************************* DECLARE FUNCTION Main_Initialize(BYVAL VerNum&) AS LONG DECLARE SUB OtherForm_Events(FormName$, CID&, CMsg&, CVal&, Cancel&) DECLARE SUB OtherForm_Design(FormName$) DECLARE FUNCTION PreProcess_Events(FormName$, CID&, CMsg&, CVal&, Cancel&) AS LONG DECLARE SUB EZ_F1_Display(BYVAL Parent$) DECLARE SUB EZ_F1_Design() DECLARE SUB EZ_F1_ParseEvents(CID&, CMsg&, CVal&, Cancel&) DECLARE SUB F1_Events(CID&, CMsg&, CVal&, Cancel&) ' ------------------------------------------------ %F1_TVBTN = 100 %F1_CLOSEBTN = 105 DECLARE SUB F1_TVBTN_Events(MyID&, CMsg&, CVal&, Cancel&) DECLARE SUB F1_CLOSEBTN_Events(MyID&, CMsg&, CVal&, Cancel&) DECLARE SUB EZ_F2_Display(BYVAL Parent$) DECLARE SUB EZ_F2_Design() DECLARE SUB EZ_F2_ParseEvents(CID&, CMsg&, CVal&, Cancel&) DECLARE SUB F2_Events(CID&, CMsg&, CVal&, Cancel&) ' ------------------------------------------------ %F2_TV = 100 %F2_ADDBTN = 105 %F2_CLOSEBTN = 110 DECLARE SUB F2_TV_Fill(BYVAL Mode&) DECLARE SUB F2_TV_Events(MyID&, CMsg&, CVal&, Cancel&) DECLARE SUB F2_TV_SubClass(BYVAL CVal&, Cancel&) DECLARE SUB F2_ADDBTN_Events(MyID&, CMsg&, CVal&, Cancel&) DECLARE SUB F2_CLOSEBTN_Events(MyID&, CMsg&, CVal&, Cancel&) DECLARE SUB EZ_F3_Display(BYVAL Parent$) DECLARE SUB EZ_F3_Design() DECLARE SUB EZ_F3_ParseEvents(CID&, CMsg&, CVal&, Cancel&) DECLARE SUB F3_Events(CID&, CMsg&, CVal&, Cancel&) ' ------------------------------------------------ %F3_ITEMTXT = 100 %F3_OKBTN = 105 %F3_CANCELBTN = 110 %F3_FRAME1 = 115 DECLARE SUB F3_ITEMTXT_Events(MyID&, CMsg&, CVal&, Cancel&) DECLARE SUB F3_OKBTN_Events(MyID&, CMsg&, CVal&, Cancel&) DECLARE SUB F3_CANCELBTN_Events(MyID&, CMsg&, CVal&, Cancel&) ' ************************************************************************************* ' Code Generator Defined Global Variables and Types ' ************************************************************************************* ' Note: Do NOT change the names of the EZGUI Callback Procedures ! ' -------------------- #INCLUDE "C:\ezgui40pro\includes\ezwmain.inc" ' EZGUI Include file for WinMain ' -------------------- ' ************************************************************************************* ' User Defined Global Variables and Types ' (Put code in CODE TAGS! to protect from deletion by Code Generator !) ' ************************************************************************************* '<<SAVE>> %WM_RBUTTONDOWN = &H204 %ADDTVITEM = 2000 '<<END>> SUB EZ_Main(VerNum&) ' (PROTECTED) EZ_Reg %EZ_USERID,%EZ_REGNUM EZ_DefImageFolder "Images" EZ_AllowCommandEvents 1 EZ_AllowNotifyEvents 1 EZ_AllowKeyEvents 1 EZ_AllowCursorEvents 1 EZ_DefFont 6, "Tahoma", 8, "L+V" EZ_DefFont 7, "Tahoma", 8, "BV" EZ_DefFont 8, "Arial", 12, "BV" EZ_DefFont 9, "Webdings", 16, "L+SV" EZ_DefSystemColor 32, 4 EZ_DefSystemColor 33, 5 EZ_DefSystemColor 34, 15 EZ_DefSystemColor 35, 24 EZ_DefColorL 36, &HB96FFF EZ_DefColorL 37, &H14AB9F EZ_DefColorL 38, &H47A7FF EZ_DefColorL 39, &HD2AACF EZ_DefColorL 40, &H1CD5E3 EZ_DefColorL 41, &HBC8943 EZ_DefColorL 42, &H6C6AB7 EZ_DefColorL 43, &HDD4489 IF Main_Initialize(VerNum&) THEN EZ_F1_Display "" END IF END SUB ' ------------------------------------------------------------------------------------- SUB EZ_DesignWindow(FormName$) ' (PROTECTED) SELECT CASE FormName$ CASE "F1" EZ_F1_Design CASE "F2" EZ_F2_Design CASE "F3" EZ_F3_Design CASE ELSE OtherForm_Design FormName$ END SELECT END SUB ' ------------------------------------------------------------------------------------- SUB EZ_Events(FormName$, CID&, CMsg&, CVal&, Cancel&) ' (PROTECTED) IF PreProcess_Events(FormName$, CID&, CMsg&, CVal&, Cancel&) THEN EXIT SUB SELECT CASE FormName$ CASE "F1" EZ_F1_ParseEvents CID&, CMsg&, CVal&, Cancel& CASE "F2" EZ_F2_ParseEvents CID&, CMsg&, CVal&, Cancel& CASE "F3" EZ_F3_ParseEvents CID&, CMsg&, CVal&, Cancel& CASE ELSE OtherForm_Events FormName$, CID&, CMsg&, CVal&, Cancel& END SELECT END SUB ' ------------------------------------------------------------------------------------- ' ************************************************************************************* ' Applications FORM Code ' ************************************************************************************* ' ====================================== ' [USER ACCESSABLE CODE] You may Edit ! ' ====================================== FUNCTION Main_Initialize(BYVAL VerNum&) AS LONG LOCAL RV& RV&=1 FUNCTION=RV& END FUNCTION SUB OtherForm_Design(FormName$) SELECT CASE FormName$ CASE ELSE END SELECT END SUB SUB OtherForm_Events(FormName$, CID&, CMsg&, CVal&, Cancel&) SELECT CASE FormName$ CASE "{OPENDLG}", "{SAVEDLG}", "{OPENDLGX}", "{SAVEDLGX}", "{COLORDLG}", "{FONTDLG}", "{PRINTDLG}", "{PAGEDLG}", "{FINDDLG}" CASE "{ABORTDLG}" CASE "{MSGBOX}" CASE ELSE END SELECT END SUB FUNCTION PreProcess_Events(FormName$, CID&, CMsg&, CVal&, Cancel&) AS LONG LOCAL RV& RV&=0 FUNCTION=RV& END FUNCTION '<<BEGINFORM>> "F1" ' ====================================== ' [PROTECTED CODE] Do NOT Edit ! ' ====================================== SUB EZ_F1_Display(BYVAL Parent$) ' (PROTECTED) EZ_Color -1, -1 EZ_Form "F1", Parent$, "Test Form", 0, 0, 36.5, 9, "_C" END SUB SUB EZ_F1_Design() ' (PROTECTED) LOCAL CText$ EZ_Color-1,-1 EZ_UseFont 6 EZ_Button %F1_TVBTN, 9, 2.5, 18.5, 1.875, "Show Treeview", "T" ' ----------------------------------------------- EZ_Color-1,-1 EZ_UseFont 6 EZ_Button %F1_CLOSEBTN, 9, 5, 18.5, 1.875, "Close Form", "T" ' ----------------------------------------------- END SUB SUB EZ_F1_ParseEvents(CID&, CMsg&, CVal&, Cancel&) ' (PROTECTED) SELECT CASE CID& CASE %EZ_Window F1_Events CID&, CMsg&, CVal&, Cancel& CASE %F1_TVBTN F1_TVBTN_Events CID&, CMsg&, CVal&, Cancel& CASE %F1_CLOSEBTN F1_CLOSEBTN_Events CID&, CMsg&, CVal&, Cancel& CASE ELSE F1_Events CID&, CMsg&, CVal&, Cancel& END SELECT END SUB SUB F1_Events(CID&, CMsg&, CVal&, Cancel&) SELECT CASE CID& CASE %EZ_Window SELECT CASE CMsg& CASE %EZ_Loading CASE %EZ_Loaded CASE %EZ_Started CASE %EZ_Close CASE ELSE END SELECT CASE ELSE END SELECT END SUB SUB F1_TVBTN_Events( MyID&, CMsg&, CVal&, Cancel&) SELECT CASE CMsg& CASE %EZ_Click EZ_F2_Display "F1" CASE ELSE END SELECT END SUB SUB F1_CLOSEBTN_Events( MyID&, CMsg&, CVal&, Cancel&) SELECT CASE CMsg& CASE %EZ_Click EZ_UNLOADFORM "F1" CASE ELSE END SELECT END SUB '<<BEGINFORM>> "F2" ' ====================================== ' [PROTECTED CODE] Do NOT Edit ! ' ====================================== SUB EZ_F2_Display(BYVAL Parent$) ' (PROTECTED) EZ_Color -1, -1 EZ_Form "F2", Parent$, "Treeview Form", 0, 0, 41.75, 20.75, "_CMR" END SUB SUB EZ_F2_Design() ' (PROTECTED) LOCAL CText$ EZ_Color-1,-1 EZ_UseFont 6 EZ_SubClass 2 EZ_TreeView %F2_TV, 3.5, .875, 35, 14.75, "-+STV" EZ_SubClass 0 F2_TV_Fill -1 EZ_AddToolTip "F2", %F2_TV ' ----------------------------------------------- EZ_Color-1,-1 EZ_UseFont 6 EZ_Button %F2_ADDBTN, 3.5, 16.125, 35, 1.625, "Add an Item to the Treeview", "T" ' ----------------------------------------------- EZ_Color-1,-1 EZ_UseFont 6 EZ_Button %F2_CLOSEBTN, 3.5, 18.125, 35, 1.625, "Close this Modal Dialog", "T" ' ----------------------------------------------- END SUB SUB EZ_F2_ParseEvents(CID&, CMsg&, CVal&, Cancel&) ' (PROTECTED) SELECT CASE CID& CASE %EZ_Window F2_Events CID&, CMsg&, CVal&, Cancel& CASE %F2_TV IF CMsg& = %EZ_ToolTip THEN EZ_SetToolTip "" F2_TV_Events CID&, CMsg&, CVal&, Cancel& IF CMsg&=%EZ_SubClass THEN F2_TV_SubClass CVal&, Cancel& END IF CASE %F2_ADDBTN F2_ADDBTN_Events CID&, CMsg&, CVal&, Cancel& CASE %F2_CLOSEBTN F2_CLOSEBTN_Events CID&, CMsg&, CVal&, Cancel& CASE ELSE F2_Events CID&, CMsg&, CVal&, Cancel& END SELECT END SUB ' ====================================== ' [USER ACCESSABLE CODE] You may Edit ! ' ====================================== '<<SAVE>> SUB AddTexttoTreeview(txt$) LOCAL x& x& = EZ_ADDTVITEM("F2", %F2_TV, 0, 0, txt$, 0, 0, "") END SUB '<<END>> SUB F2_Events(CID&, CMsg&, CVal&, Cancel&) SELECT CASE CID& CASE %EZ_Window SELECT CASE CMsg& CASE %EZ_Loading CASE %EZ_Loaded CASE %EZ_Started CASE %EZ_Close CASE ELSE END SELECT CASE %ADDTVITEM IF CMsg& = %EZ_Click THEN EZ_F3_Display "F2" END IF CASE ELSE END SELECT END SUB SUB F2_TV_Fill(BYVAL Mode&) END SUB SUB F2_TV_Events( MyID&, CMsg&, CVal&, Cancel&) SELECT CASE CMsg& CASE %EZ_Selected CASE %EZ_ToolTip EZ_SETTOOLTIP "Right click to demonstrate Popup problem" CASE ELSE END SELECT END SUB SUB F2_TV_SubClass(BYVAL CVal&, Cancel&) LOCAL hCtrl&, Msg&, wParam&, lParam& LOCAL x??, y?? EZ_GetSubClass CVal&, hCtrl&, Msg&, wParam&, lParam& SELECT CASE Msg& CASE %WM_RBUTTONDOWN x?? = LO(WORD, lParam&) y?? = HI(WORD, lParam&) lParam& = MAK(LONG, x?? + 25, y?? + 20) EZ_DOPOPUPMENU "F2", lParam&, %ADDTVITEM, "Add Item to Treeview", "" CASE ELSE END SELECT END SUB SUB F2_ADDBTN_Events( MyID&, CMsg&, CVal&, Cancel&) SELECT CASE CMsg& CASE %EZ_Click EZ_F3_Display "F2" CASE ELSE END SELECT END SUB SUB F2_CLOSEBTN_Events( MyID&, CMsg&, CVal&, Cancel&) SELECT CASE CMsg& CASE %EZ_Click EZ_UNLOADFORM "F2" CASE ELSE END SELECT END SUB '<<BEGINFORM>> "F3" ' ====================================== ' [PROTECTED CODE] Do NOT Edit ! ' ====================================== SUB EZ_F3_Display(BYVAL Parent$) ' (PROTECTED) EZ_Color -1, -1 EZ_Form "F3", Parent$, "Second Modal Dialog", 0, 0, 37.75, 6.875, "_CMR" END SUB SUB EZ_F3_Design() ' (PROTECTED) LOCAL CText$ EZ_Color-1,-1 EZ_UseFont 6 EZ_Text %F3_ITEMTXT, 3.75, 1.75, 29.5, 1.25, "", "EST" EZ_AddToolTip "F3", %F3_ITEMTXT ' ----------------------------------------------- EZ_Color-1,-1 EZ_UseFont 6 EZ_Button %F3_OKBTN, 10.25, 4.75, 8.25, 1.5, "&OK", "T" ' ----------------------------------------------- EZ_Color-1,-1 EZ_UseFont 6 EZ_Button %F3_CANCELBTN, 19.75, 4.75, 8.25, 1.5, "&Cancel", "T" ' ----------------------------------------------- EZ_Color-1,-1 EZ_UseFont 6 EZ_Frame %F3_FRAME1, 1.75, .375, 34, 3.625, "Enter an Item to Add to the Listbox", "" ' ----------------------------------------------- END SUB SUB EZ_F3_ParseEvents(CID&, CMsg&, CVal&, Cancel&) ' (PROTECTED) SELECT CASE CID& CASE %EZ_Window F3_Events CID&, CMsg&, CVal&, Cancel& CASE %F3_ITEMTXT IF CMsg& = %EZ_ToolTip THEN EZ_SetToolTip "" F3_ITEMTXT_Events CID&, CMsg&, CVal&, Cancel& CASE %F3_OKBTN F3_OKBTN_Events CID&, CMsg&, CVal&, Cancel& CASE %F3_CANCELBTN F3_CANCELBTN_Events CID&, CMsg&, CVal&, Cancel& CASE ELSE F3_Events CID&, CMsg&, CVal&, Cancel& END SELECT END SUB ' ====================================== ' [USER ACCESSABLE CODE] You may Edit ! ' ====================================== SUB F3_Events(CID&, CMsg&, CVal&, Cancel&) SELECT CASE CID& CASE %EZ_Window SELECT CASE CMsg& CASE %EZ_Loading CASE %EZ_Loaded CASE %EZ_Started CASE %EZ_Close CASE ELSE END SELECT CASE ELSE END SELECT END SUB SUB F3_ITEMTXT_Events( MyID&, CMsg&, CVal&, Cancel&) SELECT CASE CMsg& CASE %EZ_Change CASE %EZ_ToolTip EZ_SETTOOLTIP "Add an item to the Treeview" CASE ELSE END SELECT END SUB SUB F3_OKBTN_Events( MyID&, CMsg&, CVal&, Cancel&) LOCAL txt$ SELECT CASE CMsg& CASE %EZ_Click txt$ = TRIM$(EZ_GETTEXT("F3", %F3_ITEMTXT)) IF LEN(txt$) THEN CALL AddTextToTreeview(txt$) EZ_UNLOADFORM "F3" END IF CASE ELSE END SELECT END SUB SUB F3_CANCELBTN_Events( MyID&, CMsg&, CVal&, Cancel&) SELECT CASE CMsg& CASE %EZ_Click EZ_UNLOADFORM "F3" CASE ELSE END SELECT END SUB '<<END ALL FORMS>> UnKnown Routines follow: #IF %EZ_NOSKIPCODE #ENDIF 'PARSE END
|
Frank Kelley Member
|
posted 06-08-2007 07:06 PM
Of interest, if I substitute %EZ_RButtonUp in the Treeview events (and even in the subclassed code), everything works correctly.However... It takes a double right-click to get the popup menu to respond. Now that I think about it, this double-clicking of the right button was the reason we went with subclassing the Treeview and processing the %WM_RBUTTONDOWN message in the first place. Chris, you are correct insofar as grabbing the button up message and avoiding the button down as being the right way to go. So how do we manage to get around the double-clicking of the right button? Lots of commercial apps require only a single right-click to get the job done. |
Frank Kelley Member
|
posted 06-08-2007 07:31 PM
Okay, the solution (at least partially), is to use the %EZ_Notify event:code:
SUB F2_TV_Notify(BYVAL CVal&, Cancel&) LOCAL hCtrl&, ID&, NCode& EZ_GetNotify CVal&, hCtrl&, ID&, NCode& SELECT CASE NCode& ' Notification Code CASE %NM_RCLICK EZ_DOPOPUPMENU "F2", CVal&, %ADDTVITEM, "Add Item to Treeview", "" CASE ELSE END SELECT END SUB
This code correctly detects the right mouse button up event (without double-clicking). The only problem is the pop-up menu appears off to the left side of the screen. Have to figure out a way of capturing the mouse position...perhaps on the right button down event. Also, in the test program--using the %EZ_Notify event--the application does not lock up.  |
Frank Kelley Member
|
posted 06-08-2007 07:52 PM
Okay, this code works. A combination of subclassing and %EZ_Notify does the trick. I think Chris can certainly make improvements, but this does the job for the time being.code:
SUB F2_TV_Notify(BYVAL CVal&, Cancel&) LOCAL hCtrl&, ID&, NCode& EZ_GetNotify CVal&, hCtrl&, ID&, NCode& SELECT CASE NCode& ' Notification Code CASE %NM_RCLICK EZ_DOPOPUPMENU "F2", gParam&, %ADDTVITEM, "Add Item to Treeview", "" CASE ELSE END SELECT END SUBSUB F2_TV_SubClass(BYVAL CVal&, Cancel&) LOCAL hCtrl&, Msg&, wParam&, lParam& LOCAL x??, y?? EZ_GETSUBCLASS CVal&, hCtrl&, Msg&, wParam&, lParam& SELECT CASE Msg& CASE %WM_RBUTTONDOWN x?? = LO(WORD, lParam&) y?? = HI(WORD, lParam&) gParam& = MAK(LONG, x?? + 25, y?? + 20) CASE ELSE END SELECT END SUB
gParam& is a global defined earlier in the program. The "adjustment" of +25 and +20 for the x and y coordinates places the popup menu in the correct location (next to the mouse click). |
Chris Boss Administrator
|
posted 03-01-2008 02:40 PM
The problem is not with EZGUI ! The problem is with how you are implimenting a right click action to display the popup menu.The Popup Menu should not be executed during the right button down event, but should be executed when the button comes up. The problem though is some common controls (ie. listview, treeview) don't generate the WM_RBUTTONUP message, so subclassing won't work. Fortunately the common controls generate a notification event (NM_RCLICK) via the WM_NOTIFY message to the parent form, for a right click and this occurs when the mouse button goes up. To trap this event, requires two steps. One is to subclass the control to trap the WM_RBUTTONDOWN message, so you can get the current mouse position and then store it in a global variable. Step 2 is to process the %EZ_Notify event (WM_NOTIFY) and trap the NM_RCLICK notification event (has a value of -5). This is where you display your popup. The lesson from this is always display a popup menu during the mouse UP event, not down. Here is a modified version of Franks code, which demonstrates this. You can right click the treeview, display a popup menu and then display a form from it. code:
' ************************************************************************************* ' Code Generated by EZGUI Visual Designer 4.0 ' Portions: Copyright Christopher R. Boss, 2003 to 2006 ' All Rights Reserved ! ' Registered EZGUI 4.0 users may use this code Royalty Free ! ' ************************************************************************************* ' ' -------------------------------------------------------- ' WARNING ! Do Not Modify any code WITHIN Protected Sections ! ' You can add code (Sub,Function,etc.) BEFORE any Protected Routine ' by using the following CODE TAGS: '<<SAVE>> '<<END>> ' and the Designer will not remove it. ' --------------------------------------------------------' ====================================== ' [PROTECTED CODE] Do NOT Edit ! ' ====================================== ' #COMPILE EXE #DIM ALL ' This is helpful to prevent errors in coding ' ------------------------------ ' Enable all constants below to ' customize maximums in EZGUI ' runtime. ' ------------------------------ ' %EZGUI_MaxColors = 800 ' %EZGUI_MaxFonts = 800 ' %EZGUI_MaxImages = 300 ' %EZGUI_MaxControls = 1500 ' %EZGUI_MaxForms = 150 ' %EZGUI_MaxMenus = 200 ' ------------------------------ ' -------------------- #INCLUDE "C:\ezgui40pro\includes\ezgui40.inc" ' EZGUI Include file for Declares ' -------------------- ' ************************************************************************************* ' ************************************************************************************* ' Code Generator Defined Constants and Declares ' ************************************************************************************* DECLARE FUNCTION Main_Initialize(BYVAL VerNum&) AS LONG DECLARE SUB OtherForm_Events(FormName$, CID&, CMsg&, CVal&, Cancel&) DECLARE SUB OtherForm_Design(FormName$) DECLARE FUNCTION PreProcess_Events(FormName$, CID&, CMsg&, CVal&, Cancel&) AS LONG DECLARE SUB EZ_F1_Display(BYVAL Parent$) DECLARE SUB EZ_F1_Design() DECLARE SUB EZ_F1_ParseEvents(CID&, CMsg&, CVal&, Cancel&) DECLARE SUB F1_Events(CID&, CMsg&, CVal&, Cancel&) ' ------------------------------------------------ %F1_TVBTN = 100 %F1_CLOSEBTN = 105 DECLARE SUB F1_TVBTN_Events(MyID&, CMsg&, CVal&, Cancel&) DECLARE SUB F1_CLOSEBTN_Events(MyID&, CMsg&, CVal&, Cancel&) DECLARE SUB EZ_F2_Display(BYVAL Parent$) DECLARE SUB EZ_F2_Design() DECLARE SUB EZ_F2_ParseEvents(CID&, CMsg&, CVal&, Cancel&) DECLARE SUB F2_Events(CID&, CMsg&, CVal&, Cancel&) ' ------------------------------------------------ %F2_TV = 100 %F2_ADDBTN = 105 %F2_CLOSEBTN = 110 DECLARE SUB F2_TV_Fill(BYVAL Mode&) DECLARE SUB F2_TV_Events(MyID&, CMsg&, CVal&, Cancel&) DECLARE SUB F2_TV_SubClass(BYVAL CVal&, Cancel&) DECLARE SUB F2_ADDBTN_Events(MyID&, CMsg&, CVal&, Cancel&) DECLARE SUB F2_CLOSEBTN_Events(MyID&, CMsg&, CVal&, Cancel&) DECLARE SUB EZ_F3_Display(BYVAL Parent$) DECLARE SUB EZ_F3_Design() DECLARE SUB EZ_F3_ParseEvents(CID&, CMsg&, CVal&, Cancel&) DECLARE SUB F3_Events(CID&, CMsg&, CVal&, Cancel&) ' ------------------------------------------------ %F3_ITEMTXT = 100 %F3_OKBTN = 105 %F3_CANCELBTN = 110 %F3_FRAME1 = 115 DECLARE SUB F3_ITEMTXT_Events(MyID&, CMsg&, CVal&, Cancel&) DECLARE SUB F3_OKBTN_Events(MyID&, CMsg&, CVal&, Cancel&) DECLARE SUB F3_CANCELBTN_Events(MyID&, CMsg&, CVal&, Cancel&) ' ************************************************************************************* ' Code Generator Defined Global Variables and Types ' ************************************************************************************* ' Note: Do NOT change the names of the EZGUI Callback Procedures ! ' -------------------- #INCLUDE "C:\ezgui40pro\includes\ezwmain.inc" ' EZGUI Include file for WinMain ' -------------------- ' ************************************************************************************* ' User Defined Global Variables and Types ' (Put code in CODE TAGS! to protect from deletion by Code Generator !) ' ************************************************************************************* '<<SAVE>> %WM_RBUTTONDOWN = &H204 %WM_RBUTTONUP = &H205 %ADDTVITEM = 2000 '<<END>> SUB EZ_Main(VerNum&) ' (PROTECTED) EZ_DefImageFolder "Images" EZ_AllowCommandEvents 1 EZ_AllowNotifyEvents 1 EZ_AllowKeyEvents 1 EZ_AllowCursorEvents 1 EZ_DefFont 6, "Tahoma", 8, "L+V" EZ_DefFont 7, "Tahoma", 8, "BV" EZ_DefFont 8, "Arial", 12, "BV" EZ_DefFont 9, "Webdings", 16, "L+SV" EZ_DefSystemColor 32, 4 EZ_DefSystemColor 33, 5 EZ_DefSystemColor 34, 15 EZ_DefSystemColor 35, 24 EZ_DefColorL 36, &HB96FFF EZ_DefColorL 37, &H14AB9F EZ_DefColorL 38, &H47A7FF EZ_DefColorL 39, &HD2AACF EZ_DefColorL 40, &H1CD5E3 EZ_DefColorL 41, &HBC8943 EZ_DefColorL 42, &H6C6AB7 EZ_DefColorL 43, &HDD4489 IF Main_Initialize(VerNum&) THEN EZ_F1_Display "" END IF END SUB ' ------------------------------------------------------------------------------------- SUB EZ_DesignWindow(FormName$) ' (PROTECTED) SELECT CASE FormName$ CASE "F1" EZ_F1_Design CASE "F2" EZ_F2_Design CASE "F3" EZ_F3_Design CASE ELSE OtherForm_Design FormName$ END SELECT END SUB ' ------------------------------------------------------------------------------------- SUB EZ_Events(FormName$, CID&, CMsg&, CVal&, Cancel&) ' (PROTECTED) IF PreProcess_Events(FormName$, CID&, CMsg&, CVal&, Cancel&) THEN EXIT SUB SELECT CASE FormName$ CASE "F1" EZ_F1_ParseEvents CID&, CMsg&, CVal&, Cancel& CASE "F2" EZ_F2_ParseEvents CID&, CMsg&, CVal&, Cancel& CASE "F3" EZ_F3_ParseEvents CID&, CMsg&, CVal&, Cancel& CASE ELSE OtherForm_Events FormName$, CID&, CMsg&, CVal&, Cancel& END SELECT END SUB ' ------------------------------------------------------------------------------------- ' ************************************************************************************* ' Applications FORM Code ' ************************************************************************************* ' ====================================== ' [USER ACCESSABLE CODE] You may Edit ! ' ====================================== FUNCTION Main_Initialize(BYVAL VerNum&) AS LONG LOCAL RV& RV&=1 FUNCTION=RV& END FUNCTION SUB OtherForm_Design(FormName$) SELECT CASE FormName$ CASE ELSE END SELECT END SUB SUB OtherForm_Events(FormName$, CID&, CMsg&, CVal&, Cancel&) SELECT CASE FormName$ CASE "{OPENDLG}", "{SAVEDLG}", "{OPENDLGX}", "{SAVEDLGX}", "{COLORDLG}", "{FONTDLG}", "{PRINTDLG}", "{PAGEDLG}", "{FINDDLG}" CASE "{ABORTDLG}" CASE "{MSGBOX}" CASE ELSE END SELECT END SUB FUNCTION PreProcess_Events(FormName$, CID&, CMsg&, CVal&, Cancel&) AS LONG LOCAL RV& RV&=0 FUNCTION=RV& END FUNCTION '<<BEGINFORM>> "F1" ' ====================================== ' [PROTECTED CODE] Do NOT Edit ! ' ====================================== SUB EZ_F1_Display(BYVAL Parent$) ' (PROTECTED) EZ_Color -1, -1 EZ_Form "F1", Parent$, "Test Form", 0, 0, 36.5, 9, "_C" END SUB SUB EZ_F1_Design() ' (PROTECTED) LOCAL CText$ EZ_Color-1,-1 EZ_UseFont 6 EZ_Button %F1_TVBTN, 9, 2.5, 18.5, 1.875, "Show Treeview", "T" ' ----------------------------------------------- EZ_Color-1,-1 EZ_UseFont 6 EZ_Button %F1_CLOSEBTN, 9, 5, 18.5, 1.875, "Close Form", "T" ' ----------------------------------------------- END SUB SUB EZ_F1_ParseEvents(CID&, CMsg&, CVal&, Cancel&) ' (PROTECTED) SELECT CASE CID& CASE %EZ_Window F1_Events CID&, CMsg&, CVal&, Cancel& CASE %F1_TVBTN F1_TVBTN_Events CID&, CMsg&, CVal&, Cancel& CASE %F1_CLOSEBTN F1_CLOSEBTN_Events CID&, CMsg&, CVal&, Cancel& CASE ELSE F1_Events CID&, CMsg&, CVal&, Cancel& END SELECT END SUB SUB F1_Events(CID&, CMsg&, CVal&, Cancel&) SELECT CASE CID& CASE %EZ_Window SELECT CASE CMsg& CASE %EZ_Loading CASE %EZ_Loaded CASE %EZ_Started CASE %EZ_Close CASE ELSE END SELECT CASE ELSE END SELECT END SUB SUB F1_TVBTN_Events( MyID&, CMsg&, CVal&, Cancel&) SELECT CASE CMsg& CASE %EZ_Click EZ_F2_Display "F1" CASE ELSE END SELECT END SUB SUB F1_CLOSEBTN_Events( MyID&, CMsg&, CVal&, Cancel&) SELECT CASE CMsg& CASE %EZ_Click EZ_UNLOADFORM "F1" CASE ELSE END SELECT END SUB '<<BEGINFORM>> "F2" ' ====================================== ' [PROTECTED CODE] Do NOT Edit ! ' ====================================== SUB EZ_F2_Display(BYVAL Parent$) ' (PROTECTED) EZ_Color -1, -1 EZ_Form "F2", Parent$, "Treeview Form", 0, 0, 41.75, 20.75, "_CMR" END SUB SUB EZ_F2_Design() ' (PROTECTED) LOCAL CText$ EZ_Color-1,-1 EZ_UseFont 6 EZ_SubClass 2 EZ_TreeView %F2_TV, 3.5, .875, 35, 14.75, "-+STV" EZ_SubClass 0 F2_TV_Fill -1 EZ_AddToolTip "F2", %F2_TV ' ----------------------------------------------- EZ_Color-1,-1 EZ_UseFont 6 EZ_Button %F2_ADDBTN, 3.5, 16.125, 35, 1.625, "Add an Item to the Treeview", "T" ' ----------------------------------------------- EZ_Color-1,-1 EZ_UseFont 6 EZ_Button %F2_CLOSEBTN, 3.5, 18.125, 35, 1.625, "Close this Modal Dialog", "T" ' ----------------------------------------------- END SUB SUB EZ_F2_ParseEvents(CID&, CMsg&, CVal&, Cancel&) ' (PROTECTED) SELECT CASE CID& CASE %EZ_Window F2_Events CID&, CMsg&, CVal&, Cancel& CASE %F2_TV IF CMsg& = %EZ_ToolTip THEN EZ_SetToolTip "" F2_TV_Events CID&, CMsg&, CVal&, Cancel& IF CMsg&=%EZ_SubClass THEN F2_TV_SubClass CVal&, Cancel& END IF CASE %F2_ADDBTN F2_ADDBTN_Events CID&, CMsg&, CVal&, Cancel& CASE %F2_CLOSEBTN F2_CLOSEBTN_Events CID&, CMsg&, CVal&, Cancel& CASE ELSE F2_Events CID&, CMsg&, CVal&, Cancel& END SELECT END SUB ' ====================================== ' [USER ACCESSABLE CODE] You may Edit ! ' ====================================== '<<SAVE>> SUB AddTexttoTreeview(txt$) LOCAL x& x& = EZ_ADDTVITEM("F2", %F2_TV, 0, 0, txt$, 0, 0, "") END SUB '<<END>> SUB F2_Events(CID&, CMsg&, CVal&, Cancel&) SELECT CASE CID& CASE %EZ_Window SELECT CASE CMsg& CASE %EZ_Loading CASE %EZ_Loaded CASE %EZ_Started CASE %EZ_Close CASE ELSE END SELECT CASE %ADDTVITEM IF CMsg& = %EZ_Click THEN EZ_F3_Display "F2" END IF CASE ELSE END SELECT END SUB SUB F2_TV_Fill(BYVAL Mode&) END SUB ' -------------------------------------------------------------------------- ' Implimenting Treeview Right Click action for Popup menus ' -------------------------------------------------------------------------- GLOBAL App_TrackMousePos& ' SUB F2_TV_SubClass(BYVAL CVal&, Cancel&) LOCAL hCtrl&, Msg&, wParam&, lParam& LOCAL x??, y?? EZ_GetSubClass CVal&, hCtrl&, Msg&, wParam&, lParam& SELECT CASE Msg& CASE %WM_RBUTTONDOWN App_TrackMousePos&=lParam& ' need to get mouse position in the right button down action CASE ELSE END SELECT END SUB ' SUB F2_TV_Notify(BYVAL CVal&) LOCAL hCtrl&, CID&, NCode&, V AS LONG PTR EZ_GetNotify CVal&, hCtrl&, CID&, NCode& IF NCode&=-5 THEN ' %NM_RCLICK notification event V=CVal& ' get pointer to WM_NOTIFY event structure ' convert mouse position from treeview client to form client App_TrackMousePos&=EZ_ConvertMousePos(EZ_Handle("F2",0), EZ_Handle("F2", %F2_TV), App_TrackMousePos&) EZ_DOPOPUPMENU "F2", App_TrackMousePos&, %ADDTVITEM, "Add Item to Treeview", "" END IF END SUB ' -------------------------------------------------------------------------- SUB F2_TV_Events( MyID&, CMsg&, CVal&, Cancel&) SELECT CASE CMsg& CASE %EZ_Selected CASE %EZ_ToolTip EZ_SETTOOLTIP "Right click to demonstrate Popup problem" CASE %EZ_Notify F2_TV_Notify Cval& CASE ELSE END SELECT END SUB SUB F2_ADDBTN_Events( MyID&, CMsg&, CVal&, Cancel&) SELECT CASE CMsg& CASE %EZ_Click EZ_F3_Display "F2" CASE ELSE END SELECT END SUB
SUB F2_CLOSEBTN_Events( MyID&, CMsg&, CVal&, Cancel&) SELECT CASE CMsg& CASE %EZ_Click EZ_UNLOADFORM "F2" CASE ELSE END SELECT END SUB '<<BEGINFORM>> "F3" ' ====================================== ' [PROTECTED CODE] Do NOT Edit ! ' ====================================== SUB EZ_F3_Display(BYVAL Parent$) ' (PROTECTED) EZ_Color -1, -1 EZ_Form "F3", Parent$, "Second Modal Dialog", 0, 0, 37.75, 6.875, "_CMR" END SUB SUB EZ_F3_Design() ' (PROTECTED) LOCAL CText$ EZ_Color-1,-1 EZ_UseFont 6 EZ_Text %F3_ITEMTXT, 3.75, 1.75, 29.5, 1.25, "", "EST" EZ_AddToolTip "F3", %F3_ITEMTXT ' ----------------------------------------------- EZ_Color-1,-1 EZ_UseFont 6 EZ_Button %F3_OKBTN, 10.25, 4.75, 8.25, 1.5, "&OK", "T" ' ----------------------------------------------- EZ_Color-1,-1 EZ_UseFont 6 EZ_Button %F3_CANCELBTN, 19.75, 4.75, 8.25, 1.5, "&Cancel", "T" ' ----------------------------------------------- EZ_Color-1,-1 EZ_UseFont 6 EZ_Frame %F3_FRAME1, 1.75, .375, 34, 3.625, "Enter an Item to Add to the Listbox", "" ' ----------------------------------------------- END SUB SUB EZ_F3_ParseEvents(CID&, CMsg&, CVal&, Cancel&) ' (PROTECTED) SELECT CASE CID& CASE %EZ_Window F3_Events CID&, CMsg&, CVal&, Cancel& CASE %F3_ITEMTXT IF CMsg& = %EZ_ToolTip THEN EZ_SetToolTip "" F3_ITEMTXT_Events CID&, CMsg&, CVal&, Cancel& CASE %F3_OKBTN F3_OKBTN_Events CID&, CMsg&, CVal&, Cancel& CASE %F3_CANCELBTN F3_CANCELBTN_Events CID&, CMsg&, CVal&, Cancel& CASE ELSE F3_Events CID&, CMsg&, CVal&, Cancel& END SELECT END SUB ' ====================================== ' [USER ACCESSABLE CODE] You may Edit ! ' ====================================== SUB F3_Events(CID&, CMsg&, CVal&, Cancel&) SELECT CASE CID& CASE %EZ_Window SELECT CASE CMsg& CASE %EZ_Loading CASE %EZ_Loaded CASE %EZ_Started CASE %EZ_Close CASE ELSE END SELECT CASE ELSE END SELECT END SUB SUB F3_ITEMTXT_Events( MyID&, CMsg&, CVal&, Cancel&) SELECT CASE CMsg& CASE %EZ_Change CASE %EZ_ToolTip EZ_SETTOOLTIP "Add an item to the Treeview" CASE ELSE END SELECT END SUB SUB F3_OKBTN_Events( MyID&, CMsg&, CVal&, Cancel&) LOCAL txt$ SELECT CASE CMsg& CASE %EZ_Click txt$ = TRIM$(EZ_GETTEXT("F3", %F3_ITEMTXT)) IF LEN(txt$) THEN CALL AddTextToTreeview(txt$) EZ_UNLOADFORM "F3" END IF CASE ELSE END SELECT END SUB SUB F3_CANCELBTN_Events( MyID&, CMsg&, CVal&, Cancel&) SELECT CASE CMsg& CASE %EZ_Click EZ_UNLOADFORM "F3" CASE ELSE END SELECT END SUB '<<END ALL FORMS>> UnKnown Routines follow: #IF %EZ_NOSKIPCODE #ENDIF 'PARSE END
| |