Solved

Having the old resize style with the standard TForm class?

Posted on 2004-04-30
5
585 Views
Last Modified: 2010-04-05
I've made a few complicated components that needs lots of CPU power to draw when resizing the form (their alClient aligned). When I resize the form it redraws it dozens of times, causing 50% CPU on my HT cpu (would otherwize cause 100%), while resizing. My application needs much CPU power already (it's a P2P client), so it would be nice to stop this resizing from causing that high CPU load. That's why I thought of the way old windowses resizes forms (it draws a simple rectangle, and when I let the mousebutton go, it redraws the form at that position). I know that is possible in XP too, but I can't really ask each user to enable the old resizing style, to save CPU power when using my app, so there must be a simple way (using a few modifications to original TForm code, or WinAPI's) to get the same effect on any windows OS. I looked through all settings (I think) in the default TForm, and found nothing (only for moving the form). Any ideas?
0
Comment
Question by:chrml0606
  • 2
  • 2
5 Comments
 
LVL 17

Assisted Solution

by:mokule
mokule earned 20 total points
Comment Utility
I've got such an idea.
In a Form's event OnCanResize when mouse button is down set Align := alNone for Your components.
In a MouseUp event set Align to alClient.
0
 
LVL 17

Expert Comment

by:mokule
Comment Utility
Hey, did You try DisableAlign?
0
 

Author Comment

by:chrml0606
Comment Utility
Good idea. I just tried DisableAlign and EnableAlign, and it seems to work fine, but if I disable it more times than I enable it, it won't be enabled again (of some very weird reason). That's no problem fixing that though.

However, MouseUp doesn't seem to trigger when I end the resizing (it triggers when the mouse goes up, but not when I let the mouse go after resizing for example). Are there any other way notifying when the mouse goes down/up, cuz it shouldn't bring any problem if I just disable/enable it every time the mouse goes down/up.
0
 
LVL 26

Accepted Solution

by:
Russell Libby earned 80 total points
Comment Utility
How about this though, might give you a little better control of what you are after...


unit dragform;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TFullDragForm     =  class(TForm)
  private
     // Private declarations
     FOldRect:      TRect;
     FSizeRect:     TRect;
     procedure      DrawDragRect(R: TRect; Erase: Boolean);
  protected
     // Protected declarations
     procedure      WMSizing(var Message: TMessage); message WM_SIZING;
     procedure      WMMoving(var Message: TMessage); message WM_MOVING;
     procedure      WMEnterSizeMove(var Message: TMessage); message WM_ENTERSIZEMOVE;
     procedure      WMExitSizeMove(var Message: TMessage); message WM_EXITSIZEMOVE;
  public
     // Public declarations
  end;

type
  TForm1 = class(TFullDragForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
{$R *.DFM}

procedure TFullDragForm.WMSizing(var Message: TMessage);
begin

  // Remove the frame rect
  DrawDragRect(FSizeRect, True);

  // Inherited
  inherited;

  // Get new window rect
  GetWindowRect(Handle, FSizeRect);

  // Draw new fram rect
  DrawDragRect(FSizeRect, False);

end;

procedure TFullDragForm.WMMoving(var Message: TMessage);
begin

  // Remove the frame rect
  DrawDragRect(FSizeRect, True);

  // Inherited
  inherited;

  // Get new window rect
  GetWindowRect(Handle, FSizeRect);

  // Draw new fram rect
  DrawDragRect(FSizeRect, False);

end;

procedure TFullDragForm.DrawDragRect(R: TRect; Erase: Boolean);
var  DesktopWindow:    HWND;
     DC:               HDC;
     OldBrush:         HBrush;
     DrawRect:         TRect;
     PenSize:          Integer;
begin

  PenSize:=4;
  DrawRect:=R;
  DesktopWindow:=GetDesktopWindow;
  DC:=GetDCEx(DesktopWindow, 0, DCX_CACHE or DCX_LOCKWINDOWUPDATE);
  try
     OldBrush:=SelectObject(DC, Canvas.Brush.Handle);
     with DrawRect do
     begin
        PatBlt(DC, Left + PenSize, Top, Right - Left - PenSize, PenSize, PATINVERT);
        PatBlt(DC, Right - PenSize, Top + PenSize, PenSize, Bottom - Top - PenSize, PATINVERT);
        PatBlt(DC, Left, Bottom - PenSize, Right - Left - PenSize, PenSize, PATINVERT);
        PatBlt(DC, Left, Top, PenSize, Bottom - Top - PenSize, PATINVERT);
     end;
     SelectObject(DC, OldBrush);
  finally
     ReleaseDC(DesktopWindow, DC);
  end;

end;

procedure TFullDragForm.WMEnterSizeMove(var Message: TMessage);
begin

  // Get the current window rect
  GetWindowRect(Handle, FOldRect);
  FSizeRect:=FOldRect;

  // Perform inherited
  inherited;

  // Lock the window
  Perform(WM_SETREDRAW, 0, 0);

  // Draw the frame rect
  DrawDragRect(FSizeRect, False);

end;

procedure TFullDragForm.WMExitSizeMove(var Message: TMessage);
begin

  // Perform inherited
  inherited;

  // Remove the last drag frame
  DrawDragRect(FSizeRect, True);

  // Unlock the window
  Perform(WM_SETREDRAW, 1, 0);

  // Repaint the desktop
  InvalidateRect(0, nil, False);

  // Repaint our window
  InvalidateRect(Handle, nil, True);

end;

end.

--------

Regards,
Russell
0
 

Author Comment

by:chrml0606
Comment Utility
Nice, nice. Thanks :). Accepted.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 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

10 Experts available now in Live!

Get 1:1 Help Now