Archive-Unzip-Burst
view release on metacpan or search on metacpan
unzip-6.0/wince/winmain.cpp view on Meta::CPAN
// This is our subclass of Windows CE's common save-as dialog. We intercept
// the messages we care about and forward everything else to the original
// window procedure for the dialog.
if (uMsg == WM_PRIVATE) { // wParam always equals MSG_INIT_DIALOG
RECT rc1, rc2;
// Get the window rectangle for the name edit control.
HWND hWnd = GetDlgItem(hDlg, IDC_SAVE_NAME_EDIT);
GetWindowRect(hWnd, &rc1);
POINT pt1 = { rc1.left, rc1.top };
ScreenToClient(hDlg, &pt1);
// Hide all the windows we don't want.
ShowWindow(hWnd, SW_HIDE);
ShowWindow(GetDlgItem(hDlg, IDC_SAVE_NAME_PROMPT), SW_HIDE);
ShowWindow(GetDlgItem(hDlg, IDC_SAVE_TYPE_PROMPT), SW_HIDE);
ShowWindow(GetDlgItem(hDlg, IDC_SAVE_TYPE_LIST), SW_HIDE);
// Get the window rectangle for the file list.
hWnd = GetDlgItem(hDlg, IDC_SAVE_FILE_LIST);
GetWindowRect(hWnd, &rc2);
POINT pt2 = { rc2.left, rc2.top };
ScreenToClient(hDlg, &pt2);
// Resize the file list to fill the dialog.
MoveWindow(hWnd, pt2.x, pt2.y, rc2.right - rc2.left, rc1.bottom - rc2.top, TRUE);
} else if ((uMsg == WM_COMMAND) && (LOWORD(wParam) == IDOK)) {
// Get our file list window.
HWND hWnd = GetDlgItem(hDlg, IDC_SAVE_FILE_LIST);
// Check to see if a directory is selected.
if (ListView_GetNextItem(hWnd, -1, LVNI_SELECTED) >= 0) {
// If a directory is highlighted, then we post ourself a "Ok". The "Ok"
// we are processing now will cause us to change into the highlighted
// directory, and our posted "Ok" will close the dialog in that directory.
PostMessage(hDlg, uMsg, wParam, lParam);
} else {
// If no directory is selected, then enter the imaginary filename "!"
// into the name edit control and let the "Ok" end this dialog. The
// result will be the correct path with a "\!" at the end.
SetDlgItemText(hDlg, IDC_SAVE_NAME_EDIT, TEXT("!"));
}
}
// Pass all messages to the base control's window proc.
return CallWindowProc(g_wpSaveAsDlg, hDlg, uMsg, wParam, lParam);
}
#endif // _WIN32_WCE
//******************************************************************************
#ifdef _WIN32_WCE
void SubclassSaveAsDlg() {
// Get our current thread ID so we can compare it to other thread IDs.
DWORD dwThreadId = GetCurrentThreadId();
// Get the the top window in the z-order that is a child of the desktop.
// Dialogs are always children of the desktop on CE. This first window
// should be the dialog we are looking for, but we will walk the window list
// just in case.
HWND hWnd = GetWindow(g_hWndMain, GW_HWNDFIRST);
// Walk the window list.
while (hWnd) {
// Check to see if this window was created by us and has controls from a
// common "save as" dialog.
if ((GetWindowThreadProcessId(hWnd, NULL) == dwThreadId) &&
GetDlgItem(hWnd, IDC_SAVE_FILE_LIST) &&
GetDlgItem(hWnd, IDC_SAVE_NAME_EDIT))
{
// We found our dialog. Subclass it.
g_wpSaveAsDlg = (WNDPROC)GetWindowLong(hWnd, GWL_WNDPROC);
SetWindowLong(hWnd, GWL_WNDPROC, (LONG)DlgProcBrowser);
// Send our new dialog a message so it can do its initialization.
SendMessage(hWnd, WM_PRIVATE, MSG_INIT_DIALOG, 0);
}
// Get the next window in our window list.
hWnd = GetWindow(hWnd, GW_HWNDNEXT);
}
}
#endif // _WIN32_WCE
//******************************************************************************
//***** Extraction/Test/View Progress Dialog Functions
//******************************************************************************
BOOL CALLBACK DlgProcExtractProgress(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
static EXTRACT_INFO *pei;
static BOOL fComplete;
static HWND hWndButton;
TCHAR szBuffer[32];
switch (uMsg) {
case WM_INITDIALOG:
// Globally store our handle so our worker thread can post to us.
g_hDlgProgress = hDlg;
// Get a pointer to our extract information structure.
pei = (EXTRACT_INFO*)lParam;
// Clear our complete flag. It will be set to TRUE when done.
fComplete = FALSE;
// Get and store our edit control.
g_hWndEdit = GetDlgItem(hDlg, IDC_LOG);
// Disable our edit box from being edited.
DisableEditing(g_hWndEdit);
// Store a static handle for our Abort/Close button.
hWndButton = GetDlgItem(hDlg, IDCANCEL);
#ifdef _WIN32_WCE
// Set our No-Drag style
SetWindowLong(hDlg, GWL_EXSTYLE, WS_EX_NODRAG |GetWindowLong(hDlg, GWL_EXSTYLE));
RECT rc1, rc2, rcEdit;
// Get our current client size.
GetClientRect(hDlg, &rc1);
// Get the window rectangle for the edit control in client coordinates.
GetWindowRect(g_hWndEdit, &rcEdit);
ScreenToClient(hDlg, ((POINT*)&rcEdit));
ScreenToClient(hDlg, ((POINT*)&rcEdit) + 1);
// Resize our dialog to be full screen (same size as parent).
GetWindowRect(g_hWndMain, &rc2);
MoveWindow(hDlg, rc2.left, rc2.top, rc2.right - rc2.left,
rc2.bottom - rc2.top + 1, FALSE);
// Get our new client size.
GetClientRect(hDlg, &rc2);
// Resize our edit box to fill the client.
MoveWindow(g_hWndEdit, rcEdit.left, rcEdit.top,
(rcEdit.right - rcEdit.left) + (rc2.right - rc1.right),
(rcEdit.bottom - rcEdit.top) + (rc2.bottom - rc1.bottom),
FALSE);
#else
// On NT, we just center our dialog over our parent.
CenterWindow(hDlg);
#endif
// Store some globals until the extract/test finishes.
pei->hWndEditFile = GetDlgItem(hDlg, IDC_FILE);
pei->hWndProgFile = GetDlgItem(hDlg, IDC_FILE_PROGRESS);
pei->hWndProgTotal = GetDlgItem(hDlg, IDC_TOTAL_PROGRESS);
pei->hWndPercentage = GetDlgItem(hDlg, IDC_PERCENTAGE);
pei->hWndFilesProcessed = GetDlgItem(hDlg, IDC_FILES_PROCESSED);
pei->hWndBytesProcessed = GetDlgItem(hDlg, IDC_BYTES_PROCESSED);
if (pei->fExtract) {
// Set our main window's caption.
SetCaptionText(TEXT("Extracting"));
} else {
// Set our main window's caption.
SetCaptionText(TEXT("Testing"));
// Hide the current file progress for test since it never moves.
ShowWindow(pei->hWndProgFile, SW_HIDE);
}
// Set the ranges on our progress bars.
SendMessage(pei->hWndProgFile, PBM_SETRANGE, 0,
MAKELPARAM(0, PROGRESS_MAX));
SendMessage(pei->hWndProgTotal, PBM_SETRANGE, 0,
MAKELPARAM(0, PROGRESS_MAX));
// Set our file and byte totals.
SetDlgItemText(hDlg, IDC_FILES_TOTAL,
FormatValue(szBuffer, pei->dwFileCount));
SetDlgItemText(hDlg, IDC_BYTES_TOTAL,
FormatValue(szBuffer, pei->uzByteCount));
// Launch our Extract/Test thread and wait for WM_PRIVATE
DoExtractOrTestFiles(g_szZipFile, pei);
return TRUE;
case WM_PRIVATE: // Sent with wParam equal to MSG_OPERATION_COMPLETE when
// test/extract is complete.
// Check to see if the operation was a success
if ((pei->result == PK_OK) || (pei->result == PK_WARN)) {
// Set all our fields to their "100%" settings.
SendMessage(pei->hWndProgFile, PBM_SETPOS, PROGRESS_MAX, 0);
SendMessage(pei->hWndProgTotal, PBM_SETPOS, PROGRESS_MAX, 0);
SetWindowText(pei->hWndPercentage, TEXT("100%"));
SetDlgItemText(hDlg, IDC_FILES_PROCESSED,
FormatValue(szBuffer, pei->dwFileCount));
SetDlgItemText(hDlg, IDC_BYTES_PROCESSED,
FormatValue(szBuffer, pei->uzByteCount));
}
// Update our status text.
SetWindowText(pei->hWndEditFile,
(pei->result == PK_OK) ? TEXT("Completed. There were no warnings or errors.") :
(pei->result == PK_WARN) ? TEXT("Completed. There was one or more warnings.") :
(pei->result == PK_ABORTED) ? TEXT("Aborted. There may be warnings or errors.") :
TEXT("Completed. There was one or more errors."));
// Clear our global edit handle.
g_hWndEdit = NULL;
// Update our caption to show that we are done extracting/testing.
SetCaptionText(NULL);
// Change our abort button to now read "Close".
SetWindowText(hWndButton, TEXT("&Close"));
EnableWindow(hWndButton, TRUE);
// Display an error dialog if an error occurred.
if ((pei->result != PK_OK) && (pei->result != PK_WARN)) {
MessageBox(hDlg, GetZipErrorString(pei->result),
g_szAppName, MB_ICONERROR | MB_OK);
}
// We are done. Allow the user to close the dialog.
fComplete = TRUE;
return FALSE;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDCANCEL:
// If abort is pressed, then set a flag that our worker thread
// periodically checks to decide if it needs to bail out.
if (!fComplete && !pei->fAbort) {
pei->fAbort = TRUE;
SetWindowText(hWndButton, TEXT("Aborting..."));
EnableWindow(hWndButton, FALSE);
return FALSE;
}
// fall through to IDOK
case IDOK:
// Don't allow dialog to close until extract/test is complete.
if (fComplete) {
g_hDlgProgress = NULL;
EndDialog(hDlg, LOWORD(wParam));
}
return FALSE;
}
return FALSE;
}
return FALSE;
}
//******************************************************************************
BOOL CALLBACK DlgProcViewProgress(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
static EXTRACT_INFO *pei;
switch (uMsg) {
case WM_INITDIALOG:
// Globally store our handle so our worker thread can post to us.
g_hDlgProgress = hDlg;
// Get a pointer to our extract information structure.
pei = (EXTRACT_INFO*)lParam;
// Center our dialog over our parent.
CenterWindow(hDlg);
// Store some globals until the extract finishes.
pei->hWndProgFile = GetDlgItem(hDlg, IDC_FILE_PROGRESS);
// Set the ranges on our progress bar.
SendDlgItemMessage(hDlg, IDC_FILE_PROGRESS, PBM_SETRANGE, 0,
MAKELPARAM(0, PROGRESS_MAX));
// Launch our Extract thread and wait for WM_PRIVATE message.
DoExtractOrTestFiles(g_szZipFile, pei);
return TRUE;
case WM_PRIVATE: // Sent with wParam equal to MSG_OPERATION_COMPLETE when
// test/extract is complete.
// We are done. Close our dialog. Any errors will be reported by
// OnActionView().
g_hDlgProgress = NULL;
EndDialog(hDlg, LOWORD(wParam));
return FALSE;
case WM_COMMAND:
// If abort is pressed, then set a flag that our worker thread
// periodically checks to decide if it needs to bail out.
if ((LOWORD(wParam) == IDCANCEL) && !pei->fAbort) {
pei->fAbort = TRUE;
SetWindowText(GetDlgItem(hDlg, IDCANCEL), TEXT("Aborting..."));
EnableWindow(GetDlgItem(hDlg, IDCANCEL), FALSE);
return FALSE;
}
}
return FALSE;
}
//******************************************************************************
void UpdateProgress(EXTRACT_INFO *pei, BOOL fFull) {
DWORD dwFile, dwTotal, dwPercentage;
TCHAR szBuffer[_MAX_PATH + 32];
// Compute our file progress bar position.
if (pei->uzBytesTotalThisFile) {
dwFile = (DWORD)(((DWORDLONG)PROGRESS_MAX *
(DWORDLONG)pei->uzBytesWrittenThisFile) /
(DWORDLONG)pei->uzBytesTotalThisFile);
} else {
dwFile = PROGRESS_MAX;
}
// Set our file progress indicators.
SendMessage(pei->hWndProgFile, PBM_SETPOS, dwFile, 0);
// If we are only updating our View Progress dialog, then we are done.
if (!pei->hWndProgTotal) {
return;
}
// Compute our total progress bar position.
dwTotal = (DWORD)(((DWORDLONG)PROGRESS_MAX *
(DWORDLONG)(pei->uzBytesWrittenPreviousFiles +
pei->uzBytesWrittenThisFile +
pei->dwFile)) /
(DWORDLONG)(pei->uzByteCount +
pei->dwFileCount));
dwPercentage = dwTotal / (PROGRESS_MAX / 100);
// Set our total progress indicators.
SendMessage(pei->hWndProgTotal, PBM_SETPOS, dwTotal, 0);
// Set our total percentage text.
_stprintf(szBuffer, TEXT("%u%%"), dwPercentage);
SetWindowText(pei->hWndPercentage, szBuffer);
// Set our current file and byte process counts.
FormatValue(szBuffer, pei->dwFile - 1);
SetWindowText(pei->hWndFilesProcessed, szBuffer);
FormatValue(szBuffer, pei->uzBytesWrittenPreviousFiles +
pei->uzBytesWrittenThisFile);
SetWindowText(pei->hWndBytesProcessed, szBuffer);
if (fFull) {
( run in 1.657 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )