Link to home
Start Free TrialLog in
Avatar of LuRen
LuRen

asked on

[VB6/SP5] Why can't show the form vbModal?

hi,
    I have a case in which I can't show a form vbModal,

    Suppose I have three forms: Form1, Form2, Form3

     Form1 have a popup menu(MainMenu1): the action of the only menu item(SubMenu1_1) is 'Form2.show vbModal';
     Form2 have a popup menu(MainMenu1): the action of the only menu item(SubMenu1_1) is 'Form3.show vbModal';  
 
     the code list below:  

     Form1:
        ...
        Private Sub Form1_MouseDown()
            PopupMenu MainMenu1
        End Sub

        Private Sub  SubMenu1_1_Click()        
            Form2.Show vbModal
        End sub
        ....
   
     Form2:
        ...
        Private Sub Form2_MouseDown()
            PopupMenu MainMenu1                 ' here is the problem, it is executed, but no effection. That is, no menu is

popup.
        End Sub

        Private Sub  SubMenu1_1_Click()        
             Form3.Show vbModal                
        End sub
        ...

    Any suggestion or idea will be appreciated.

   -------
      lr

Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

is there a Menu Object called MainMenu1 in Form2? or you want to call the Menu MainMenu1 from Form1?

if yes then try this instead:

PopupMenu Form1.MainMenu1

regards
Avatar of LuRen
LuRen

ASKER

ryancys,
    Form1 has a menu named MainMenu1 (Private), and Form2 has a menu named MainMenu1 (Private), too.

    -- lr
You can only show 1 form modal.
Because you call form2 vbmodal, you can't show another form modal, even not a popupmenu (because it's also seen as a form)
ASKER CERTIFIED SOLUTION
Avatar of marconovaro
marconovaro

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
        'Keeps current form on top replace form1 with current form name
         lR = SetTopMostWindow(Form1.hwnd, True)
         'removes current top from on top position
         lR = SetTopMostWindow(Form1.hwnd, False)
 
On the Project menu, click Add Module, to add a new module to the project.


Add the following code to the new module:



      Option Explicit
      Public Const SWP_NOMOVE = 2
      Public Const SWP_NOSIZE = 1
      Public Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
      Public Const HWND_TOPMOST = -1
      Public Const HWND_NOTOPMOST = -2

      Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos"  _
            (ByVal hwnd As Long, _
            ByVal hWndInsertAfter As Long, _
            ByVal x As Long, _
            ByVal y As Long, _
            ByVal cx As Long, _
            ByVal cy As Long, _
            ByVal wFlags As Long  ) As Long

      Public Function SetTopMostWindow(hwnd As Long, Topmost As Boolean) _
         As Long

         If Topmost = True Then 'Make the window topmost
            SetTopMostWindow = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, _
               0, FLAGS)
         Else
            SetTopMostWindow = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, _
               0, 0,FLAGS)
            SetTopMostWindow = False
         End If
      End Function
 

this is equivalent of vbmodal without errors
Avatar of LuRen

ASKER

Thx a lot.  now the popupmenu is available.


 --
   lr

   
Avatar of LuRen

ASKER

ryancys,Dhaest,avya2k
 
    Thank your help , too.