3 * Copyright (C) 2004 ReactOS Team
4 * Copyright (C) 2004 GkWare e.K.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /* $Id: control.cpp,v 1.1 2004/06/18 20:43:44 kuehng Exp $
22 * PROJECT: ReactOS System Control Panel
23 * FILE: lib/cpl/system/control.cpp
24 * PURPOSE: ReactOS System Control Panel
25 * PROGRAMMER: Gero Kuehn (reactos.filter@gkware.com)
42 //#define CONTROL_DEBUG_ENABLE
44 #ifdef CONTROL_DEBUG_ENABLE
45 #define CTL_DEBUG(x) dbgprint x
53 void dbgprint(TCHAR
*format
,...)
58 _vstprintf(buf
,format
,va
);
59 OutputDebugString(buf
);
63 #define MYWNDCLASS _T("CTLPANELCLASS")
66 typedef LONG (CALLBACK
*CPLAPPLETFUNC
)(HWND hwndCPL
, UINT uMsg
, LPARAM lParam1
, LPARAM lParam2
);
68 typedef struct CPLLISTENTRY
{
69 TCHAR pszPath
[MAX_PATH
];
76 void PopulateCPLList(HWND hLisCtrl
)
80 TCHAR pszSearchPath
[MAX_PATH
];
81 GetSystemDirectory(pszSearchPath
,MAX_PATH
);
82 _tcscat(pszSearchPath
,_T("\\*.cpl"));
83 hFind
= FindFirstFile(pszSearchPath
,&fd
);
84 HIMAGELIST hImgListSmall
;
85 HIMAGELIST hImgListLarge
;
86 hImgListSmall
= ImageList_Create(16,16,ILC_COLOR
,256,1000);
87 hImgListLarge
= ImageList_Create(32,32,ILC_COLOR
,256,1000);
88 while(hFind
!= INVALID_HANDLE_VALUE
)
90 CTL_DEBUG((_T("Found %s\r\n"),fd
.cFileName
));
92 pEntry
= (CPLLISTENTRY
*)malloc(sizeof(CPLLISTENTRY
));
95 _tcscpy(pEntry
->pszPath
,pszSearchPath
);
96 *_tcsrchr(pEntry
->pszPath
,'\\')=0;
97 _tcscat(pEntry
->pszPath
,_T("\\"));
98 _tcscat(pEntry
->pszPath
,fd
.cFileName
);
100 pEntry
->hDLL
= LoadLibrary(pEntry
->pszPath
);
101 CTL_DEBUG((_T("Handle %08X\r\n"),pEntry
->hDLL
));
102 pEntry
->pFunc
= (CPLAPPLETFUNC
)GetProcAddress(pEntry
->hDLL
,_T("CPlApplet"));
103 CTL_DEBUG((_T("CPLFunc %08X\r\n"),pEntry
->pFunc
));
104 if(pEntry
->pFunc
&& pEntry
->pFunc(hLisCtrl
,CPL_INIT
,0,0))
106 for(int i
=0;i
<pEntry
->pFunc(hLisCtrl
,CPL_GETCOUNT
,0,0);i
++)
108 pEntry
->pFunc(hLisCtrl
,CPL_INQUIRE
,0,(LPARAM
)&pEntry
->CPLInfo
);
110 HICON hIcon
= LoadIcon(pEntry
->hDLL
,MAKEINTRESOURCE(pEntry
->CPLInfo
.idIcon
));
112 index
= ImageList_AddIcon(hImgListSmall
,hIcon
);
113 ImageList_AddIcon(hImgListLarge
,hIcon
);
116 TCHAR Name
[MAX_PATH
];
117 LoadString(pEntry
->hDLL
,pEntry
->CPLInfo
.idName
,Name
,MAX_PATH
);
123 memset(&lvi
,0x00,sizeof(lvi
));
124 lvi
.mask
=LVIF_TEXT
|LVIF_PARAM
|LVIF_STATE
|LVIF_IMAGE
;
128 lvi
.lParam
= (LPARAM
)pEntry
;
129 pEntry
->nIndex
= ListView_InsertItem(hLisCtrl
,&lvi
);
131 LoadString(pEntry
->hDLL
,pEntry
->CPLInfo
.idInfo
,Name
,MAX_PATH
);
132 ListView_SetItemText(hLisCtrl
,pEntry
->nIndex
,1,Name
);
134 ListView_SetImageList(hLisCtrl
,hImgListSmall
,LVSIL_SMALL
);
135 ListView_SetImageList(hLisCtrl
,hImgListLarge
,LVSIL_NORMAL
);
140 if(!FindNextFile(hFind
,&fd
))
141 hFind
= INVALID_HANDLE_VALUE
;
145 LRESULT CALLBACK
MyWindowProc(HWND hWnd
,UINT uMsg
,WPARAM wParam
,LPARAM lParam
)
151 GetClientRect(hWnd
,&rect
);
152 hListView
= CreateWindow(WC_LISTVIEW
,_T(""),LVS_REPORT
| LVS_ALIGNLEFT
| LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_VISIBLE
| WS_CHILD
|WS_BORDER
|WS_TABSTOP
,0,0,rect
.right
,rect
.bottom
,hWnd
,NULL
,hInst
,0);
153 CTL_DEBUG((_T("Listview Window %08X\r\n"),hListView
));
156 memset(&column
,0x00,sizeof(column
));
157 column
.mask
=LVCF_FMT
| LVCF_WIDTH
| LVCF_SUBITEM
|LVCF_TEXT
;
158 column
.fmt
=LVCFMT_LEFT
;
161 column
.pszText
= _T("Name");
162 ListView_InsertColumn(hListView
,0,&column
);
165 column
.pszText
= _T("Comment");
166 ListView_InsertColumn(hListView
,1,&column
);
167 PopulateCPLList(hListView
);
168 ListView_SetColumnWidth(hListView
,2,LVSCW_AUTOSIZE_USEHEADER
);
169 ListView_Update(hListView
,0);
175 GetClientRect(hWnd
,&rect
);
176 MoveWindow(hListView
,0,0,rect
.right
,rect
.bottom
,TRUE
);
180 phdr
= (NMHDR
*)lParam
;
185 nSelect
=SendMessage(hListView
,LVM_GETNEXTITEM
,(WPARAM
)-1,LVNI_FOCUSED
);
187 if(nSelect
==-1) // no items
189 MessageBox(hWnd
,_T("No Items in ListView"),_T("Error"),MB_OK
|MB_ICONINFORMATION
);
192 CTL_DEBUG((_T("Select %d\r\n"),nSelect
));
194 memset(&lvi
,0x00,sizeof(lvi
));
196 lvi
.mask
= LVIF_PARAM
;
197 ListView_GetItem(hListView
,&lvi
);
198 CPLLISTENTRY
*pEntry
;
199 pEntry
= (CPLLISTENTRY
*)lvi
.lParam
;
200 CTL_DEBUG((_T("Listview DblClk Entry %08X\r\n"),pEntry
));
202 CTL_DEBUG((_T("Listview DblClk Entry Func %08X\r\n"),pEntry
->pFunc
));
204 if(pEntry
&& pEntry
->pFunc
)
205 pEntry
->pFunc(hListView
,CPL_DBLCLK
,pEntry
->CPLInfo
.lData
,0);
209 switch(LOWORD(wParam
))
212 SetWindowLong(hListView
,GWL_STYLE
,LVS_ICON
| LVS_ALIGNLEFT
| LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_VISIBLE
| WS_CHILD
|WS_BORDER
|WS_TABSTOP
);
215 SetWindowLong(hListView
,GWL_STYLE
,LVS_SMALLICON
| LVS_ALIGNLEFT
| LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_VISIBLE
| WS_CHILD
|WS_BORDER
|WS_TABSTOP
);
218 SetWindowLong(hListView
,GWL_STYLE
,LVS_LIST
| LVS_ALIGNLEFT
| LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_VISIBLE
| WS_CHILD
|WS_BORDER
|WS_TABSTOP
);
221 SetWindowLong(hListView
,GWL_STYLE
,LVS_REPORT
| LVS_ALIGNLEFT
| LVS_AUTOARRANGE
| LVS_SINGLESEL
| WS_VISIBLE
| WS_CHILD
|WS_BORDER
|WS_TABSTOP
);
227 MessageBox(hWnd
,_T("Simple Control Panel (not Shell-namespace based)\rCopyright 2004 GkWare e.K.\rhttp://www.gkware.com\rReleased under the GPL"),_T("About the Control Panel"),MB_OK
| MB_ICONINFORMATION
);
232 return DefWindowProc(hWnd
,uMsg
,wParam
,lParam
);
238 int WINAPI
wWinMain(HINSTANCE hInstance
,HINSTANCE hPrevInstance
,WCHAR
*lpCmdLine
,int nCmdShow
)
240 int WINAPI
WinMain(HINSTANCE hInstance
,HINSTANCE hPrevInstance
,char *lpCmdLine
,int nCmdShow
)
245 CTL_DEBUG((_T("My Control Panel\r\n")));
247 memset(&wc
,0x00,sizeof(wc
));
248 wc
.hIcon
= LoadIcon(hInst
,MAKEINTRESOURCE(IDI_MAINICON
));
249 wc
.lpszClassName
= MYWNDCLASS
;
250 wc
.lpszMenuName
= _T("MAINMENU");
251 wc
.lpfnWndProc
= MyWindowProc
;
253 InitCommonControls();
254 hMainWnd
= CreateWindow(MYWNDCLASS
,_T("Control Panel"),WS_OVERLAPPEDWINDOW
,300,300,500,300,NULL
,LoadMenu(hInst
,MAKEINTRESOURCE(IDM_MAINMENU
)),hInst
,0);
256 CTL_DEBUG((_T("Unable to create window\r\n")));
259 ShowWindow(hMainWnd
,nCmdShow
);
260 while(GetMessage(&msg
,0,0,0))
262 TranslateMessage(&msg
);
263 DispatchMessage(&msg
);