Add control panel program on Windows Mobile

Source: Internet
Author: User

In Windows Mobile, users can access control panel applications through settings. Software developers can also access control panel information through the API functions provided by Windows Mobile, for example, you can add a control panel application to it.

 

The control panel application is implemented as a DLL, but must be suffixed with Cpl. It exports a callback function:

LONG CPlApplet(HWND hwndCPl, UINT msg, LPARAM lParam1, LPARAM lParam2);

When users click to set up, the ctlpnl.exe process will send some messages by calling the cplapplet. a cpl can support the applets of multiple control panels ):

Hwndcpl: Control Panel window handle, which is the parent window of the applet.

MSG: controls the messages sent by the panel program (ctlpnl.exe) to our application. These messages determine the application initialization, startup, stop, and exit. They mainly include:

Cpl_init, cpl_getcount, cpl_newinquire, cpl_idname, cpl_dblclk, cpl_stop, and cpl_exit.

Cpl_init: The ctlpnl.exe notifies the control panel application to perform global initialization, such as memory allocation.

Cpl_getcount: obtains the number of small programs supported by Control Panel applications.

Cpl_newinquire: Query Information about the applet of the Control Panel application. The information is contained in the newcplinfo structure.

Cpl_idname: Obtain the name of the Control Panel application. By setting the following registry key value, you can change the location of the application on the control panel property page.

 

[HKEY_LOCAL_MACHINE/ControlPanel/<ID name>].

"Group" = dword:1

Group Value

Settings tab where CPL exists

0

Personal

1 (default value)

System

2

Connections


Cpl_dblclk: This message indicates that you have clicked the control panel application and can start a process here to complete the corresponding work.

Cpl_stop and cpl_exit: Stop messages and exit messages respectively.

The following is a simple example:
First, create a Win32 smart device project DLL project for smart device,
Add the following code:

 

// Testcpl. cpp: defines the entry point for the DLL application.

# Include "stdafx. H"
# Include <Cpl. h>

# Define num_applets 1

Hinstance g_hinstance = NULL;

Typedef struct tagapplets
{
Int icon; // icon Resource Identifier
Int namestring; // name-string Resource Identifier
Int descstring; // description-string Resource Identifier
} Applets;

Const applets systemapplets [] =
{
Applet_icon, applet_name, applet_desc
// Add more struct Members here if supporting more than on Applet
};

Bool apientry dllmain (handle hmodule,
DWORD ul_reason_for_call,
Lpvoid lpreserved
)
{
If (dll_process_attach = ul_reason_for_call)
G_hinstance = (hinstance) hmodule;

Return true;
}

Bool initapplet (hwnd hwndparent)
{
Return true;
}

Void termapplet ()
{
Return;
}

//////////////////////////////////////// ////////////////
// This is the entry point called by ctlpnl.exe
//////////////////////////////////////// ////////////////

Long callback cplapplet (hwnd hwndcpl, uint umsg, long lparam1, long lparam2)
{
Int iapplet;
Lpnewcplinfo;
Static int iinitcount = 0;

Switch (umsg)
{
// First message sent. It is sent only once
// Allow the DLL to initialize it's applet (s)
Case cpl_init:
If (! Iinitcount)
{
If (! Initapplet (hwndcpl ))
Return false;
}
Iinitcount ++;
Return true;

// Second message sent. Return the Count of applets supported
// By this DLL
Case cpl_getcount:
Return (long) num_applets;

// Third message sent. Sent once for each applet supported by this DLL.
// The lparam1 contains the number that indicates which applet this is
// For, from 0 to 1 less than the Count of applets.
// Lparam2 is a newcplinfo that shoshould be filled with information about
// This applet before returning
Case cpl_newinquire:
Lpnewcplinfo = (lpnewcplinfo) lparam2;
Iapplet = (INT) lparam1;
Lpnewcplinfo-> dwsize = (DWORD) sizeof (newcplinfo );
Lpnewcplinfo-> dwflags = 0;
Lpnewcplinfo-> dwhelpcontext = 0;
Lpnewcplinfo-> ldata = systemapplets [iapplet]. Icon;
Lpnewcplinfo-> hicon = loadicon (g_hinstance, (lpctstr) makeintresource (systemapplets [iapplet]. Icon ));
Lpnewcplinfo-> szhelpfile [0] = '/0 ';

Loadstring (g_hinstance, systemapplets [iapplet]. namestring, lpnewcplinfo-> szname, 32 );
Loadstring (g_hinstance, systemapplets [iapplet]. descstring, lpnewcplinfo-> szinfo, 64 );

Break;

Case cpl_idname:
_ Tcscpy (lpwstr) lparam2, _ T ("device information "));

Break;

// This is sent whenever the user clicks an icon in settings for one
// The applets supported by this DLL. lparam1 contains the number indicating
// Which applet. Return 0 if applet successfully launched, non-zero otherwise
Case cpl_dblclk:
Iapplet = (uint) lparam1;
// Loaddialog (g_hinstance, hwndcpl );
CreateProcess (_ T ("deviceinfo.exe"), null, null );
Break;

// Sent once per applet, before cpl_exit
Case cpl_stop:
Break;

// Sent once before the DLL is unloaded
Case cpl_exit:
Iinitcount --;
If (! Iinitcount)
Termapplet ();
Break;

Default:
Break;
}
Return 0;
}

// Testcpl. Def

Library "testcpl"

Exports dllmain

Cplapplet

In addition, add the registry key value as follows:

[HKEY_LOCAL_MACHINE/controlpanel/device information].

"Group" = DWORD: 1


 

The following is a supplement from another article:

 

 

By default, the project generates DLL files and the Control Panel (. CPL) files, which must be configured as follows:

1. Mybacklight(Project name) Right-click-> -〉 Properties-> -〉 Configuration Properties-> -〉 Debugging. Linker-> -〉 General-> -〉 Output fileSet $ (Outdir)/mybacklight. Cpl (that is, change the suffix DLL to CPL)

2.Remote executableSet to "/Windows/ctlpnl.exe ";Command argumentsSet to "mybacklight. Cpl ".
(You can not set it, but you can deepen your understanding of the CPL program.) The configuration is complete, and the newly added AP icon is addedSetting-> -〉SystemIf you want to specifyPersonalOrConnectionTo process the cpl_idname message in the cplapplet.GroupValue: 0 -- personal, 1 -- System (default ),
2 -- connection.

The above program writes the Registry directly in the reg file (such as platform. Reg). It is written in the program here. I have only tried the previous one. The following is a reference.Case cpl_idname:
{
Uint uapp = lparam1;
Lpwstr pszname = (lptstr) lparam2; tchar szkey [2, 100];
_ Tcscpy (pszname, text ("mybacklight "));
Swprintf (szkey, l "controlpanel // % s", pszname );
DWORD dwsize = sizeof (DWORD );
Hkey;
DWORD dwdisp;
DWORD dwgroup; dwgroup = 0;


Regcreatekeyexw (HKEY_LOCAL_MACHINE, szkey, 0, null, 0, key_all_access, null, & hkey, & dwdisp );
Regsetvalueexw (hkey, l "group", 0, REG_DWORD, (lpbyte) & dwgroup, sizeof (DWORD ));
Return 0;
}

--------------------------------------------------
Supplement:
1. There is an example in the Windows Mobile 6 SDK called mybacklight. You can refer to the code above.

2. The vast majority of code does not need to be changed, as long as there are:
(1) Change the output files suffix DLL to Cpl in the Project Properties
(2) cpl_dblclk
(3) cpl_idname
(4) Registry Key. To determine where your CPl program appears.
[HKEY_LOCAL_MACHINE/controlpanel/
Device information].

"Group" = dword:1


3. At the beginning, I was wrong about how to set the position of the CPL program. I thought it was enough to set the registry.

In fact, setting the registry is only one step. Another step is to process the cpl_idname message,

Set the name of the Control Panel applet for the message, which may not be the same as the name of the program itself,

But it must be the same as the name set in the registry. This is the link between the program and the settings in the registry.


 

4. In the CPl. h file of the example, cpl_idname is not defined. Add the following statement to it:

# Define cpl_idname 100

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.