Solved

NT Service Form in Control Panel

Posted on 2001-07-19
11
375 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
Comment Utility
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
Comment Utility
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
Comment Utility
Epsylon
Setting Tform.Visible to true just make the form display immediately not in control panel.
0
 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Expert Comment

by:smurff
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I forgot about this one :)
0
 
LVL 26

Expert Comment

by:Russell Libby
Comment Utility

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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
IExtractImage Delphi 14 162
PDF library for Delphi 2 89
Send message from delphi to whatsapp, is it possible? 3 912
select query - oracle 16 81
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now