Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Having the old resize style with the standard TForm class?

Posted on 2004-04-30
5
Medium Priority
?
592 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

636 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