no modal forms ? 
Author Message
 no modal forms ?

Hi all

Just like in VB6, I'd like to call a form modally and return
to where it was called after it finishes.

According to the documentation, there is a Style parameter
for the Show method, which can be used to call a form
modally or modelessly. I tried to use it but it appears to be
non-functional. The statement after the Form.Show always
gets executed, even if the form was called modally.

Now I think what I'm trying to accomplish isn't possible
through the use of modal attribute because forms are never
unloaded in WinCE, so program control never returns to where
that form was called. And only Microsoft knows why there
is a Style parameter good-for-nothing !..

Any other solution would be greatly appreciated.
Thanks.



Fri, 14 Jan 2005 20:31:32 GMT  
 no modal forms ?
I believe that this article still applies, although it was written in the
VBCE6 timeframe:

Q218750: HOWTO: Simulate a Modal Form in Visual Basic CE 6.0
   http://support.microsoft.com/default.aspx?scid=kb;en-us;Q218750

hth,
Michael Fosmire
Community Program Manager, Windows Embedded

This posting is provided AS IS with no warranties, and confers no rights.



Sat, 15 Jan 2005 23:39:27 GMT  
 no modal forms ?
This can be achieved with a combination of API calls and disabling the
calling form.

Here is an example from a project I am currently working on...

'Window positioning
Public Declare Function SetWindowPos Lib "Coredll" ( _
       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 Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOZORDER = &H4
Public Const SWP_HIDEWINDOW = &H80
Public Const SWP_SHOWWINDOW = &H40

Before calling the modal form, disable the calling form
e.g. Me.Enabled = False

<Place the following code in the Form Load event of the modal form>

' position the window using API call, this method positions the new
window on top of any existing windows currently on the screen and
disallows any moving or re-sizing and emulates a modal form in eVB

    BytLeftPos = (Screen.Width - Me.Width) / 2          'centre the
form
    BytTopPos = (Screen.Height - Me.Height) / 2

    ' call the API
    lret = SetWindowPos(frmLondisPopupDetLab.hwnd, HWND_TOPMOST, 0, 0,
0, 0, SWP_NOSIZE Or SWP_NOMOVE)

    Me.Left = BytLeftPos
    Me.Top = BytTopPos

Re-enable the calling form when you return to it.

You will have to show/hide the forms also...

Hope this helps.

Paul Newton
Software Developer
BUSINESS INFORMATION TECHNOLOGY SERVICES LTD
www.b-i-t-s.co.uk

Quote:

> Hi all

> Just like in VB6, I'd like to call a form modally and return
> to where it was called after it finishes.

> According to the documentation, there is a Style parameter
> for the Show method, which can be used to call a form
> modally or modelessly. I tried to use it but it appears to be
> non-functional. The statement after the Form.Show always
> gets executed, even if the form was called modally.

> Now I think what I'm trying to accomplish isn't possible
> through the use of modal attribute because forms are never
> unloaded in WinCE, so program control never returns to where
> that form was called. And only Microsoft knows why there
> is a Style parameter good-for-nothing !..

> Any other solution would be greatly appreciated.
> Thanks.



Sun, 16 Jan 2005 00:11:30 GMT  
 no modal forms ?


Quote:
> This can be achieved with a combination of API calls and
> disabling the calling form.


Quote:
> I believe that this article still applies, although it was written
> in the VBCE6 timeframe:

Thank you Paul & Michael for your interest.

As I said in my first post, I want a form to behave just like an
InputBox does, it will be called somewhere in code, and return
to where it was called after it finished its work.
I tried the solution that you offered, but it doesn't solve the
problem.

The article which Michael pointed me includes a sample code.
A comment in this code clearly warns the users that
"Code still executes despite the fact that Form2 will be shown
modally". This is the problem that I want to find a solution for.
Also the sample code mentioned above is supposed to
illustrate how to simulate a modal form, but I couldn't see
which behaviour of the modal forms is simulated here.
What is the use of making the form topmost, non-resizable and
non-movable if it doesn't prevent the code after the Form.Show
statement from getting executed ?

Am I missing something ?



Sun, 16 Jan 2005 18:12:57 GMT  
 no modal forms ?
You'll want to play with this a bit - there are issues with the form
showing up on top, but this code holds off the code from firing after the
second form is dimissed.  You can probably use a SetWindowPos or something
..

Here's a not-fully-tested snippet:

Declare Function PeekMessage Lib "coredll.dll" Alias "PeekMessageW" ( _
    ByVal Msg As String, _
    ByVal hWnd As Long, _
    ByVal wMsgFilterMin As Integer, _
    ByVal wMsgFilterMax As Integer, _
    ByVal wRemoveMsg As Integer) As Boolean

Declare Function TranslateMessage Lib "coredll.dll" ( _
    ByVal Msg As String) As Boolean

Declare Function DispatchMessage Lib "coredll.dll" Alias "DispatchMessageW"
( _
    ByVal Msg As String) As Boolean

Dim Msg As String
Private Sub Form_OKClick()
    App.End
End Sub
Private Sub Command1_Click()
    Form2.Show
    Form1.Enabled = False
    Form1.Visible = False
    Do
        CEDoEvents
    Loop While Form2.Visible

    Form1.Enabled = True

    MsgBox "This code is held off until send form is closed."
End Sub

Private Sub Form_Load()
    Msg = String(18, Chr(0))
End Sub

Private Sub CEDoEvents()
    Dim PM_REMOVE As Integer
    PM_REMOVE = 1
    If PeekMessage(Msg, 0, 0, 0, PM_REMOVE) Then
        TranslateMessage (Msg)
        DispatchMessage (Msg)
    End If
End Sub

hth,
Michael Fosmire
Community Program Manager, Windows Embedded

This posting is provided AS IS with no warranties, and confers no rights.



Mon, 17 Jan 2005 02:35:25 GMT  
 no modal forms ?

Quote:
> You'll want to play with this a bit - there are issues with the form
> showing up on top, but this code holds off the code from firing
> after the second form is dimissed.  You can probably use a
> SetWindowPos or something

> Private Sub Command1_Click()
>     Form2.Show
>     Form1.Enabled = False
>     Form1.Visible = False
>     Do
>         CEDoEvents
>     Loop While Form2.Visible
>     Form1.Enabled = True
>     MsgBox "This code is held off until send form is closed."
> End Sub

Hello Michael,
Waiting in a DoEvents loop was one of my workaround solutions
and I'll probably make use of it. I just wondered if there could be
a more elegant way, with some API calls, for example.
Thank you again.

Serdar Aytamaner



Mon, 17 Jan 2005 06:05:48 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Problem with draw order after calling modal a modal from from a modal form

2. MODAL FORM & NON MODAL FORM

3. Unloading modal owner form also unloads modal form?

4. Modal Form with Modal form using Control?

5. MODAL FORM & NON MODAL FORM

6. Modal Form can't open another Modal Form

7. MODAL FORM & NON MODAL FORM

8. non-modal form when a modal form is displayed

9. MODAL FORM & NON MODAL FORM

10. Loading a Modal Form from a Modal Form

11. ActiveX control on modal form give 'can't show non-modal form when modal form is displayed'

12. How Do I Change A Modal Form To Non-Modal

 

 
Powered by phpBB® Forum Software