home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2002 February
/
Chip_2002-02_cd1.bin
/
sharewar
/
apaths
/
APSOURCE.ZIP
/
RunTab.c
< prev
next >
Wrap
C/C++ Source or Header
|
2001-03-26
|
11KB
|
416 lines
/* RunTab - March 26th, 2001
**
** Copyright (c) 1997-2001 by Gregory Braun. All rights reserved.
**
** This routine displays a list of the Run keys found in the
** MS Windows 95/NT System Registry.
**
** Private (static) routines are included to initialize the
** property page sheet when first invoked as well as handle
** [Create], [Modify] and [Remove] user requests.
**
** Called: dlg = handle to the dialog window.
** msg = the MS Windows WM_xxxxxx message to be handled.
** wp = the WPARAM specific to the message being sent
** lp = the LPARAM specific to the message being sent
**
** Returns: TRUE upon success, or FALSE if the user pressed [Cancel],
** or an internal error exists.
*/
#include "AppPaths.h"
#define KILL_QUERY "Title:\t%s\r" \
"Cmd:\t%s\r\r" \
"There is no UNDO available for the Remove command.\r" \
"Are you sure you want to delete this registery entry?\r"
#define CREATE_FAILURE "The selected MS Windows System Registry\r" \
"Run key could not be created."
#define KILL_FAILURE "The selected MS Windows System Registry\r" \
"Run key could not be removed."
#define MODIFY_FAILURE "The selected MS Windows System Registry\r" \
"Run key could not be modified."
#define MEMORY_ERROR "Memory Error\r\r" \
"Windows can not allocate a temporary memory\r" \
"buffer for the requested sorting operations."
static int sort = COLUMN_1;
static BOOL user = FALSE;
static BOOL initiate (HWND dlg);
static BOOL selection (HWND dlg,WPARAM wp,LPARAM lp);
static BOOL verify (HWND dlg);
static BOOL create (HWND dlg);
static BOOL modify (HWND dlg);
static BOOL kill (HWND dlg);
static BOOL reflect (HWND dlg,BOOL hit);
static BOOL refresh (HWND dlg,BOOL user);
static BOOL order (HWND list,int column);
static int by_name (const void * k1,const void * k2);
static int by_path (const void * k1,const void * k2);
static int cmp_name (LPCSTR n1,LPCSTR n2);
static int cmp_path (LPCSTR p1,LPCSTR p2);
extern UINT CALLBACK RunTab (HWND dlg,UINT msg,WPARAM wp,LPARAM lp)
{
auto int item = LOWORD (wp);
auto LPNMHDR hdr = (LPNMHDR) lp;
auto NM_LISTVIEW * cmd = (NM_LISTVIEW *) lp;
auto HWND list;
auto BOOL good;
switch (msg) {
case WM_COMMAND :
switch (item) {
case RUN_MACHINE_BOX :
refresh (dlg,user = FALSE);
break;
case RUN_USER_BOX :
refresh (dlg,user = TRUE);
break;
case RUN_CREATE_BTN :
create (dlg);
break;
case RUN_MODIFY_BTN :
modify (dlg);
break;
case RUN_REMOVE_BTN :
kill (dlg);
break;
default :
break;
}
break;
case WM_HELP :
HelpTip (dlg,((LPHELPINFO) lp)->iCtrlId);
break;
case WM_NOTIFY :
switch (((LPNMHDR) lp)->code) {
case LVN_COLUMNCLICK :
list = hdr->hwndFrom;
sort = cmd->iSubItem;
order (list,sort);
break;
case PSN_SETACTIVE :
initiate (dlg);
break;
case PSN_KILLACTIVE :
good = verify (dlg);
SetWindowLong (dlg,DWL_MSGRESULT,!good);
return ((good) ? FALSE : TRUE);
break;
case PSN_APPLY :
good = verify (dlg);
SetWindowLong (dlg,DWL_MSGRESULT,good);
return ((good) ? PSNRET_NOERROR : PSNRET_INVALID_NOCHANGEPAGE);
break;
case PSN_HELP :
HelpTopic (dlg,RUN_TAB);
break;
default :
selection (dlg,wp,lp);
break;
}
break;
break;
}
return (FALSE);
}
static BOOL initiate (HWND dlg)
{
static BOOL created = FALSE;
auto LPSTR label[] = { "Title", "Command" };
auto int width[] = { 115,300 };
auto HWND ctl = GetDlgItem (dlg,RUN_MEMBER_LST);
auto LV_COLUMN col = { NIL };
auto int inx;
if (!created) {
col.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
col.fmt = LVCFMT_LEFT;
for (inx = NIL; inx < RUN_COLS_MAX; inx++) {
col.iSubItem = inx;
col.pszText = label[inx];
col.cx = width[inx];
ListView_InsertColumn (ctl,inx,&col);
}
created = TRUE;
}
CheckDlgButton (dlg,RUN_MACHINE_BOX,!user);
CheckDlgButton (dlg,RUN_USER_BOX,user);
GetRKeys (ctl,user);
order (ctl,sort);
reflect (dlg,TRUE);
return (TRUE);
}
static BOOL selection (HWND dlg,WPARAM wp,LPARAM lp)
{
auto int item = (int) wp;
auto LPNMHDR hdr = (LPNMHDR) lp;
auto UINT code = hdr->code;
auto HWND list = hdr->hwndFrom;
auto int hit;
if (item != RUN_MEMBER_LST)
return (FALSE);
switch (code) {
case NM_CLICK :
case NM_DBLCLK :
if ((hit = LV_RowHit (list)) >= NIL) {
reflect (dlg,TRUE);
if (code == NM_DBLCLK)
modify (dlg);
}
else reflect (dlg,FALSE);
break;
default :
break;
}
return (TRUE);
}
static BOOL verify (HWND dlg)
{
UNUSED_ARG (dlg);
return (TRUE);
}
static BOOL create (HWND dlg)
{
auto RUN run = { NIL };
auto HWND list = GetDlgItem (dlg,RUN_MEMBER_LST);
if (!EditRun (dlg,&run))
return (FALSE);
if (!MakeRKey (&run,user))
return (Error (dlg,NULL,CREATE_FAILURE));
RL_AddItem (list,&run);
return (TRUE);
}
static BOOL modify (HWND dlg)
{
auto RUN was = { NIL };
auto RUN run = { NIL };
auto HWND list = GetDlgItem (dlg,RUN_MEMBER_LST);
auto int index = LV_GetCurSel (list);
ListView_EnsureVisible (list,index,FALSE);
RL_GetItem (list,index,&run);
was = run;
if (!EditRun (dlg,&run))
return (FALSE);
if (!KillRKey (&was,user))
return (Error (dlg,NULL,KILL_FAILURE));
if (!MakeRKey (&run,user))
return (Error (dlg,NULL,MODIFY_FAILURE));
RL_PutItem (list,index,&run);
return (TRUE);
}
static BOOL kill (HWND dlg)
{
auto RUN run = { NIL };
auto HWND list = GetDlgItem (dlg,RUN_MEMBER_LST);
auto int index = LV_GetCurSel (list);
auto char msg[MSTRING];
ListView_EnsureVisible (list,index,FALSE);
RL_GetItem (list,index,&run);
wsprintf (msg,KILL_QUERY,run.name,run.path);
if (!Query (dlg,NULL,msg))
return (FALSE);
if (!KillRKey (&run,user))
return (Error (dlg,NULL,KILL_FAILURE));
ListView_DeleteItem (list,index);
reflect (dlg,FALSE);
return (TRUE);
}
static BOOL reflect (HWND dlg,BOOL hit)
{
Button_Enable (GetDlgItem (dlg,RUN_CREATE_BTN),TRUE);
Button_Enable (GetDlgItem (dlg,RUN_MODIFY_BTN),hit);
Button_Enable (GetDlgItem (dlg,RUN_REMOVE_BTN),hit);
return (TRUE);
}
static BOOL refresh (HWND dlg,BOOL user)
{
auto HWND ctl = GetDlgItem (dlg,RUN_MEMBER_LST);
CheckDlgButton (dlg,RUN_MACHINE_BOX,!user);
CheckDlgButton (dlg,RUN_USER_BOX,user);
GetRKeys (ctl,user);
order (ctl,sort);
reflect (dlg,TRUE);
return (TRUE);
}
static BOOL order (HWND list,int column)
{
auto int count = ListView_GetItemCount (list);
auto LPRUN run = (count) ? GlobalAllocPtr (GHND,count * sizeof (RUN)) : NULL;
auto HCURSOR old;
auto int inx;
if (!count) return (FALSE);
if (!run) return (Error (list,NULL,MEMORY_ERROR));
old = SetCursor (LoadCursor (NULL,IDC_WAIT));
SetWindowRedraw (list,FALSE);
for (inx = NIL; inx < count; inx++)
RL_GetItem (list,inx,&run[inx]);
switch (column) {
case COLUMN_2 :
qsort (run,count,sizeof (RUN),by_path);
break;
default :
qsort (run,count,sizeof (RUN),by_name);
break;
}
for (inx = NIL; inx < count; inx++)
RL_PutItem (list,inx,&run[inx]);
SetWindowRedraw (list,TRUE);
LV_SetCurSel (list,NIL);
GlobalFreePtr (run);
SetCursor (old);
return (TRUE);
}
static int by_name (const void * k1,const void * k2)
{
auto LPRUN p1 = (LPRUN) k1;
auto LPRUN p2 = (LPRUN) k2;
auto int result = cmp_name (p1->name,p2->name);
if (result) return (result);
return (cmp_path (p1->path,p2->path));
}
static int by_path (const void * k1,const void * k2)
{
auto LPRUN p1 = (LPRUN) k1;
auto LPRUN p2 = (LPRUN) k2;
auto int result = cmp_path (p1->path,p2->path);
if (result) return (result);
return (cmp_name (p1->name,p2->name));
}
static int cmp_name (LPCSTR n1,LPCSTR n2)
{
if (!*n1 && !*n2) return (NIL);
if (!*n1) return (1);
if (!*n2) return (-1);
return (lstrcmpi (n1,n2));
}
static int cmp_path (LPCSTR p1,LPCSTR p2)
{
if (!*p1 && !*p2) return (NIL);
if (!*p1) return (1);
if (!*p2) return (-1);
return (lstrcmpi (p1,p2));
}
/* end of RunTab.c - written by Gregory Braun */