Solved

trapping events (window messages)

Posted on 2004-04-15
11
903 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
Comment Utility
>>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
Comment Utility
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
Comment Utility
ps. Change MDIForm to your MDI form name

S
0
 

Author Comment

by:norifumi
Comment Utility
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
Comment Utility
"besides, when a window is maximized, the resize event is not launch....."

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


S
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 19

Expert Comment

by:Shauli
Comment Utility
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
Comment Utility
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
Comment Utility
That's fair enough, I'll keep looking :)

S
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Glad I could help  :-)h
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

772 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

11 Experts available now in Live!

Get 1:1 Help Now