Solved

NT Service Form in Control Panel

Posted on 2001-07-19
11
386 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

737 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