?
Solved

Having the old resize style with the standard TForm class?

Posted on 2004-04-30
5
Medium Priority
?
590 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
[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
  • 2
  • 2
5 Comments
 
LVL 17

Assisted Solution

by:mokule
mokule earned 80 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 320 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

764 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