Mega Code Archive

 
Categories / Delphi / Ide Indy
 

Windows XP flavour to common controls in Delphi Part 1

Title: Windows XP flavour to common controls in Delphi - Part 1 Question: When Delphi 6 came out, Windows XP was still in beta, so Borland decided to unsupport the new common controls of this new operating system. Althought you can apply this new style to your app with few steps and some workaround. Some tips you'll find comefrom messages posted in various newsgroups. Thanks to all! Answer: First of all, I'm sorry for my english :) Well, I'm sure that you were sad when you saw that Delphi-made apps doesn't take visual enhancements under Windows XP. Me too. I thought that something went wrong in my code but the answer is in front of each Delphi developer: Delphi 6 doesn't support WinXP, even with the Update Pack 1 installed. Then, what to do? Be calm and start pointing your browser to www.tmssoftware.com . The guys at TMS made a free component named TWinXP that placed on your mainform makes your app theme-aware. Wow: is it all here? No, because not every component can be XP-compliant: only the ones that wraps the comctl32.dll can be converted to the new gui style. What can make a Delphi app theme-aware? The answer comes just from Microsoft: you need to add a "manifest" xml file to your resources that force the app to use the comctl32.dll version 6.0, just because Windows XP ships both version 5 and 6 of that file, in order to ensure backward compatibility. So almost all the components in your Win32 page of the Delphi palette will adopt XP themes; between these, some controls have strange behaviours and these are: - TListView Using this control in vsReport mode and together with TWinXp, causes a crash when your mouse pointer moves over a column header. - TPageControl This control should show pages with a smooth color gradient as background, instead it draws pages with the default clBtnFace color for background. - TTrackBar The new version of this control can show its current position value as a tooltip while dragging the cursor, but not in Delphi: we will enable this useful feature. ----------------------------------------------------------------------------- TListView - Fixing the "XP bug". (From a message posted on a newsgroup by Markus Pingel - the Delphi community thanks you!) 1) Open "ComCtrls.pas" and search for "TCustomListView.UpdateColumn" 2) You will find the following line. if FImageIndex -1 then fmt := fmt or LVCFMT_IMAGE or LVCFMT_COL_HAS_IMAGES; 3) Change that line into: if FImageIndex -1 then fmt := fmt or LVCFMT_IMAGE or LVCFMT_COL_HAS_IMAGES else mask := mask and not (LVCF_IMAGE); 4) Save Comctrls.pas. Now TListView doesn't crash when in vsReport mode and in junction with TWinXP. TO DO: The native ListView of WindowsXP can change the color of an entire column in vsReport when clicking on the related header section. How to achieve this result? ----------------------------------------------------------------------------- TPageControl - Avoiding clBtnFace as background color for TTabSheets. You know PageControl is a container for TTabSheet controls: the first one seems to well accept new Windows XP themes, but this remains true until you add a TabSheet. And PageControls are useless without TabSheets... 1) Open "ComCtrls.pas" and search for "TTabSheet.UpdateTabShowing". 2) You will find the following lines: procedure TTabSheet.UpdateTabShowing; begin SetTabShowing((FPageControl nil) and FTabVisible); end; 3) Add this new line to that procedure: SetWindowLong(handle,GWL_EXSTYLE,WS_EX_TRANSPARENT); 4) If you have multiple TabSheets, probably you will see all the controls pasted on the first TabSheet you see when your app starts. Ok, no panic and do the following. Search for "TPageControl.Loaded" and modify it as follows: procedure TPageControl.Loaded; var I: integer; begin inherited Loaded; UpdateTabHighlights; for I:=self.PageCount-1 downto 0 do self.ActivePage:=self.Pages[I]; end; This new line forces PageControl to switch between all pages before showing up with all messed controls. It's a bit brutal, but this method works; if you know something better, please let us know. 5) Save "ComCtrls.pas" and enjoy a truly new style also on TPageControls. ----------------------------------------------------------------------------- TTrackBar - Excuse me, what's your current position? A tooltip that shows the current value of the trackbar you're moving is really useful, because this means that you won't need anymore to add a label only for this scope :) 1) Open "ComCtrls.pas" and search for "TTrackBar.CreateParams" 2) You will see the following code: procedure TTrackBar.CreateParams(var Params: TCreateParams); const OrientationStyle: array[TTrackbarOrientation] of DWORD = (TBS_HORZ, TBS_VERT); TickStyles: array[TTickStyle] of DWORD = (TBS_NOTICKS, TBS_AUTOTICKS, 0); ATickMarks: array[TTickMark] of DWORD = (TBS_BOTTOM, TBS_TOP, TBS_BOTH); begin [...] with Params do begin Style := Style or OrientationStyle[FOrientation] or TickStyles[FTickStyle] or ATickMarks[FTickMarks] or TBS_FIXEDLENGTH or TBS_ENABLESELRANGE; [...] end; end; 3) Add "or TBS_TOOLTIPS" to the Style line. It will look as: Style := Style or OrientationStyle[FOrientation] or TickStyles[FTickStyle] or ATickMarks[FTickMarks] or TBS_FIXEDLENGTH or TBS_ENABLESELRANGE or TBS_TOOLTIPS; 4) Save ComCtrls.pas and enjoy tooltips on TTrackBar. TO DO: Also TTrackBar messes with backgrounds, because it's not transparent and the default background color is clBtnFace (obviously). ------------------------------------------------------------------------------ Well, this is only the first part of XP-related tips collection. May the force be with you!