Solved

Delay form resize until mouse release?

Posted on 1999-01-25
7
282 Views
Last Modified: 2013-12-26
I'm resizing all my controls as the user resizes one of my forms. I'd like to get rid of the ugly flashing that takes place as the user resizes. Is there any way to prevent the resize until the user releases the mouse button? I want to have a ghost outline of the new form size appear as the user resizes and then update the display once the resizing's done.
Having the form resize without the controls is not enough (ie. all or nothing). I imagine some Win32 API is needed. Cheers & thanks.
0
Comment
Question by:deal051298
[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
7 Comments
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1489929
I think that this is a general option in your control panel (or in option in tweekUI), but not per window.
0
 
LVL 4

Accepted Solution

by:
anzen earned 250 total points
ID: 1489930
I'll assume You're familiar with the Windows API and the techniques needed to subclass a form; what You need is subclass the target form using the "SetWindowLong" API, next in Your message processing routine You will look for the messages WM_ENTERSIZEMOVE and WM_EXITSIZEMOVE, they are sent to a window whenever a user begins/ends moving or resizing a form (You must check to see whether it's a move or a resize), when You see the "exit" message You'll do all Your resizing work.

If You need more details please let me know.


0
 
LVL 12

Expert Comment

by:jgv
ID: 1489931
What method are you using to do this? If you're not already doing so, resize the form controls under Form_Resize(). Processing shouldn't occur until the mouse button is released.
0
Technology Partners: 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:deal051298
ID: 1489932
Anzen, I've only done windows API calls through Visual Basic so I'm not totally sure what you mean by "subclassing the form" and my "message processing routine". I'll be researching your answer in the win32 documentation but a little help would go a long way.

jgv, the resize code is executed continually as the form is resized, not just on mouse release.

Mirkwood, do you ever sleep man!
0
 
LVL 4

Expert Comment

by:anzen
ID: 1489933
To subclass a form You must use the Get/Set..WindowLong API calls together with a user supplied function to process the incoming windows messages, the code is something like this:

' Messages - declare as needed
Private Const WM_ENTERSIZEMOVE = 561&
Private Const WM_SIZING = 532&
Private Const WM_SIZE = 5&
Private Conts WM_EXITSIZEMOVE = 562&

' Subclassing APIs
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private 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


' Enables/Disables window subclassing, note that
' You must store in a safe place the value returned
' by this function since it's needed to disable the
' subclassing for the window and You MUST disable the
' subclassing whenever You unload the window or all You
' got is a system crash !!
Public Function SubClass(ByVal hWnd As Long, ByVal bOnOff As Boolean) As Long
      Dim lpWindowProc As Long

    On Local Error Resume Next
    If bOnOff = True Then
            ' Enables subclassing
        lpWindowProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)
    ElseIf lpWindowProc <> 0 Then
        ' disables subclassing
        lpWindowProc = SetWindowLong(hWnd, GWL_WNDPROC, lpWindowProc)
        lpWindowProc = 0
    End If
    SubClass = lpWindowProc
End Function

' User WindowProc, all messages sent from Windows
' to the subclassed hWnd now come here and can be
' manipulated as needed
Public Function WindowProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Dim lRet As Long
   
    ' There MUST be this !!
    On Local Error Resume Next
   
    ' calls default windowproc - just to be safe
      ' You could also decide NOT to call the default
      ' WinProc and to have this function "eat" the message
    lRet = CallWindowProc(lpWindowProc, hWnd, Msg, wParam, lParam)

      ' Now let's do some msg handling
      Select Case Msg
            Case WM_ENTERSIZEMOVE      ' begin size/move
                  ' prepare...
            Case WM_SIZING                  ' sizing (mouse down/moving)
                  ' noop
            Case WM_SIZE                  ' size paused (mouse still down)
                  ' can give some feedback
                  ' e.g. move controls....
            Case WM_EXITSIZEMOVE      ' end size/move (mouse up)
                  ' now do the full resizing !
            Case Else
                  ' nothing here
      End Select
   
    ' returns result to windows
    WindowProc = lRet
End Function

' Helper fn: Extracts HiWord from a Long
Public Function HiWord(dwValue As Long) As Integer
    On Local Error Resume Next
    If dwValue And &H80000000 Then
        HiWord = (dwValue \ 65535) - 1
    Else
        HiWord = dwValue \ 65535
    End If
End Function

' Helper fn: Extracts LoWord from a Long
Public Function LoWord(dwValue As Long) As Integer
    On Local Error Resume Next
    If dwValue And &H8000& Then
        LoWord = &H8000 Or (dwValue And &H7FFF&)
    Else
        LoWord = dwValue And &HFFFF&
    End If
End Function

keep in mind that You MUST store the value returned from the SubClass() function and use it to disable subclassing for Your window whenever You unload it or terminate Your app, failure to do this will result in a system crash !!

Hope it's clear ... Bye


0
 
LVL 4

Expert Comment

by:anzen
ID: 1489934
I leave out one thing: before You activate Your code to do the resizing/moving job call the LockWindowUpdate API to avoid flickering, then when You're done call it again to restore painting for the target form, that is:

Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long

' Disable repainting
lRet = LockWindowUpdate(frmForm.hWnd)

' ... do Your job...

' Re-Enable painting
lRet = LockWindowUpdate( 0&)

Bye



0
 

Expert Comment

by:wornways
ID: 34535543
anzen:

I don't know if you're still around, but when I try your code I end up with WindowProc being called in an infinite loop. Any ideas?
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…

734 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