Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
493 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi



Loremo - the 1.5 liter car coming in 2009




Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (0)


Delphi 5 TToolbar does not resize correctly when XP common controls 6.0 are enabled.Format this article printer-friendly!Bookmark function is only available for registered users!
Altering Delphi 5 comctrls.pas to fit your needs!
Product:
Delphi 5.x (or higher)
Category:
VCL-General
Skill Level:
Scoring:
Last Update:
11/12/2002
Search Keys:
delphi delphi3000 article borland vcl code-snippet Windows-XP common-controls comctrls Delphi-5 manifest TToolbar TToolbutton theme-aware CreateButtons
Times Scored:
1
Visits:
3151
Uploader: Flurin Honegger
Company:
Reference: N/A
 
Question/Problem/Abstract:
I currently check a Delphi 5.x developed application running under XP with common controls 6.0 enabled (see Paul Swonger, http://www.delphi3000.com/articles/article_2359.asp). Beside the corrections to comctrls.com mentioned by Matteo Riso, http://www.delphi3000.com/articles/article_2843.asp, I realized an other flaw in the same unit, preventing TToolbar to resize correctly.
Answer:



Remark:
This article only applies to Delphi Professional 5.0 (Build 6.18) Update Pack 1!


The problem in my application was, that the button size and bar size did not change to the desired values. Even worse the outcome was depending on the Order of the following assignments to Toolbar1. By repetitive changing from large to small icons the buttons even growth in size.

{my code snippet}

  if AppRegSet.LargeIcons then begin
    BuildLargeButtonsFromSmall(AppRegSet.StretchIcons,ImageList1,ImageList2);
    ToolBar1.Images:=ImageList2;
    ToolBar1.ButtonWidth:=32;
    ToolBar1.ButtonHeight:=32;
  end else begin
    ToolBar1.Images:=ImageList1;
    ToolBar1.ButtonHeight:=24;
    ToolBar1.ButtonWidth:=24;
  end;


Careful inspection revealed the problem in the method CreateButtons of TToolbar. The new size settings are applied to the toolbar before removing the individual buttons. Debugging further revealed that the applied size was automatically overridden by the system to bigger values. Not only changed the alteration of the ButtonHeight its height but also its wisth and some how the minimal allowed value (see TB_SETBUTTONWIDTH message).

The win32 platform SDK say’s (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/toolbar/messages/tb_setbitmapsize.asp) that TB_SetButtonsize, TB_SetBitmapSize  must be set before adding buttons. I interpreted this statement as “must be applied to an empty toolbar” and changed the corresponding vcl code in this sense (changed lines have an “//XP Theme fix " comment line prepended).  When testing my application the resizing now works perfect in either ways, common controls 6 enabled or not.


{changed comctrls.pas code}

procedure TToolBar.CreateButtons(NewWidth, NewHeight: Integer);

  function ToolButtonVisible: Boolean;
  var
    I: Integer;
    Control: TControl;
  begin
    for I := 0 to FButtons.Count - 1 do
    begin
      Control := TControl(FButtons[I]);
      if (Control is TToolButton) and ((csDesigning in ComponentState) or
        Control.Visible) and not (TToolButton(Control).Style in
        [tbsSeparator, tbsDivider]) then
      begin
        Result := True;
        Exit;
      end;
    end;
    Result := False;
  end;

var
  ImageWidth, ImageHeight: Integer;
  I: Integer;
begin
  BeginUpdate;
  try
    HandleNeeded;
//XP theme fix: folowing line added
    for I := 0 to InternalButtonCount - 1 do Perform(TB_DELETEBUTTON, 0, 0);  
    Perform(TB_BUTTONSTRUCTSIZE, SizeOf(TTBButton), 0);
    Perform(TB_SETINDENT, FIndent, 0);
    if FImages <> nil then
    begin
      ImageWidth := FImages.Width;
      ImageHeight := FImages.Height;
    end
    else if FDisabledImages <> nil then
    begin
      ImageWidth := FDisabledImages.Width;
      ImageHeight := FDisabledImages.Height;
    end
    else if FHotImages <> nil then
    begin
      ImageWidth := FHotImages.Width;
      ImageHeight := FHotImages.Height;
    end
    else
    begin
      ImageWidth := 0;
      ImageHeight := 0;
    end;
    Perform(TB_SETBITMAPSIZE, 0, MakeLParam(ImageWidth, ImageHeight));
    { Adjust the working height if there is a visible TToolButton whose caption
      height is automatically added by the common control. }
    if ShowCaptions and ToolButtonVisible then Dec(NewHeight, FHeightMargin);
    { Prevent toolbar from setting default button size }
    if NewWidth <= 0 then NewWidth := 1;
    if NewHeight <= 0 then NewHeight := 1;
    Perform(TB_SETBUTTONSIZE, 0, MakeLParam(NewWidth, NewHeight));
    FButtonWidth := NewWidth;
    FButtonHeight := NewHeight;
  finally
    EndUpdate;
  end;
  { Retrieve current button sizes }
//XP theme fix: following line commented
//  for I := 0 to InternalButtonCount - 1 do Perform(TB_DELETEBUTTON, 0, 0);
  UpdateButtons;
  UpdateImages;
  GetButtonSize(FButtonWidth, FButtonHeight);
end;





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment













 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
L. Rosenstein
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)