home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1999 October
/
VPR9910A.BIN
/
OLS
/
unrar32005
/
unrar32005.lzh
/
src
/
dialog.cxx
< prev
next >
Wrap
C/C++ Source or Header
|
1998-04-03
|
6KB
|
226 lines
/*
* Copyright (c) 1998 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 "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) const
{
doevents ();
if (!hwnd)
return 0;
SendDlgItemMessage (hwnd, IDC_PROG, PBM_SETRANGE, 0, MAKELPARAM (0, nmax));
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, n, 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;
}