Solved

trapping events (window messages)

Posted on 2004-04-15
11
920 Views
Last Modified: 2008-03-06
Hi all,

My question is about how trap a window message.
I have an MDI application, in VB6, and I want to prevent all the MDI child forms to be maximized.
So, I think I have to trap the windows event ( window message ), in order to avoid that. I can't take the maximize button out of the child form.

I read on the MSDN that the event is WM_MDIMAXIMIZE, but I don't know how to trap it.

Any idea??

Nori.
0
Comment
Question by:norifumi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
11 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 10834972
>>I can't take the maximize button out of the child form

Why not set BorderStyle to Fixed Single and MinButton to True?  Max button will be visible but disabled.
0
 
LVL 19

Expert Comment

by:Shauli
ID: 10835135
Put the line below in the Form_Resize event of the child form:

MDIForm.Arrange vbCascade

Not a very nice solution, but works :)

S
0
 
LVL 19

Expert Comment

by:Shauli
ID: 10835140
ps. Change MDIForm to your MDI form name

S
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:norifumi
ID: 10840991
I want the maximize button to be visible and enable, but when the user will press it, I need to avoid the window to be maximized, so I need to catch the event -WM_MDIMAXIMIZE-
The user must to be able to move, resize and minimize the window normally.

My problem is that I don't know how handle window events. I know that I have to use the API to do that, and I tried some code but it doesn't work.

About the shauli comment, I don't understand what do you want to say with arrenging the windows. besides, when a window is maximized, the resize event is not launch..

0
 
LVL 19

Expert Comment

by:Shauli
ID: 10841228
"besides, when a window is maximized, the resize event is not launch....."

Is that so?????????????????????????????


S
0
 
LVL 19

Expert Comment

by:Shauli
ID: 10841317
Sorry about the above comments, I couldn't resist :)
The Resize event does launch when you maximize a form. Do a simple test: Put a msgbox in Form_Resize and see for yourself. As for my suggestion, what it does, it cascades the form while it is resized. So it keeps it in normal mode instead of maximize all the time. However it is an "ugly" solution, as when the user tries to maximize, it does flicker once, trying to maximize and then back to normal. As I said above, it is not a nice solution, rather it is a kind of walkaround.

S
0
 

Author Comment

by:norifumi
ID: 10841590
You're right, the resize event is launched..

but it is launched after the maximize. I mean, the window is maximized, then the resize event is raised.

On my concrete application, the window never can be on a maximize state, so I can't use this solution..
0
 
LVL 19

Expert Comment

by:Shauli
ID: 10841615
That's fair enough, I'll keep looking :)

S
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 500 total points
ID: 10842464
You need to subclass like so:

'form code
Private Sub Form_Load()
    p_lngPrevWndProc = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Call SetWindowLong(Me.hwnd, GWL_WNDPROC, p_lngPrevWndProc)
End Sub


'bas module code
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

Public Const GWL_WNDPROC = (-4)
Public Const WM_GETMINMAXINFO = &H24


Public Type POINTAPI
    x As Long
    y As Long
End Type

Public Type MINMAXINFO
    ptReserved As POINTAPI
    ptMaxSize As POINTAPI
    ptMaxPosition As POINTAPI
    ptMinTrackSize As POINTAPI
    ptMaxTrackSize As POINTAPI
End Type


Public p_lngPrevWndProc     As Long



Public Function WindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Dim mmi     As MINMAXINFO
   
    If Msg = WM_GETMINMAXINFO Then
        CopyMemory mmi, ByVal lParam, Len(mmi)
       
        mmi.ptMaxSize.x = Form1.Width \ Screen.TwipsPerPixelX
        mmi.ptMaxSize.y = Form1.Height \ Screen.TwipsPerPixelY
        mmi.ptMaxPosition.x = Form1.Left \ Screen.TwipsPerPixelX
        mmi.ptMaxPosition.y = Form1.Top \ Screen.TwipsPerPixelY
        Form1.WindowState = vbNormal
       
        CopyMemory ByVal lParam, mmi, Len(mmi)
        WindowProc = 0

    Else
        WindowProc = CallWindowProc(p_lngPrevWndProc, hwnd, Msg, wParam, lParam)
    End If
End Function
0
 

Author Comment

by:norifumi
ID: 10858000
Great answer!!
thanks, Azrasound, that was exactly what I was looking for. I tried on my project and it works perfectly.

Sorry cos I've spent three days on giving you the points, but this weekend I was on holidays :D

Thanks and greetings

Norifumi.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 10859971
Glad I could help  :-)h
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
using web browser with BING 40 136
Hide vba in gp 7 115
IF ELSE Statement in Excel Macro VBA 16 87
Publisher:   Unknown     VB.exe Application 1 31
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question