Archive-Unzip-Burst
view release on metacpan or search on metacpan
unzip-6.0/wince/winmain.cpp view on Meta::CPAN
//***** WinMain - Our one and only entry point
//******************************************************************************
// Entrypoint is a tiny bit different on Windows CE - UNICODE command line.
#ifdef _WIN32_WCE
extern "C" int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow)
#else
extern "C" int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
#endif
{
// Wrap the whole ball of wax in a big exception handler.
__try {
// Store global instance handle.
g_hInst = hInstance;
// Create our banner font. We need to do this before creating our window.
// This font handle will be deleted in ShutdownApplication().
LOGFONT lf;
ZeroMemory(&lf, sizeof(lf));
lf.lfHeight = 16;
lf.lfWeight = FW_BOLD;
lf.lfCharSet = ANSI_CHARSET;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = DEFAULT_QUALITY;
lf.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
_tcscpy(lf.lfFaceName, TEXT("MS Sans Serif"));
g_hFontBanner = CreateFontIndirect(&lf);
// Define the window class for our application's main window.
WNDCLASS wc;
ZeroMemory(&wc, sizeof(wc));
wc.lpszClassName = g_szClass;
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
TCHAR *szZipPath = NULL;
#ifdef _WIN32_WCE
// Get our main window's small icon. On Windows CE, we need to send ourself
// a WM_SETICON in order for our task bar to update itself.
g_hIconMain = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_UNZIP),
IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
wc.hIcon = g_hIconMain;
// On Windows CE, we only need the WS_VISIBLE flag.
DWORD dwStyle = WS_VISIBLE;
// Get and store command line file (if any).
if (lpCmdLine && *lpCmdLine) {
szZipPath = lpCmdLine;
}
#else
// On NT we add a cursor, icon, and menu to our application's window class.
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_UNZIP));
wc.lpszMenuName = MAKEINTRESOURCE(IDR_UNZIP);
// On Windows NT, we use the standard overlapped window style.
DWORD dwStyle = WS_OVERLAPPEDWINDOW;
TCHAR szBuffer[_MAX_PATH];
// Get and store command line file (if any).
if (lpCmdLine && *lpCmdLine) {
MBSTOTSTR(szBuffer, lpCmdLine, countof(szBuffer));
szZipPath = szBuffer;
}
#endif
// Register our window class with the OS.
if (!RegisterClass(&wc)) {
DebugOut(TEXT("RegisterClass() failed [%u]"), GetLastError());
}
// Create our main window using our registered window class.
g_hWndMain = CreateWindow(wc.lpszClassName, g_szAppName, dwStyle,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
// Quit now if we failed to create our main window.
if (!g_hWndMain) {
DebugOut(TEXT("CreateWindow() failed [%u]"), GetLastError());
ShutdownApplication();
return 0;
}
// Make sure our window is visible. Really only needed for NT.
ShowWindow(g_hWndMain, nCmdShow);
// Load our keyboard accelerator shortcuts.
MSG msg;
HACCEL hAccel = LoadAccelerators(g_hInst, MAKEINTRESOURCE(IDR_UNZIP));
DWORD dwPaintFlags = 0;
// The message pump. Loop until we get a WM_QUIT message.
while (GetMessage(&msg, NULL, 0, 0)) {
// Check to see if this is an accelerator and handle it if neccessary.
if (!TranslateAccelerator(g_hWndMain, hAccel, &msg)) {
// If a normal message, then dispatch it to the correct window.
TranslateMessage(&msg);
DispatchMessage(&msg);
// Wait until our application is up and visible before trying to
// initialize some of our structures and load any command line file.
if ((msg.message == WM_PAINT) && (dwPaintFlags != 0x11)) {
if (msg.hwnd == g_hWndWaitFor) {
dwPaintFlags |= 0x01;
} else if (msg.hwnd == g_hWndList) {
dwPaintFlags |= 0x10;
}
if (dwPaintFlags == 0x11) {
InitializeApplication((szZipPath && *szZipPath) ?
szZipPath : NULL);
}
}
}
}
// Clean up code.
ShutdownApplication();
// Nice clean finish - were out of here.
return msg.wParam;
} __except(EXCEPTION_EXECUTE_HANDLER) {
// Something very bad happened. Try our best to appear somewhat graceful.
MessageBox(NULL,
TEXT("An internal error occurred. Possible causes are that you are ")
TEXT("out of memory, a ZIP file (if one is loaded) contains an ")
TEXT("unexpected error, or there is a bug in our program (that's why ")
TEXT("it's free). Pocket UnZip cannot continue. It will exit now, ")
TEXT("but you may restart it and try again.\n\n")
TEXT("If the problem persists, please write to stevemil@pobox.com with ")
TEXT("any information that might help track down the problem."),
g_szAppName, MB_ICONERROR | MB_OK);
}
return 1;
}
//******************************************************************************
//***** Startup and Shutdown Functions
//******************************************************************************
void InitializeApplication(LPCTSTR szZipFile) {
// This function is called after our class is registered and all our windows
// are created and visible to the user.
// Show hour glass cursor.
HCURSOR hCur = SetCursor(LoadCursor(NULL, IDC_WAIT));
// Register UnZip in the registry to handle ".ZIP" files.
RegisterUnzip();
// Enumerate the system file assoications and build an image list.
BuildImageList();
// Load our initial MRU into our menu.
InitializeMRU();
// Restore/remove our cursor.
SetCursor(hCur);
// Clear our initialization window handle.
g_hWndWaitFor = NULL;
// Load our command line file if one was specified. Otherwise, just update
// our banner to show that no file is loaded.
if (szZipFile) {
ReadZipFileList(szZipFile);
} else {
DrawBanner(NULL);
}
// Enable some controls.
EnableAllMenuItems(IDM_FILE_OPEN, TRUE);
EnableAllMenuItems(IDM_FILE_CLOSE, TRUE);
EnableAllMenuItems(IDM_VIEW_EXPANDED_VIEW, TRUE);
EnableAllMenuItems(IDM_HELP_ABOUT, TRUE);
// Set our temporary directory.
#ifdef _WIN32_WCE
g_szTempDir = TEXT("\\Temporary Pocket UnZip Files");
#else
g_szTempDir = TEXT("C:\\Temporary Pocket UnZip Files");
// Set the drive to be the same drive as the OS installation is on.
if (GetWindowsDirectory(g_szTempDirPath, countof(g_szTempDirPath))) {
lstrcpy(g_szTempDirPath + 3, TEXT("Temporary Pocket UnZip Files"));
g_szTempDir = g_szTempDirPath;
}
#endif
}
//******************************************************************************
void ShutdownApplication() {
// Free our banner font.
if (g_hFontBanner) {
DeleteObject(g_hFontBanner);
g_hFontBanner = NULL;
}
// Delete our FILE_TYPE_NODE linked list.
for (FILE_TYPE_NODE *pft = g_pftHead; pft; ) {
FILE_TYPE_NODE *pftNext = pft->pNext;
delete[] (BYTE*)pft;
pft = pftNext;
}
g_pftHead = NULL;
// If there are no other instances of our application open, then delete our
// temporary directory and all the files in it. Any files opened for viewing
// should be locked and will fail to delete. This is to be expected.
if (g_szTempDir && (FindWindow(g_szClass, NULL) == NULL)) {
TCHAR szPath[_MAX_PATH];
_tcscpy(szPath, g_szTempDir);
DeleteDirectory(szPath);
}
}
unzip-6.0/wince/winmain.cpp view on Meta::CPAN
fFound = TRUE;
}
}
// Only update menu if we found a file to remove.
if (fFound) {
// Clear out our menu's MRU list.
for (i = MRU_START_ID; i < (MRU_START_ID + MRU_MAX_FILE); i++) {
DeleteMenu(hMenu, i, MF_BYCOMMAND);
}
// Write the rest of our MRU list back to the menu.
for (i = 0, j = 0; i < MRU_MAX_FILE; i++) {
// If this MRU still exists, then add it.
if (szMRU[i][3]) {
// Build the accelerator prefix for this menu item.
szMRU[i][0] = TEXT('&');
szMRU[i][1] = TEXT('1') + j;
szMRU[i][2] = TEXT(' ');
// Add the item to our menu.
InsertMenu(hMenu, 4 + j, MF_BYPOSITION | MF_STRING, MRU_START_ID + j,
szMRU[i]);
// Increment our actual MRU count.
j++;
}
}
}
}
//******************************************************************************
void ActivateMRU(UINT uIDItem) {
TCHAR szFile[_MAX_PATH + 4];
// Get our menu handle.
#ifdef _WIN32_WCE
HMENU hMenu = GetSubMenu(CommandBar_GetMenu(g_hWndCmdBar, 0), 0);
#else
HMENU hMenu = GetSubMenu(GetMenu(g_hWndMain), 0);
#endif
// Query our menu for the selected MRU.
if (GetMenuString(hMenu, uIDItem, szFile, countof(szFile), MF_BYCOMMAND)) {
// Move past 3 character accelerator prefix and open the file.
ReadZipFileList(&szFile[3]);
}
}
//******************************************************************************
//***** Open Zip File Functions
//******************************************************************************
void ReadZipFileList(LPCTSTR wszPath) {
// Show wait cursor.
HCURSOR hCur = SetCursor(LoadCursor(NULL, IDC_WAIT));
TSTRTOMBS(g_szZipFile, wszPath, countof(g_szZipFile));
// Update our banner to show that we are loading.
g_fLoading = TRUE;
DrawBanner(NULL);
// Update our caption to show that we are loading.
SetCaptionText(TEXT("Loading"));
// Clear our list view.
ListView_DeleteAllItems(g_hWndList);
// Ghost all our Unzip related menu items.
EnableAllMenuItems(IDM_FILE_PROPERTIES, FALSE);
EnableAllMenuItems(IDM_ACTION_EXTRACT, FALSE);
EnableAllMenuItems(IDM_ACTION_EXTRACT_ALL, FALSE);
EnableAllMenuItems(IDM_ACTION_TEST, FALSE);
EnableAllMenuItems(IDM_ACTION_TEST_ALL, FALSE);
EnableAllMenuItems(IDM_ACTION_VIEW, FALSE);
EnableAllMenuItems(IDM_ACTION_SELECT_ALL, FALSE);
EnableAllMenuItems(IDM_VIEW_COMMENT, FALSE);
// Let Info-ZIP and our callbacks do the work.
SendMessage(g_hWndList, WM_SETREDRAW, FALSE, 0);
int result = DoListFiles(g_szZipFile);
SendMessage(g_hWndList, WM_SETREDRAW, TRUE, 0);
// Restore/remove cursor.
SetCursor(hCur);
// Update our column widths
ResizeColumns();
if ((result == PK_OK) || (result == PK_WARN)) {
// Sort the items by name.
Sort(0, TRUE);
// Update this file to our MRU list and menu.
AddFileToMRU(g_szZipFile);
// Enabled the comment button if the zip file has a comment.
if (lpUserFunctions->cchComment) {
EnableAllMenuItems(IDM_VIEW_COMMENT, TRUE);
}
// Update other items that are related to having a Zip file loaded.
EnableAllMenuItems(IDM_ACTION_EXTRACT_ALL, TRUE);
EnableAllMenuItems(IDM_ACTION_TEST_ALL, TRUE);
EnableAllMenuItems(IDM_ACTION_SELECT_ALL, TRUE);
} else {
// Make sure we didn't partially load and added a few files.
ListView_DeleteAllItems(g_hWndList);
// If the file itself is bad or missing, then remove it from our MRU.
if ((result == PK_ERR) || (result == PK_BADERR) || (result == PK_NOZIP) ||
(result == PK_FIND) || (result == PK_EOF))
{
RemoveFileFromMRU(wszPath);
}
// Display an error.
TCHAR szError[_MAX_PATH + 128];
_stprintf(szError, TEXT("Failure loading \"%s\".\n\n"), wszPath);
_tcscat(szError, GetZipErrorString(result));
MessageBox(g_hWndMain, szError, g_szAppName, MB_OK | MB_ICONERROR);
// Clear our file status.
*g_szZipFile = '\0';
}
// Update our caption to show that we are done loading.
SetCaptionText(NULL);
// Update our banner to show that we are done loading.
g_fLoading = FALSE;
DrawBanner(NULL);
}
//******************************************************************************
//***** Zip File Properties Dialog Functions
//******************************************************************************
BOOL CALLBACK DlgProcProperties(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
unzip-6.0/wince/winmain.cpp view on Meta::CPAN
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hDlg;
ofn.hInstance = g_hInst;
ofn.lpstrFilter = TEXT("Programs (*.exe)\0*.exe\0All Files (*.*)\0*.*\0");
ofn.nFilterIndex = 1;
ofn.lpstrFile = szApp;
ofn.nMaxFile = _MAX_PATH;
ofn.lpstrInitialDir = szInitialDir;
ofn.lpstrTitle = TEXT("Open With...");
ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
ofn.lpstrDefExt = TEXT("exe");
// Display the browse dialog and update our path edit box if neccessary.
if (GetOpenFileName(&ofn)) {
SetDlgItemText(hDlg, IDC_PATH, szApp);
}
break;
}
return FALSE;
}
return FALSE;
}
//******************************************************************************
//***** Comment Dialog Functions
//******************************************************************************
BOOL CALLBACK DlgProcComment(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
RECT rc;
HCURSOR hCur;
int result;
switch (uMsg) {
case WM_INITDIALOG:
// Get the handle to our edit box and store it globally.
g_hWndEdit = GetDlgItem(hDlg, IDC_COMMENT);
// Disable our edit box from being edited.
DisableEditing(g_hWndEdit);
#ifdef _WIN32_WCE
// Add "Ok" button to caption bar and make window No-Drag.
SetWindowLong(hDlg, GWL_EXSTYLE, WS_EX_CAPTIONOKBTN | WS_EX_NODRAG |
GetWindowLong(hDlg, GWL_EXSTYLE));
// On CE, we resize our dialog to be full screen (same size as parent).
GetWindowRect(g_hWndMain, &rc);
MoveWindow(hDlg, rc.left, rc.top, rc.right - rc.left,
rc.bottom - rc.top + 1, FALSE);
#else
// On NT we just center the dialog.
CenterWindow(hDlg);
#endif
// Set our edit control to be the full size of our dialog.
GetClientRect(hDlg, &rc);
MoveWindow(g_hWndEdit, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, FALSE);
// Show hour glass cursor while processing comment.
hCur = SetCursor(LoadCursor(NULL, IDC_WAIT));
// Let Info-ZIP and our callbacks do the work.
result = DoGetComment(g_szZipFile);
// Restore/remove our cursor.
SetCursor(hCur);
// Display an error dialog if an error occurred.
if ((result != PK_OK) && (result != PK_WARN)) {
MessageBox(g_hWndMain, GetZipErrorString(result), g_szAppName,
MB_ICONERROR | MB_OK);
}
// Clear our global edit box handle as we are done with it.
g_hWndEdit = NULL;
// Return FALSE to prevent edit box from gaining focus and showing highlight.
return FALSE;
case WM_COMMAND:
if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL)) {
EndDialog(hDlg, LOWORD(wParam));
}
return FALSE;
}
return FALSE;
}
//******************************************************************************
//***** About Dialog Functions
//******************************************************************************
BOOL CALLBACK DlgProcAbout(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
case WM_INITDIALOG:
#ifdef _WIN32_WCE
// Add "Ok" button to caption bar.
SetWindowLong(hDlg, GWL_EXSTYLE, WS_EX_CAPTIONOKBTN |
GetWindowLong(hDlg, GWL_EXSTYLE));
#endif
// Fill in a few static members.
// (For VER_FULLVERSION_STR and VER_COMMENT_STR, the TEXT() macro is
// not applicable, because they are defined as a set of concatenated
// string constants. These strings need to be converted to UNICODE
// at runtime, sigh.)
TCHAR szBuffer[128];
SetDlgItemText(hDlg, IDC_PRODUCT, TEXT(VER_PRODUCT_STR));
#ifdef UNICODE
_stprintf(szBuffer, TEXT("Freeware Version %S"), VER_FULLVERSION_STR);
#else
_stprintf(szBuffer, TEXT("Freeware Version %s"), VER_FULLVERSION_STR);
#endif
SetDlgItemText(hDlg, IDC_VERSION, szBuffer);
_stprintf(szBuffer, TEXT("Developed by %s"), TEXT(VER_DEVELOPER_STR));
SetDlgItemText(hDlg, IDC_DEVELOPER, szBuffer);
SetDlgItemText(hDlg, IDC_COPYRIGHT, TEXT(VER_COPYRIGHT_STR));
#ifdef UNICODE
_stprintf(szBuffer, TEXT("%S"), VER_COMMENT_STR);
SetDlgItemText(hDlg, IDC_COMMENT, szBuffer);
#else
( run in 0.472 second using v1.01-cache-2.11-cpan-99c4e6809bf )