Solved

trapping events (window messages)

Posted on 2004-04-15
11
929 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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.
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…
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…

726 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