Solved

trapping events (window messages)

Posted on 2004-04-15
11
908 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now