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
Solved

Having the old resize style with the standard TForm class?

Posted on 2004-04-30
5
587 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
ID: 10961584
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
ID: 10961613
Hey, did You try DisableAlign?
0
 

Author Comment

by:chrml0606
ID: 10962009
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
ID: 10962026
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
ID: 10962222
Nice, nice. Thanks :). Accepted.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Simple Delphi Question 9 96
Run video youtube webbrowse 10 65
Why can't I create any project with my delphi EXE file? 6 39
Firemonkey webbrowser scrollbars ? 1 50
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

840 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