Delphi32.com - Home!
| Home/News | Downloads | Forums | D32 Magazine | Resources | Info and Facts |  
 
 How do I set the desktop icon color in code, or make the text behind them transparent?


How do I set the desktop icon color in code, or make the text behind them transparent?   

    To do this, you will have find the "SysListView32" window (which is the desktop icon list view window). First, you will have to find the main parent window called "Progman". It has a child window called "SHELLDLL_DefView" that has the "SysListView32". You can use the API call

    FindWindow
    to find the "Progman" window, and then FindWindowEx to find the child window. When you finally have the right handle to the "SysListView32" window, you can use the ListView macro's
    ListView_SetTextBkColor
    and
    ListView_SetTextColor
    to set the color's to whatever you want.

    Below is a sample unit that does this for you. Simply use the procedure

    SetDesktopIconColor
    to set the desktop icon color. If the parameter
    Trans
    is true, it makes the background transparent, otherwise it used the given
    Background
    color.

    Download the DeskIcons.pas file

    DeskIcons.pas Unit

    unit DeskIcons;

    interface uses Graphics; // Definition of TColor

    procedure SetDesktopIconColor(Forground, Background: TColor; Trans: Boolean); procedure SetDefaultIconColors;

    implementation uses Windows, CommCtrl; // Definition of HWND and ListView_XXXXX

    procedure SetDesktopIconColor(Forground, Background: TColor; Trans: Boolean); { This procedure set's the desktop icon text color to a given color with the option to add a transparent background. } var Window: HWND; begin // Find the right window with 3 calls Window := FindWindow('Progman', 'Program Manager'); // FindWindowEx is used to find a child window Window := FindWindowEx(Window, HWND(nil), 'SHELLDLL_DefView', ''); // SysListView32 is the desktop icon list view Window := FindWindowEx(Window, HWND(nil), 'SysListView32', ''); // Use the macro to set the background color to clear if Trans then ListView_SetTextBkColor(Window, $ffffffff) // back color else ListView_SetTextBkColor(Window, Background); // back color ListView_SetTextColor(Window, Forground); // foreground color // now send a redraw to the icons to redraw the new color ListView_RedrawItems(Window, 0, ListView_GetItemCount(Window) - ); UpdateWindow(Window); // force the redraw to take effect immediatly end;

    procedure SetDefaultIconColors; { This set's the colors to be whatever is currently stored by windows } var Kind: Integer; Color: TColor; begin Kind := COLOR_DESKTOP; Color := GetSysColor(COLOR_DESKTOP); SetSysColors( , Kind, Color); end;

    end.

     



  << Previous Faq     Complete List     Next Faq >>  



 
 Hits/month  2,500,000+ 
 Downloads
 (Since May 2000)
 7,393,709 
 Total Files  6,023 
 Forum msgs  7,670 
 Articles/FAQs  70+/900+ 
Kylix
Tips n Tricks
FAQs
Knowledge Base
Bug Listings
Articles
Books
Newsgroups
Links
Submissions
Testimonials
Advertising
Contact Us
About Us
Search Amazon:
Top Selling Software at Amazon

| Home/News | Downloads | Forums | Resources | Info and Facts | Testimonials |
  Site Search:
 


Comments/Problems: Webmaster@delphi32.com
Copyright © 1998-2006, Delphi32.com. All rights reserved.
Terms of Use