angerer
asked on
Control Panel Applet under NT
I have to create an icon in the Control Panel from Windows NT. I use a DLL (renamed into a CPL) and the function CPLApplet. I guess there is someting wrong. Here is the code that does not work:
BOF----------------------- ---------- ---------- --
library pCPLApplet;
uses
Forms,
uCPLApplet in 'uCPLApplet.pas' {Form1},
WinTypes, WinProcs, cpl, SysUtils;
{$R *.RES}
procedure RunApp; export;
begin
Application.CreateForm(TFo rm1, Form1);
Application.Run;
end;
type
TNewCPLInfo = record
dwSize: longint; // similar to the commdlg
dwFlags: longint;
dwHelpContext: longint; // help context to use
lData: Longint; // user defined data
Icon: HICON; // icon to use, this is owned by CONTROL.EXE (may be deleted)
szName: array[0..31] of Char; // short name
szInfo: array[0..63] of Char; // long name (status line)
szHelpFile: array[0..127] of Char; // path to help file to use
end;
function CPLApplet (hWndCpl: HWnd; msg: Word; lParam1: Longint;
var NewCPLInfo: TNewCPLInfo): Longint; export;
begin
beep;
case msg of
CPL_INIT: begin
CPlApplet:=1;
end;
{CP asks "Are you an Applet" We reply 1 - "Yes I am"}
CPL_GETCOUNT:begin
CPlApplet:=1;
end;
{CP asks "How many icons do you want" We reply 1 - "One icon,
please"}
CPL_NEWINQUIRE:
{CP sends this message once for every icon you require. In our
case this is only sent once, so we dont need to concern ourself
with what applet number CP wants to know about}
begin
with NewCPLInfo do begin
dwSize:=sizeof(TNewCPLInfo );
dwFlags := 0;
dwHelpContext := 0;
lData := 0;
szHelpFile[0]:= #0;
{Now comes the intersting bit; our icon and names}
Icon := Application.Icon.Handle;
StrPCopy(szName,'My First Applet');
StrPCopy(szInfo,'My first Control Panel Applet (in Delphi!)');
end;
end;
CPL_DBLCLK: RunApp;
end;
end; //CPLApplet
exports
RunApp,
CPLApplet;
begin
end.
EOF----------------------- ---------- ---------- --
thanks for help
bernhard
Dipl. Ing. Bernhard Angerer
IFT / Vienna University of Technology
Karlsplatz 13/311
A-1040 Wien
Tel: +43 1 58801 3192
Fax: +43 1 504 14 97
angerer@mail.ift.tuwien.ac .at
BOF-----------------------
library pCPLApplet;
uses
Forms,
uCPLApplet in 'uCPLApplet.pas' {Form1},
WinTypes, WinProcs, cpl, SysUtils;
{$R *.RES}
procedure RunApp; export;
begin
Application.CreateForm(TFo
Application.Run;
end;
type
TNewCPLInfo = record
dwSize: longint; // similar to the commdlg
dwFlags: longint;
dwHelpContext: longint; // help context to use
lData: Longint; // user defined data
Icon: HICON; // icon to use, this is owned by CONTROL.EXE (may be deleted)
szName: array[0..31] of Char; // short name
szInfo: array[0..63] of Char; // long name (status line)
szHelpFile: array[0..127] of Char; // path to help file to use
end;
function CPLApplet (hWndCpl: HWnd; msg: Word; lParam1: Longint;
var NewCPLInfo: TNewCPLInfo): Longint; export;
begin
beep;
case msg of
CPL_INIT: begin
CPlApplet:=1;
end;
{CP asks "Are you an Applet" We reply 1 - "Yes I am"}
CPL_GETCOUNT:begin
CPlApplet:=1;
end;
{CP asks "How many icons do you want" We reply 1 - "One icon,
please"}
CPL_NEWINQUIRE:
{CP sends this message once for every icon you require. In our
case this is only sent once, so we dont need to concern ourself
with what applet number CP wants to know about}
begin
with NewCPLInfo do begin
dwSize:=sizeof(TNewCPLInfo
dwFlags := 0;
dwHelpContext := 0;
lData := 0;
szHelpFile[0]:= #0;
{Now comes the intersting bit; our icon and names}
Icon := Application.Icon.Handle;
StrPCopy(szName,'My First Applet');
StrPCopy(szInfo,'My first Control Panel Applet (in Delphi!)');
end;
end;
CPL_DBLCLK: RunApp;
end;
end; //CPLApplet
exports
RunApp,
CPLApplet;
begin
end.
EOF-----------------------
thanks for help
bernhard
Dipl. Ing. Bernhard Angerer
IFT / Vienna University of Technology
Karlsplatz 13/311
A-1040 Wien
Tel: +43 1 58801 3192
Fax: +43 1 504 14 97
angerer@mail.ift.tuwien.ac
I mean
function RunApp;stdcall;
function CPLApplet (hWndCpl: HWnd; msg: Word; lParam1: Longint;
var NewCPLInfo: TNewCPLInfo): Longint; stdcall;
Igor
function RunApp;stdcall;
function CPLApplet (hWndCpl: HWnd; msg: Word; lParam1: Longint;
var NewCPLInfo: TNewCPLInfo): Longint; stdcall;
Igor
ASKER
to inter: yes i know - but it does not work !
is the struct TNewCPLInfo correct ? the MS SDK help says:
LONG APIENTRY CPlApplet(
HWND hwndCPl, // handle to Control Panel window
UINT uMsg, // message
LONG lParam1, // first message parameter
LONG lParam2 // second message parameter
);
b.
is the struct TNewCPLInfo correct ? the MS SDK help says:
LONG APIENTRY CPlApplet(
HWND hwndCPl, // handle to Control Panel window
UINT uMsg, // message
LONG lParam1, // first message parameter
LONG lParam2 // second message parameter
);
b.
Hi,
just add the 'packed record' instead of record to the TNewCplInfo. The following works as is
library TestCpl;
{$R *.res}
uses
SysUtils, Windows, Messages, Dialogs, Classes,
CPL;
function CPlApplet(hwndCPl: THandle; uMsg: DWORD; lParam1, lParam2: Longint): Longint;stdcall;
begin
Result := 0;
case uMsg of
CPL_DYNAMIC_RES:;
CPL_INIT:
Result := 1; // 1 = Continue.
CPL_GETCOUNT:
Result := 1;
CPL_INQUIRE:; // See CPL_NEWINQUIRE.
CPL_SELECT:;
CPL_DBLCLK, CPL_STARTWPARMS:
// Pop up your dialog here...
ShowMessage('Applet #' + IntToStr(lParam1) + ' selected');
CPL_STOP:; // Control Panel is preparing to exit.
CPL_EXIT:; // Control Panel is now exiting.
CPL_NEWINQUIRE:
begin
with PNewCPLInfo(lParam2)^ do
begin
dwSize := SizeOf(TNewCPLInfo);
hIcon := 0; // Use DLL's main icon. Make sure to include {$R *.res} above!!
StrPCopy(@szName, 'Test');
StrPCopy(@szInfo, 'This is a test Control Panel applet');
end;
Result := 1; // Don't call CPL_INQUIRE.
end;
CPL_SETUP:; // Internal. Used during system installation.
end;
end;
exports
CPlApplet;
begin
end.
just add the 'packed record' instead of record to the TNewCplInfo. The following works as is
library TestCpl;
{$R *.res}
uses
SysUtils, Windows, Messages, Dialogs, Classes,
CPL;
function CPlApplet(hwndCPl: THandle; uMsg: DWORD; lParam1, lParam2: Longint): Longint;stdcall;
begin
Result := 0;
case uMsg of
CPL_DYNAMIC_RES:;
CPL_INIT:
Result := 1; // 1 = Continue.
CPL_GETCOUNT:
Result := 1;
CPL_INQUIRE:; // See CPL_NEWINQUIRE.
CPL_SELECT:;
CPL_DBLCLK, CPL_STARTWPARMS:
// Pop up your dialog here...
ShowMessage('Applet #' + IntToStr(lParam1) + ' selected');
CPL_STOP:; // Control Panel is preparing to exit.
CPL_EXIT:; // Control Panel is now exiting.
CPL_NEWINQUIRE:
begin
with PNewCPLInfo(lParam2)^ do
begin
dwSize := SizeOf(TNewCPLInfo);
hIcon := 0; // Use DLL's main icon. Make sure to include {$R *.res} above!!
StrPCopy(@szName, 'Test');
StrPCopy(@szInfo, 'This is a test Control Panel applet');
end;
Result := 1; // Don't call CPL_INQUIRE.
end;
CPL_SETUP:; // Internal. Used during system installation.
end;
end;
exports
CPlApplet;
begin
end.
Try to make the record packed (TNewCPLInfo = packed record) or make sure that Project Option / Compiler / Align Record Fields is not checked.
angerer,
I know of a freeware coponent, with heavely docs, great source, ... which (have you heard it before) does all this and more... yep. I don't know your problem, but I'm going to look at it. Meanwhile, I'll give you the URL to the component and I we all can look at the source :
home page : http://www.wilsonc.demon.co.uk/delphi.htm
component : http://www.wilsonc.demon.co.uk/Delphi Components/d3cpl.zip
Regards, Zif.
Let me know what you think of it.
I know of a freeware coponent, with heavely docs, great source, ... which (have you heard it before) does all this and more... yep. I don't know your problem, but I'm going to look at it. Meanwhile, I'll give you the URL to the component and I we all can look at the source :
home page : http://www.wilsonc.demon.co.uk/delphi.htm
component : http://www.wilsonc.demon.co.uk/Delphi Components/d3cpl.zip
Regards, Zif.
Let me know what you think of it.
angerer,
maybe a silly question, but I still want to ask :
Why do you redeclare TNewCPLInfo, if it is already declared in cpl.pas?
PNewCPLInfoA = ^TNewCPLInfoA;
PNewCPLInfoW = ^TNewCPLInfoW;
PNewCPLInfo = PNewCPLInfoA;
TNewCPLInfoA = packed record
dwSize: DWORD; // similar to the commdlg
dwFlags: DWORD;
dwHelpContext: DWORD; // help context to use
lData: Longint; // user defined data
hIcon: HICON; // icon to use, this is owned by CONTROL.EXE (may be deleted)
szName: array[0..31] of AnsiChar; // short name
szInfo: array[0..63] of AnsiChar; // long name (status line)
szHelpFile: array[0..127] of AnsiChar; // path to help file to use
end;
TNewCPLInfoW = packed record
dwSize: DWORD; // similar to the commdlg
dwFlags: DWORD;
dwHelpContext: DWORD; // help context to use
lData: Longint; // user defined data
hIcon: HICON; // icon to use, this is owned by CONTROL.EXE (may be deleted)
szName: array[0..31] of WideChar; // short name
szInfo: array[0..63] of WideChar; // long name (status line)
szHelpFile: array[0..127] of WideChar; // path to help file to use
end;
TNewCPLInfo = TNewCPLInfoA;
Zif?
maybe a silly question, but I still want to ask :
Why do you redeclare TNewCPLInfo, if it is already declared in cpl.pas?
PNewCPLInfoA = ^TNewCPLInfoA;
PNewCPLInfoW = ^TNewCPLInfoW;
PNewCPLInfo = PNewCPLInfoA;
TNewCPLInfoA = packed record
dwSize: DWORD; // similar to the commdlg
dwFlags: DWORD;
dwHelpContext: DWORD; // help context to use
lData: Longint; // user defined data
hIcon: HICON; // icon to use, this is owned by CONTROL.EXE (may be deleted)
szName: array[0..31] of AnsiChar; // short name
szInfo: array[0..63] of AnsiChar; // long name (status line)
szHelpFile: array[0..127] of AnsiChar; // path to help file to use
end;
TNewCPLInfoW = packed record
dwSize: DWORD; // similar to the commdlg
dwFlags: DWORD;
dwHelpContext: DWORD; // help context to use
lData: Longint; // user defined data
hIcon: HICON; // icon to use, this is owned by CONTROL.EXE (may be deleted)
szName: array[0..31] of WideChar; // short name
szInfo: array[0..63] of WideChar; // long name (status line)
szHelpFile: array[0..127] of WideChar; // path to help file to use
end;
TNewCPLInfo = TNewCPLInfoA;
Zif?
Inprise has an FAQ on that with explanation & sample code:
http://www.inprise.com/devsupport/delphi/qanda/793.html
D.
http://www.inprise.com/devsupport/delphi/qanda/793.html
D.
ASKER
Dear ZifNab !
I tried this component from the web and it works well !
thank you
bernhard
I tried this component from the web and it works well !
thank you
bernhard
no problem. Glad I could help.
Shall I answer this question or not? I've only given you a link to a component... and 200 points for such a link is much...
Have a nice day and good luck with the component!
Zif.
Shall I answer this question or not? I've only given you a link to a component... and 200 points for such a link is much...
Have a nice day and good luck with the component!
Zif.
ASKER
Dear Zif !
yes you are right.
what do you do in this situation ?? (or what i have to do ?)
b.
yes you are right.
what do you do in this situation ?? (or what i have to do ?)
b.
What you can do is the following :
1. Give a comment on this thread that it is solved and that you don't need any help with it.
Then :
1. Ask linda gardner if she can reduce the points of this thread, and that we all agree on it.
2. Ask a new question with less points and let me answer it/or somebody else or give points to everybody who helped you with this question (deviding is up to you).
3. Do nothing.
It's up to you, I don't mind what you choose, everything is fine by me.
Zif.
It's up to you.
1. Give a comment on this thread that it is solved and that you don't need any help with it.
Then :
1. Ask linda gardner if she can reduce the points of this thread, and that we all agree on it.
2. Ask a new question with less points and let me answer it/or somebody else or give points to everybody who helped you with this question (deviding is up to you).
3. Do nothing.
It's up to you, I don't mind what you choose, everything is fine by me.
Zif.
It's up to you.
ronit, look at my comment of Date: Wednesday, August 05 1998 - 11:17AM PDT, Zif.
ASKER
Dear Zif !
yes - thank you it is solved - but how can i reach linda gardner ??
ciao
b.
yes - thank you it is solved - but how can i reach linda gardner ??
ciao
b.
angerer,
I last the e-mail myself....
but post a 0 question to customer service :
https://www.experts-exchange.com/browsing/experts-exchange/
and explain them what you want.
Regards, Zif.
I last the e-mail myself....
but post a 0 question to customer service :
https://www.experts-exchange.com/browsing/experts-exchange/
and explain them what you want.
Regards, Zif.
ASKER
Dear Zif !
please close the question with the 200 points.
ciao
b.
please close the question with the 200 points.
ciao
b.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help !
i think your service is very good. there is one thing missing: an intelligent way to find allready answered questions.
do you know a good 'Knowledge Base' on the Web.
ciao
bernhard
i think your service is very good. there is one thing missing: an intelligent way to find allready answered questions.
do you know a good 'Knowledge Base' on the Web.
ciao
bernhard
bernhard,
at https://www.experts-exchange.com there is now a search utility.
second at chamis place(which combines several databases).
Reach by Delphi Deli : http://delphi.lehner.at/
Regards, Zif.
at https://www.experts-exchange.com there is now a search utility.
second at chamis place(which combines several databases).
Reach by Delphi Deli : http://delphi.lehner.at/
Regards, Zif.
ASKER
Search Utility at Expert Exchange : sorry i dont find it - where is it ??
Chamis Place: i know this site - thanks
delphi.lehner.at: i could not reach it ??
b.
Chamis Place: i know this site - thanks
delphi.lehner.at: i could not reach it ??
b.
look at https://www.experts-exchange.com, on the top left, you can find search button.
deli has problems I think.
And another good one is :
http://developers.href.com/
Zif.
deli has problems I think.
And another good one is :
http://developers.href.com/
Zif.
Igor