Solved

NT Service Form in Control Panel

Posted on 2001-07-19
11
385 Views
Last Modified: 2010-07-27
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
0
Comment
Question by:cjclayton
  • 4
  • 2
  • 2
  • +2
11 Comments
 
LVL 13

Expert Comment

by:Epsylon
ID: 6301664
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.
0
 
LVL 3

Expert Comment

by:smurff
ID: 6302707
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
0
 

Author Comment

by:cjclayton
ID: 6305598
Epsylon
Setting Tform.Visible to true just make the form display immediately not in control panel.
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 13

Expert Comment

by:Epsylon
ID: 6305862
Re-reading your question, I think you have to create a (separate) control panel applet. File menu > New > Control Panel Application.
0
 
LVL 3

Accepted Solution

by:
smurff earned 100 total points
ID: 6307863
here is a control panel example. its quite easy to follow just change the CPL_DBLCLK : //your code

If you need a form then theres loads of articals saying "forms in a dll" if not then let me know and
Ill dig one out.

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,         //  Include this for the message definitions etc.
 Dialogs,
 Windows,
 Classes;

//  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('lac.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
                           ShowMessage('Write you registry changing code here');
                           //  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.



regards
Smurff
0
 
LVL 3

Expert Comment

by:smurff
ID: 6307996
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
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6976112
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.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://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.
http://www.experts-exchange.com/questions/Q.12007619.html
http://www.experts-exchange.com/questions/Q.20074880.html
http://www.experts-exchange.com/questions/Q.20090157.html
http://www.experts-exchange.com/questions/Q.20107509.html
http://www.experts-exchange.com/questions/Q.20110418.html
http://www.experts-exchange.com/questions/Q.20153985.html
http://www.experts-exchange.com/questions/Q.20162557.html
http://www.experts-exchange.com/questions/Q.20186199.html
http://www.experts-exchange.com/questions/Q.20257200.html
http://www.experts-exchange.com/questions/Q.20291160.html

To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://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
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://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
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 8703637
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
0
 
LVL 3

Expert Comment

by:smurff
ID: 8708492
I forgot about this one :)
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 8708616

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
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question