home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 2002 July
/
VPR0207A.ISO
/
OLS
/
UNRAR32007
/
unrar32007.lzh
/
src.lzh
/
src
/
dialog.cxx
< prev
next >
Wrap
C/C++ Source or Header
|
2001-01-11
|
8KB
|
294 lines
/*
* Copyright (c) 1998-2001 T. Kamei (kamei@jsdlab.co.jp)
*
* Permission to use, copy, modify, and distribute this software
* and its documentation for any purpose is hereby granted provided
* that the above copyright notice and this permission notice appear
* in all copies of the software and related documentation.
*
* NO WARRANTY
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY WARRANTIES;
* WITHOUT EVEN THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS
* FOR A PARTICULAR PURPOSE.
*/
#include <windows.h>
#include <stdio.h>
#include <commctrl.h>
#include <mbstring.h>
#include "comm-arc.h"
#include "util.h"
#include "dialog.h"
static void
center_window (HWND hwnd)
{
HWND owner = GetWindow (hwnd, GW_OWNER);
if (!owner)
owner = GetParent (hwnd);
if (!owner)
owner = GetDesktopWindow ();
RECT dr, or;
GetWindowRect (hwnd, &dr);
GetWindowRect (owner, &or);
LONG left = (or.left + (or.right - or.left) / 3
- (dr.right - dr.left) / 3);
LONG top = (or.top + (or.bottom - or.top) / 3
- (dr.bottom - dr.top) / 3);
RECT work;
SystemParametersInfo (SPI_GETWORKAREA, 0, &work, 0);
left = min (max (left, work.left), work.right - (dr.right - dr.left));
top = min (max (top, work.top), work.bottom - (dr.bottom - dr.top));
SetWindowPos (hwnd, 0, left, top, 0, 0,
SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
}
static void
set_size (HWND hwnd, int id, long size)
{
char buf[32];
sprintf (buf, "%d bytes", size);
SetDlgItemText (hwnd, id, buf);
}
static void
set_date (HWND hwnd, int id, DWORD date)
{
char buf[32];
sprintf (buf, "%d/%02d/%02d %02d:%02d:%02d",
(date >> 25) + 1980,
(date >> 21) & 15,
(date >> 16) & 31,
(date >> 11) & 31,
(date >> 5) & 63,
(date & 31) * 2);
SetDlgItemText (hwnd, id, buf);
}
static BOOL CALLBACK
replace_dlgproc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch (msg)
{
case WM_INITDIALOG:
{
center_window (hwnd);
replace_param *rp = (replace_param *)lparam;
SetDlgItemText (hwnd, IDC_OLDNAME, rp->old_name);
set_size (hwnd, IDC_OLDSIZE, rp->old_size);
set_date (hwnd, IDC_OLDDATE, rp->old_date);
SetDlgItemText (hwnd, IDC_NEWNAME, rp->new_name);
set_size (hwnd, IDC_NEWSIZE, rp->new_size);
set_date (hwnd, IDC_NEWDATE, rp->new_date);
SendMessage (GetDlgItem (hwnd, IDC_Q), STM_SETICON,
WPARAM (LoadIcon (0, IDI_QUESTION)), 0);
return 1;
}
case WM_COMMAND:
switch (LOWORD (wparam))
{
case IDYES:
case IDNO:
case IDC_ALL:
case IDCANCEL:
EndDialog (hwnd, LOWORD (wparam));
return 1;
}
break;
}
return 0;
}
int
replace_dialog (HWND hwnd, const replace_param &rp)
{
return DialogBoxParam (lstate.hinst, MAKEINTRESOURCE (IDD_REPLACE),
hwnd, replace_dlgproc, LPARAM (&rp));
}
void
doevents ()
{
MSG msg;
while (PeekMessage (&msg, 0, 0, 0, PM_REMOVE))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
static BOOL CALLBACK
progress_dlgproc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
progress_dlg *p;
if (msg == WM_INITDIALOG)
{
SetWindowLong (hwnd, DWL_USER, lparam);
p = (progress_dlg *)lparam;
p->hwnd = hwnd;
}
else
p = (progress_dlg *)GetWindowLong (hwnd, DWL_USER);
return p ? p->wndproc (msg, wparam, lparam) : 0;
}
BOOL
progress_dlg::wndproc (UINT msg, WPARAM wparam, LPARAM lparam)
{
switch (msg)
{
case WM_INITDIALOG:
center_window (hwnd);
return 1;
case WM_COMMAND:
if (LOWORD (wparam) == IDCANCEL)
{
DestroyWindow (hwnd);
hwnd = 0;
return 1;
}
break;
}
return 0;
}
int
progress_dlg::create (HWND parent)
{
if (!CreateDialogParam (lstate.hinst, MAKEINTRESOURCE (IDD_INPROG),
parent, progress_dlgproc, LPARAM (this)))
return 0;
ShowWindow (hwnd, SW_SHOW);
doevents ();
return 1;
}
int
progress_dlg::init (const char *path, int nmax)
{
doevents ();
if (!hwnd)
return 0;
max_bytes = nmax;
SendDlgItemMessage (hwnd, IDC_PROG, PBM_SETRANGE, 0, MAKELPARAM (0, PROGRESS_MAX));
SendDlgItemMessage (hwnd, IDC_PROG, PBM_SETPOS, 0, 0);
SetDlgItemText (hwnd, IDC_NAME, path);
return 1;
}
int
progress_dlg::update (int n) const
{
doevents ();
if (!hwnd)
return 0;
SendDlgItemMessage (hwnd, IDC_PROG, PBM_SETPOS,
max_bytes ? int (PROGRESS_MAX * double (n) / max_bytes) : PROGRESS_MAX,
0);
return 1;
}
static char passwd[128];
static BOOL CALLBACK
askpass_dlgproc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch (msg)
{
case WM_INITDIALOG:
center_window (hwnd);
return 1;
case WM_COMMAND:
switch (LOWORD (wparam))
{
case IDOK:
GetDlgItemText (hwnd, IDC_PASSWD, passwd, sizeof passwd - 1);
/* fall thru... */
case IDCANCEL:
EndDialog (hwnd, LOWORD (wparam));
return 1;
}
break;
}
return 0;
}
char *
askpass_dialog (HWND hwnd)
{
return DialogBox (lstate.hinst, MAKEINTRESOURCE (IDD_ASKPASSWD),
hwnd, askpass_dlgproc) == IDOK ? passwd : 0;
}
static char *vol_name;
static BOOL CALLBACK
changevol_dlgproc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch (msg)
{
case WM_INITDIALOG:
center_window (hwnd);
SetDlgItemText (hwnd, IDC_PATH, vol_name);
return 1;
case WM_COMMAND:
switch (LOWORD (wparam))
{
case IDC_REF:
{
char buf[MAX_PATH];
char filter[256];
LoadString (lstate.hinst, IDS_FILTER, filter, sizeof filter);
for (char *p = filter; (p = (char *)_mbschr ((u_char *)p, '|')); p++)
*p = 0;
GetDlgItemText (hwnd, IDC_PATH, buf, sizeof buf);
OPENFILENAME of;
memset (&of, 0, sizeof of);
of.lStructSize = sizeof of;
of.hwndOwner = hwnd;
of.lpstrFilter = filter;
of.nFilterIndex = 1;
of.lpstrFile = buf;
of.nMaxFile = sizeof buf;
of.Flags = (OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_NOCHANGEDIR
| OFN_PATHMUSTEXIST | OFN_EXPLORER);
if (GetOpenFileName (&of))
SetDlgItemText (hwnd, IDC_PATH, buf);
return 1;
}
case IDOK:
{
char buf[MAX_PATH];
GetDlgItemText (hwnd, IDC_PATH, buf, sizeof buf);
if (!*buf)
return 1;
strcpy (vol_name, buf);
}
/* fall thru... */
case IDCANCEL:
EndDialog (hwnd, LOWORD (wparam));
return 1;
}
break;
}
return 0;
}
int
change_vol_dialog (HWND hwnd, char *path)
{
vol_name = path;
return DialogBox (lstate.hinst, MAKEINTRESOURCE (IDD_CHANGEVOL),
hwnd, changevol_dlgproc) == IDOK;
}