Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Control Panel Applet - Not Showing Icon 1

Status
Not open for further replies.

djjd47130

Programmer
Nov 1, 2010
480
US
I have followed a few tutorials on creating a control panel applet. It works fine, got it in my control panel and everything, except, the icon I assigned to it is not showing. I deleted the .cpl file, all the .dcu files, and all the .~ files - recompiled - and still no icon showing.

Has anyone else faced this issue? From the looks of it, it doesn't seem too often that people make control panel applets from delphi.

I'm using delphi 7 and running this cpl item on windows server 2008 R2 (identical to windows 7) 64 bit - and I am putting this file properly in the SysWOW64 folder.


JD Solutions
 
It sounds like you need to include a resource file with your DLL that includes the icon and then point it to the icon when it loads (in some way).

An example of one:
Code:
STRINGTABLE 
{ //the "title" of applet #1 
10, "Demo Current Time" 
//the description of applet #1 
11, "Shows the current system time..." 
//the "title" of applet #2 
20, "Demo Caps Lock" //the description of applet #2 
21, "Caps and Num Lock Info..." } 
12 ICON applet1.ico //the icon for applet #1 
22 ICON applet2.ico //the icon for applet #2

And then in the CPlApplet:
Code:
case iMessage of
...
CPL_NEWINQUIRE : 
  begin 
   PNewCplInfo(lParam2)^.dwSize := sizeof(TNewCplInfo); 
   PNewCplInfo(lParam2)^.lData := 0; 
   PNewCplInfo(lParam2)^.IconH := LoadIcon(hInstance, MakeIntResource( (10 * (lParam1 + 1)) + 2)); 
   LoadString(hInstance, (10 * (lParam1 + 1)) + 0, @PNewCplInfo(lParam2)^.szName, sizeof(PNewCplInfo(lParam2).szName)); 
   LoadString(hInstance, (10 * (lParam1 + 1)) + 1, @PNewCplInfo(lParam2)^.szInfo, sizeof(PNewCplInfo(lParam2).szInfo));    
   PNewCplInfo(lParam2)^.dwHelpContext := 0;   
   PNewCplInfo(lParam2)^.szHelpFile[0] := #0; 
   Result := 0; 
  end;

Using for reference in this, but the main problem on that link is the code isn't formatted too good.

I'm sure doing CPLs are a lot like doing screen savers (SCR) were for me. You have to look at a lot of examples and check just to be sure you got all the fine points down.

I got this filed away, it'll be a good project for the future just to see how they work.

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
I got this filed away, it'll be a good project for the future just to see how they work.

I got too tempted and threw together a sample off of that URL and cleaned it up in a few ways. Works very well. I probably can throw it on here as a FAQ once I clean up things a bit more.

What is above indeed assigns the designated icons to the control panel. If you want the designated icon as part of your VCL form, you need to do this after you create the VCL form:

Code:
Frm_Applet1.Icon.Handle := LoadIcon(hInstance, MakeIntResource( (10 * (DlgNo + 1)) + 2));

Of course, I have to keep saying YMMV when it comes to Vista and Seven. But for what I'm doing this link seems to be gold and the source samples work right.

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
I just find that very odd that the property in this applet allows my to directly assign any icon I want. While it successfully saves this icon, for some reason it does not actually apply this icon in the control panel.

Sad that I have to do a bunch of code for this, when the "Icon" property is right there.

JD Solutions
 
FAQ Posted: faq102-7505 , which is basically the cleaned up version of the link I posted here.

I noticed in TD2006 that you can create a "Control Panel Application", and I notice the code is basically repetitive for any control panel app so I'm sure what I posted could be made into a component somehow. But then again, the Delphi developers can have the benefit of writing their stuff into the editor and changing code behind the scenes while the average component writer does not.

I'm thinking of a good way to do it, though, at least until I need to move onto something else.

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
Sad that I have to do a bunch of code for this, when the "Icon" property is right there.

You're interacting with the OS to be able to publish the icon (through SHELL32.DLL's calls), so you have to do it the OSes way. Just kind of how it goes. For the form icon, a lot of code happens behind the scenes in a TApplication and filling in that icon is one of them.

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
Thanks, that makes more sense. I'm sure it would most likely work fine on XP. I don't have any problem with the form's icon though.

JD Solutions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top