From 26be094c41a885a113d7089620031f71dc373257 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sat, 30 Oct 2004 12:38:52 +0000 Subject: [PATCH] Add ability to start individual control panel applications. svn path=/trunk/; revision=11476 --- reactos/lib/cpl/control/Makefile | 4 +- reactos/lib/cpl/control/control.c | 164 ++++++++++++++++++++++++------ 2 files changed, 135 insertions(+), 33 deletions(-) diff --git a/reactos/lib/cpl/control/Makefile b/reactos/lib/cpl/control/Makefile index 1ad6360f659..dd90c838987 100644 --- a/reactos/lib/cpl/control/Makefile +++ b/reactos/lib/cpl/control/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.3 2004/06/30 12:10:12 ekohl Exp $ +# $Id: Makefile,v 1.4 2004/10/30 12:38:52 ekohl Exp $ PATH_TO_TOP = ../../.. @@ -21,7 +21,7 @@ TARGET_CFLAGS = \ -Werror \ -fno-builtin -TARGET_SDKLIBS = kernel32.a user32.a comctl32.a +TARGET_SDKLIBS = ntdll.a kernel32.a user32.a comctl32.a # TARGET_GCCLIBS = gcc diff --git a/reactos/lib/cpl/control/control.c b/reactos/lib/cpl/control/control.c index 947a4e962c2..0b07f5991b2 100644 --- a/reactos/lib/cpl/control/control.c +++ b/reactos/lib/cpl/control/control.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: control.c,v 1.7 2004/10/29 16:59:16 ekohl Exp $ +/* $Id: control.c,v 1.8 2004/10/30 12:38:52 ekohl Exp $ * * PROJECT: ReactOS System Control Panel * FILE: lib/cpl/system/control.c @@ -297,36 +297,138 @@ LRESULT CALLBACK MyWindowProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam) } -#ifdef _MSVC -int WINAPI wWinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,WCHAR *lpCmdLine,int nCmdShow) -#else -int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,char *lpCmdLine,int nCmdShow) -#endif +static INT +RunControlPanelWindow(int nCmdShow) { - MSG msg; - WNDCLASS wc; - - hInst = hInstance; - CTL_DEBUG((_T("My Control Panel\r\n"))); - memset(&wc,0x00,sizeof(wc)); - wc.hIcon = LoadIcon(hInst,MAKEINTRESOURCE(IDI_MAINICON)); - wc.lpszClassName = MYWNDCLASS; - wc.lpszMenuName = _T("MAINMENU"); - wc.lpfnWndProc = MyWindowProc; - RegisterClass(&wc); - InitCommonControls(); - hMainWnd = CreateWindowEx(WS_EX_CLIENTEDGE,MYWNDCLASS,_T("Control Panel"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,LoadMenu(hInst,MAKEINTRESOURCE(IDM_MAINMENU)),hInst,0); - if (!hMainWnd) - { - CTL_DEBUG((_T("Unable to create window\r\n"))); - return -1; - } - ShowWindow(hMainWnd,nCmdShow); - while (GetMessage(&msg,0,0,0)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } + MSG msg; + WNDCLASS wc; + + memset(&wc,0x00,sizeof(wc)); + wc.hIcon = LoadIcon(hInst,MAKEINTRESOURCE(IDI_MAINICON)); + wc.lpszClassName = MYWNDCLASS; + wc.lpszMenuName = _T("MAINMENU"); + wc.lpfnWndProc = MyWindowProc; + RegisterClass(&wc); + + InitCommonControls(); + + hMainWnd = CreateWindowEx(WS_EX_CLIENTEDGE, + MYWNDCLASS, + _T("Control Panel"), + WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, + CW_USEDEFAULT, + CW_USEDEFAULT, + CW_USEDEFAULT, + NULL, + LoadMenu(hInst, MAKEINTRESOURCE(IDM_MAINMENU)), + hInst, + 0); + if (!hMainWnd) + { + CTL_DEBUG((_T("Unable to create window\r\n"))); + return -1; + } + + ShowWindow(hMainWnd, nCmdShow); + while (GetMessage(&msg, 0, 0, 0)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + + return 0; +} - return 0; + +static INT +RunControlPanel(LPCTSTR lpName, UINT uIndex) +{ + CPLINFO CplInfo; + HMODULE hDll; + CPLAPPLETFUNC pFunc; + UINT uPanelCount; + + hDll = LoadLibrary(lpName); + if (hDll == 0) + { + return -1; + } + CTL_DEBUG((_T("Handle %08X\r\n"), hDll)); + + pFunc = (CPLAPPLETFUNC)GetProcAddress(hDll, "CPlApplet"); + if (pFunc == NULL) + { + FreeLibrary(hDll); + return -1; + } + CTL_DEBUG((_T("CPLFunc %08X\r\n"), pFunc)); + + if (!pFunc(NULL, CPL_INIT, 0, 0)) + { + FreeLibrary(hDll); + return -1; + } + + uPanelCount = (UINT)pFunc(NULL, CPL_GETCOUNT, 0, 0); + if (uIndex >= uPanelCount) + { + FreeLibrary(hDll); + return -1; + } + + pFunc(NULL, CPL_INQUIRE, (LPARAM)uIndex, (LPARAM)&CplInfo); + + pFunc(NULL, CPL_DBLCLK, CplInfo.lData, 0); + + FreeLibrary(hDll); + + return 0; +} + + +int WINAPI +WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) +{ + LPTSTR lpCommandLine; + LPTSTR lpParam; + + hInst = hInstance; + CTL_DEBUG((_T("My Control Panel\r\n"))); + + lpCommandLine = GetCommandLine(); + + CTL_DEBUG((_T("CommandLine: %s\n"), lpCommandLine)); + + lpParam = _tcschr(lpCommandLine, _T(' ')); + if (lpParam == NULL) + { + /* No argument on the command line */ + return RunControlPanelWindow(nCmdShow); + } + + lpParam++; + + if (_tcsicmp(lpParam, _T("desktop")) == 0) + { + return RunControlPanel(_T("desk.cpl"), 0); + } + else if (_tcsicmp(lpParam, _T("date/time")) == 0) + { + return RunControlPanel(_T("timedate.cpl"), 0); + } + else if (_tcsicmp(lpParam, _T("international")) == 0) + { + return RunControlPanel(_T("intl.cpl"), 0); + } + else if (_tcsicmp(lpParam, _T("mouse")) == 0) + { + return RunControlPanel(_T("main.cpl"), 0); + } + else if (_tcsicmp(lpParam, _T("keyboard")) == 0) + { + return RunControlPanel(_T("main.cpl"), 1); + } + + return 0; } -- 2.17.1