Link to home
Start Free TrialLog in
Avatar of cjclayton
cjclayton

asked on

NT Service Form in Control Panel

I've created a NT service in Delphi 5 and all works fine.
Now I want to create a form that will be displayed in the control panel, so users can update registry settings for the service.  I've added a new form and set the interactive property to true.  What else do I need to do?
If you have a full example, that would be good.

Thanks
Avatar of Epsylon
Epsylon

If you use TService as skeleton, you can just add a form + unit to your project. On the object inspector set the Tform.Visible property to true.
Wouldnt it be better to just create another .exe, name it to cpl, stick it in the winnt\system32 and all it does is change the values in the registry that is relevant so the Service app can read it.
It seems a much easier way to me.
regards
Smurff
Avatar of cjclayton

ASKER

Epsylon
Setting Tform.Visible to true just make the form display immediately not in control panel.
Re-reading your question, I think you have to create a (separate) control panel applet. File menu > New > Control Panel Application.
ASKER CERTIFIED SOLUTION
Avatar of smurff
smurff

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ive added the code for the form. Ive made a simple form and just out an edit box on there and a button that shows whats in the editbox.

Heres the .dpr
library ControlPL;

//  Name : CONTROLPL
//  Description : Sample Windows control panel applet.
//  Author : Neil Jones (abton@operamail.com)
//  Date : 10/03/1999
//
//  Notes :
//
//  I created this as I could not find an example Control Panel applet
//  written in Delphi anywhere.  You are free to use it as you wish.
//
//  A control panel applet is basically a DLL that displays a modal form
//  renamed with a '.cpl' extension.
//  But, it must export a function called CPlApplet that processes a series
//  of messages sent by Windows in a specific order.
//  To install the applet, just place it in your \windows\system directory.
//
//  Please note, Windows caches the icon, title and description information.
//  So if you change them and they do not change in the control panel - delete
//  the '.cpl' from the \windows\system directory and copy in a new one.

uses
  SysUtils,
  CPL,
  Dialogs,
  Windows,
  Classes,
  forms,
  DllForm in 'DllForm.pas' {frmDllForm};

//  Include required resources (an icon and two strings)
//  See main.rc for more details
{$R main.res}

var
   CPLInfo : pCPLINFO;
   ThisInst, IconHandle : integer;

//  The exported function MUST be declared like this!
function CPlApplet(hwndCPl: THandle; uMsg: DWORD;
                   lParam1, lParam2: Longint): Longint; stdcall;
begin
     //  You MUST process these events
     case uMsg of
          //  CPL_INIT - Initialise the application.  Put your initialisation
          //  code here.
          CPL_INIT : begin
                          //  Use the name of your control panel applet here
                          ThisInst := GetModuleHandle('ControlPL.cpl');
                          //  Get a handle to our icon from main.res for use later
                          IconHandle := LoadIcon(ThisInst, 'APPLET_ICON');
                          //  Return nonzero to indicate success
                          result := 1;
                     end;
          //  CPL_GETCOUNT - Return the number of dialogs we have (only 1 in this case)
          CPL_GETCOUNT : result := 1;
          //  CPL_INQUIRE - Return information required to display an icon in the control panel.
          CPL_INQUIRE : begin
                             //  lParam2 is a pointer to a CPLINFO structure, so get a handle to it.
                             CPLInfo := pCPLINFO(lParam2);
                             //  Point the icon towards the icon handle obtained earlier.
                             CPLInfo^.idIcon := IconHandle;
                             //  The app name is defined in string resource 1 (see main.rc)
                             CPLInfo^.idName := 1;
                             //  The app description is defined in string resource 2 (see main.rc)
                             CPLInfo^.idInfo := 2;
                             //  Not used so set to 0
                             CPLInfo^.lData := 0;
                             //  Return zero to indicate success
                             result := 0;
                        end;
          //  CPL_DBLCLK - This occurs when our app is actually run.
          CPL_DBLCLK : begin
                            //  Call your dialog/modal form from here.
                            //  Note - the form must be modal
                        frmDllForm :=TfrmDllForm.Create(nil);
                        Result := frmDllForm.ShowModal;
                            //  Return zero to indicate success
                            result := 0;
                       end;
          //  CPL_STOP - Called when application is de-initialised
          CPL_STOP : begin
                          //  Perform your cleanup code here.
                          //  Return zero to indicate success
                          result := 0;
                     end;
          //  CPL_EXIT - Control panel is exiting.
          CPL_EXIT : begin
                          //  Return zero to indicate success
                          result := 0;
                     end;
     else
         //  All other events, just return 0 (processed OK)
         result := 0;
     end;
end;

exports
       CPlApplet;

begin
end.


--------------------------cut--------------------
and now heres the DllForm.pas

unit DllForm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TfrmDllForm = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmDllForm: TfrmDllForm;

implementation

{$R *.DFM}

procedure TfrmDllForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TfrmDllForm.Button1Click(Sender: TObject);
begin
ShowMessage(edit1.text);
end;

end.


Hope this helps

regards
Smurff
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if they are still open in 14 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  https://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
https://www.experts-exchange.com/questions/Q.12007619.html
https://www.experts-exchange.com/questions/Q.20074880.html
https://www.experts-exchange.com/questions/Q.20090157.html
https://www.experts-exchange.com/questions/Q.20107509.html
https://www.experts-exchange.com/questions/Q.20110418.html
https://www.experts-exchange.com/questions/Q.20153985.html
https://www.experts-exchange.com/questions/Q.20162557.html
https://www.experts-exchange.com/questions/Q.20186199.html
https://www.experts-exchange.com/questions/Q.20257200.html
https://www.experts-exchange.com/questions/Q.20291160.html

To view your locked questions, please click the following link(s) and evaluate the proposed answer.
https://www.experts-exchange.com/questions/Q.20186210.html

*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
https://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed in the link below
https://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @14 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
Avatar of Russell Libby
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept smurff's comment as answer

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Thank you,
Russell

EE Cleanup Volunteer
I forgot about this one :)

Smurff,
I'm not surprised, as its been almost 2 years. I will be turning in my list of Q's and recommendations on or around 6/18..6/20, and hopefully the moderators will close these shortly after.

Best Regards,
Russell