Solved

trapping events (window messages)

Posted on 2004-04-15
11
915 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
  • 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb6 connector to SQL Server 2 37
Using an encrypted  value to decrypt and display contents in vb6 9 55
MsgBox 4 68
Set WorkSheet  not Working 9 38
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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

840 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