2004-06-18 20:43:44 +00:00
/*
* ReactOS
* Copyright ( C ) 2004 ReactOS Team
* Copyright ( C ) 2004 GkWare e . K .
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
2004-10-29 16:59:16 +00:00
/* $Id: control.c,v 1.7 2004/10/29 16:59:16 ekohl Exp $
2004-06-18 20:43:44 +00:00
*
* PROJECT : ReactOS System Control Panel
2004-06-28 12:05:16 +00:00
* FILE : lib / cpl / system / control . c
2004-06-18 20:43:44 +00:00
* PURPOSE : ReactOS System Control Panel
* PROGRAMMER : Gero Kuehn ( reactos . filter @ gkware . com )
* UPDATE HISTORY :
* 06 - 13 - 2004 Created
*/
2004-06-30 12:11:11 +00:00
# include <windows.h>
# include <commctrl.h>
# include <cpl.h>
2004-06-18 20:43:44 +00:00
# include <stdlib.h>
# include <stdio.h>
# include <stdarg.h>
# include <tchar.h>
# include "resource.h"
//#define CONTROL_DEBUG_ENABLE
# ifdef CONTROL_DEBUG_ENABLE
# define CTL_DEBUG(x) dbgprint x
# else
# define CTL_DEBUG(x)
# endif
2004-06-28 12:05:16 +00:00
# define MYWNDCLASS _T("CTLPANELCLASS")
typedef LONG ( CALLBACK * CPLAPPLETFUNC ) ( HWND hwndCPL , UINT uMsg , LPARAM lParam1 , LPARAM lParam2 ) ;
typedef struct CPLLISTENTRY
{
TCHAR pszPath [ MAX_PATH ] ;
2004-10-29 12:27:58 +00:00
HMODULE hDll ;
2004-06-28 12:05:16 +00:00
CPLAPPLETFUNC pFunc ;
2004-10-29 12:27:58 +00:00
CPLINFO CplInfo ;
2004-06-28 12:05:16 +00:00
int nIndex ;
2004-10-29 12:27:58 +00:00
} CPLLISTENTRY , * PCPLLISTENTRY ;
2004-06-28 12:05:16 +00:00
HWND hListView ;
2004-06-18 20:43:44 +00:00
HINSTANCE hInst ;
HWND hMainWnd ;
2004-09-15 16:03:09 +00:00
DEVMODE pDevMode ;
2004-06-18 20:43:44 +00:00
2004-10-29 12:27:58 +00:00
VOID dbgprint ( TCHAR * format , . . . )
2004-06-18 20:43:44 +00:00
{
TCHAR buf [ 1000 ] ;
va_list va ;
2004-10-29 12:27:58 +00:00
2004-06-18 20:43:44 +00:00
va_start ( va , format ) ;
_vstprintf ( buf , format , va ) ;
OutputDebugString ( buf ) ;
va_end ( va ) ;
}
2004-10-29 12:27:58 +00:00
VOID PopulateCPLList ( HWND hLisCtrl )
2004-06-18 20:43:44 +00:00
{
WIN32_FIND_DATA fd ;
HANDLE hFind ;
TCHAR pszSearchPath [ MAX_PATH ] ;
2004-06-19 00:11:44 +00:00
HIMAGELIST hImgListSmall ;
HIMAGELIST hImgListLarge ;
2004-10-29 12:27:58 +00:00
int ColorDepth ;
HMODULE hDll ;
CPLAPPLETFUNC pFunc ;
TCHAR pszPath [ MAX_PATH ] ;
2004-09-15 16:03:09 +00:00
2004-10-29 12:27:58 +00:00
/* Icon drawing mode */
2004-09-15 16:03:09 +00:00
pDevMode . dmSize = sizeof ( DEVMODE ) ;
pDevMode . dmDriverExtra = 0 ;
2004-10-29 12:27:58 +00:00
2004-09-15 16:03:09 +00:00
EnumDisplaySettings ( NULL , ENUM_CURRENT_SETTINGS , & pDevMode ) ;
2004-10-29 12:27:58 +00:00
switch ( pDevMode . dmBitsPerPel )
2004-09-15 16:03:09 +00:00
{
2004-10-29 12:27:58 +00:00
case 32 : ColorDepth = ILC_COLOR32 ; break ;
case 24 : ColorDepth = ILC_COLOR24 ; break ;
case 16 : ColorDepth = ILC_COLOR16 ; break ;
case 8 : ColorDepth = ILC_COLOR8 ; break ;
case 4 : ColorDepth = ILC_COLOR4 ; break ;
default : ColorDepth = ILC_COLOR ; break ;
2004-09-15 16:03:09 +00:00
}
2004-10-29 12:27:58 +00:00
hImgListSmall = ImageList_Create ( 16 , 16 , ColorDepth | ILC_MASK , 5 , 5 ) ;
hImgListLarge = ImageList_Create ( 32 , 32 , ColorDepth | ILC_MASK , 5 , 5 ) ;
GetSystemDirectory ( pszSearchPath , MAX_PATH ) ;
_tcscat ( pszSearchPath , _T ( " \\ *.cpl " ) ) ;
hFind = FindFirstFile ( pszSearchPath , & fd ) ;
while ( hFind ! = INVALID_HANDLE_VALUE )
2004-06-18 20:43:44 +00:00
{
2004-10-29 12:27:58 +00:00
PCPLLISTENTRY pEntry ;
CTL_DEBUG ( ( _T ( " Found %s \r \n " ) , fd . cFileName ) ) ;
_tcscpy ( pszPath , pszSearchPath ) ;
* _tcsrchr ( pszPath , ' \\ ' ) = 0 ;
_tcscat ( pszPath , _T ( " \\ " ) ) ;
_tcscat ( pszPath , fd . cFileName ) ;
hDll = LoadLibrary ( pszPath ) ;
CTL_DEBUG ( ( _T ( " Handle %08X \r \n " ) , hDll ) ) ;
pFunc = ( CPLAPPLETFUNC ) GetProcAddress ( hDll , " CPlApplet " ) ;
CTL_DEBUG ( ( _T ( " CPLFunc %08X \r \n " ) , pFunc ) ) ;
if ( pFunc & & pFunc ( hLisCtrl , CPL_INIT , 0 , 0 ) )
2004-06-18 20:43:44 +00:00
{
2004-10-29 12:27:58 +00:00
UINT i , uPanelCount ;
uPanelCount = ( UINT ) pFunc ( hLisCtrl , CPL_GETCOUNT , 0 , 0 ) ;
for ( i = 0 ; i < uPanelCount ; i + + )
2004-06-18 20:43:44 +00:00
{
2004-06-19 00:11:44 +00:00
HICON hIcon ;
TCHAR Name [ MAX_PATH ] ;
int index ;
2004-06-18 20:43:44 +00:00
2004-10-29 12:27:58 +00:00
pEntry = ( PCPLLISTENTRY ) malloc ( sizeof ( CPLLISTENTRY ) ) ;
if ( pEntry = = NULL )
return ;
memset ( pEntry , 0 , sizeof ( CPLLISTENTRY ) ) ;
pEntry - > hDll = hDll ;
pEntry - > pFunc = pFunc ;
_tcscpy ( pEntry - > pszPath , pszPath ) ;
pEntry - > pFunc ( hLisCtrl , CPL_INQUIRE , ( LPARAM ) i , ( LPARAM ) & pEntry - > CplInfo ) ;
hIcon = LoadImage ( pEntry - > hDll , MAKEINTRESOURCE ( pEntry - > CplInfo . idIcon ) , IMAGE_ICON , 16 , 16 , LR_DEFAULTCOLOR ) ;
2004-06-18 20:43:44 +00:00
index = ImageList_AddIcon ( hImgListSmall , hIcon ) ;
2004-06-29 12:03:56 +00:00
DestroyIcon ( hIcon ) ;
2004-10-29 12:27:58 +00:00
hIcon = LoadImage ( pEntry - > hDll , MAKEINTRESOURCE ( pEntry - > CplInfo . idIcon ) , IMAGE_ICON , 32 , 32 , LR_DEFAULTCOLOR ) ;
2004-06-18 20:43:44 +00:00
ImageList_AddIcon ( hImgListLarge , hIcon ) ;
2004-06-29 12:03:56 +00:00
DestroyIcon ( hIcon ) ;
2004-06-18 20:43:44 +00:00
2004-10-29 12:27:58 +00:00
if ( LoadString ( pEntry - > hDll , pEntry - > CplInfo . idName , Name , MAX_PATH ) )
2004-06-18 20:43:44 +00:00
{
2004-10-29 12:27:58 +00:00
LV_ITEM lvi ;
2004-06-18 20:43:44 +00:00
2004-10-29 12:27:58 +00:00
memset ( & lvi , 0x00 , sizeof ( lvi ) ) ;
2004-10-29 16:59:16 +00:00
lvi . mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE | LVIF_IMAGE ;
2004-10-29 12:27:58 +00:00
lvi . pszText = Name ;
lvi . state = 0 ;
lvi . iImage = index ;
lvi . lParam = ( LPARAM ) pEntry ;
pEntry - > nIndex = ListView_InsertItem ( hLisCtrl , & lvi ) ;
2004-06-18 20:43:44 +00:00
2004-10-29 12:27:58 +00:00
if ( LoadString ( pEntry - > hDll , pEntry - > CplInfo . idInfo , Name , MAX_PATH ) )
ListView_SetItemText ( hLisCtrl , pEntry - > nIndex , 1 , Name ) ;
2004-06-18 20:43:44 +00:00
}
}
}
2004-10-29 12:27:58 +00:00
if ( ! FindNextFile ( hFind , & fd ) )
2004-06-18 20:43:44 +00:00
hFind = INVALID_HANDLE_VALUE ;
}
2004-10-29 12:27:58 +00:00
ListView_SetImageList ( hLisCtrl , hImgListSmall , LVSIL_SMALL ) ;
ListView_SetImageList ( hLisCtrl , hImgListLarge , LVSIL_NORMAL ) ;
2004-06-18 20:43:44 +00:00
}
LRESULT CALLBACK MyWindowProc ( HWND hWnd , UINT uMsg , WPARAM wParam , LPARAM lParam )
{
2004-10-29 12:27:58 +00:00
switch ( uMsg )
2004-06-18 20:43:44 +00:00
{
case WM_CREATE :
2004-06-28 12:05:16 +00:00
{
2004-10-29 12:27:58 +00:00
RECT rect ;
LV_COLUMN column ;
GetClientRect ( hWnd , & rect ) ;
2004-10-29 16:59:16 +00:00
hListView = CreateWindow ( WC_LISTVIEW , _T ( " " ) , LVS_REPORT | LVS_ALIGNLEFT | LVS_SORTASCENDING | LVS_AUTOARRANGE | LVS_SINGLESEL | WS_VISIBLE | WS_CHILD | WS_TABSTOP , 0 , 0 , rect . right , rect . bottom , hWnd , NULL , hInst , 0 ) ;
2004-10-29 12:27:58 +00:00
CTL_DEBUG ( ( _T ( " Listview Window %08X \r \n " ) , hListView ) ) ;
memset ( & column , 0x00 , sizeof ( column ) ) ;
2004-10-29 16:59:16 +00:00
column . mask = LVCF_FMT | LVCF_WIDTH | LVCF_SUBITEM | LVCF_TEXT ;
column . fmt = LVCFMT_LEFT ;
2004-10-29 12:27:58 +00:00
column . cx = ( rect . right - rect . left ) / 3 ;
column . iSubItem = 0 ;
column . pszText = _T ( " Name " ) ;
ListView_InsertColumn ( hListView , 0 , & column ) ;
column . cx = ( rect . right - rect . left ) - ( ( rect . right - rect . left ) / 3 ) - 1 ;
column . iSubItem = 1 ;
column . pszText = _T ( " Comment " ) ;
ListView_InsertColumn ( hListView , 1 , & column ) ;
PopulateCPLList ( hListView ) ;
ListView_SetColumnWidth ( hListView , 2 , LVSCW_AUTOSIZE_USEHEADER ) ;
ListView_Update ( hListView , 0 ) ;
SetFocus ( hListView ) ;
2004-06-19 00:11:44 +00:00
}
2004-06-18 20:43:44 +00:00
break ;
2004-10-29 12:27:58 +00:00
2004-06-18 20:43:44 +00:00
case WM_DESTROY :
2004-06-28 12:05:16 +00:00
PostQuitMessage ( 0 ) ;
2004-06-18 20:43:44 +00:00
break ;
2004-10-29 12:27:58 +00:00
2004-06-18 20:43:44 +00:00
case WM_SIZE :
2004-06-28 12:05:16 +00:00
{
2004-10-29 12:27:58 +00:00
RECT rect ;
GetClientRect ( hWnd , & rect ) ;
MoveWindow ( hListView , 0 , 0 , rect . right , rect . bottom , TRUE ) ;
2004-06-19 00:11:44 +00:00
}
2004-06-18 20:43:44 +00:00
break ;
2004-10-29 12:27:58 +00:00
2004-06-18 20:43:44 +00:00
case WM_NOTIFY :
2004-06-28 12:05:16 +00:00
{
2004-10-29 12:27:58 +00:00
NMHDR * phdr ;
phdr = ( NMHDR * ) lParam ;
switch ( phdr - > code )
2004-06-18 20:43:44 +00:00
{
2004-10-29 12:27:58 +00:00
case NM_RETURN :
case NM_DBLCLK :
{
int nSelect ;
LV_ITEM lvi ;
PCPLLISTENTRY pEntry ;
nSelect = SendMessage ( hListView , LVM_GETNEXTITEM , ( WPARAM ) - 1 , LVNI_FOCUSED ) ;
if ( nSelect = = - 1 )
{
/* no items */
MessageBox ( hWnd , _T ( " No Items in ListView " ) , _T ( " Error " ) , MB_OK | MB_ICONINFORMATION ) ;
break ;
}
CTL_DEBUG ( ( _T ( " Select %d \r \n " ) , nSelect ) ) ;
memset ( & lvi , 0x00 , sizeof ( lvi ) ) ;
lvi . iItem = nSelect ;
lvi . mask = LVIF_PARAM ;
ListView_GetItem ( hListView , & lvi ) ;
pEntry = ( PCPLLISTENTRY ) lvi . lParam ;
CTL_DEBUG ( ( _T ( " Listview DblClk Entry %08X \r \n " ) , pEntry ) ) ;
if ( pEntry )
{
CTL_DEBUG ( ( _T ( " Listview DblClk Entry Func %08X \r \n " ) , pEntry - > pFunc ) ) ;
}
if ( pEntry & & pEntry - > pFunc )
pEntry - > pFunc ( hListView , CPL_DBLCLK , pEntry - > CplInfo . lData , 0 ) ;
}
2004-06-19 00:11:44 +00:00
}
}
2004-06-18 20:43:44 +00:00
break ;
2004-10-29 12:27:58 +00:00
2004-06-18 20:43:44 +00:00
case WM_COMMAND :
2004-10-29 12:27:58 +00:00
switch ( LOWORD ( wParam ) )
2004-06-18 20:43:44 +00:00
{
2004-06-29 12:03:56 +00:00
case IDM_LARGEICONS :
2004-06-18 20:43:44 +00:00
SetWindowLong ( hListView , GWL_STYLE , LVS_ICON | LVS_ALIGNLEFT | LVS_AUTOARRANGE | LVS_SINGLESEL | WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP ) ;
break ;
2004-06-29 12:03:56 +00:00
case IDM_SMALLICONS :
2004-06-18 20:43:44 +00:00
SetWindowLong ( hListView , GWL_STYLE , LVS_SMALLICON | LVS_ALIGNLEFT | LVS_AUTOARRANGE | LVS_SINGLESEL | WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP ) ;
break ;
2004-06-29 12:03:56 +00:00
case IDM_LIST :
2004-06-18 20:43:44 +00:00
SetWindowLong ( hListView , GWL_STYLE , LVS_LIST | LVS_ALIGNLEFT | LVS_AUTOARRANGE | LVS_SINGLESEL | WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP ) ;
break ;
2004-06-29 12:03:56 +00:00
case IDM_DETAILS :
2004-06-18 20:43:44 +00:00
SetWindowLong ( hListView , GWL_STYLE , LVS_REPORT | LVS_ALIGNLEFT | LVS_AUTOARRANGE | LVS_SINGLESEL | WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP ) ;
break ;
2004-06-29 12:03:56 +00:00
case IDM_CLOSE :
2004-06-18 20:43:44 +00:00
DestroyWindow ( hWnd ) ;
break ;
2004-06-29 12:03:56 +00:00
case IDM_ABOUT :
2004-06-18 20:43:44 +00:00
MessageBox ( hWnd , _T ( " Simple Control Panel (not Shell-namespace based) \r Copyright 2004 GkWare e.K. \r http://www.gkware.com \r Released under the GPL " ) , _T ( " About the Control Panel " ) , MB_OK | MB_ICONINFORMATION ) ;
break ;
}
break ;
2004-10-29 12:27:58 +00:00
2004-06-18 20:43:44 +00:00
default :
return DefWindowProc ( hWnd , uMsg , wParam , lParam ) ;
}
2004-10-29 12:27:58 +00:00
2004-06-18 20:43:44 +00:00
return 0 ;
}
2004-10-29 12:27:58 +00:00
2004-06-18 20:43:44 +00:00
# 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
{
MSG msg ;
2004-06-19 00:11:44 +00:00
WNDCLASS wc ;
2004-10-29 12:27:58 +00:00
2004-06-18 20:43:44 +00:00
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 ( ) ;
2004-06-28 12:05:16 +00:00
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 ) ;
2004-10-29 12:27:58 +00:00
if ( ! hMainWnd )
{
2004-06-18 20:43:44 +00:00
CTL_DEBUG ( ( _T ( " Unable to create window \r \n " ) ) ) ;
return - 1 ;
}
ShowWindow ( hMainWnd , nCmdShow ) ;
2004-10-29 12:27:58 +00:00
while ( GetMessage ( & msg , 0 , 0 , 0 ) )
2004-06-18 20:43:44 +00:00
{
TranslateMessage ( & msg ) ;
DispatchMessage ( & msg ) ;
}
2004-10-29 12:27:58 +00:00
2004-06-18 20:43:44 +00:00
return 0 ;
}