wndmain.c
来自「文件驱动加密,功能强大,可产生加密分区,支持AES,MD2,MD4,MD5MD2」· C语言 代码 · 共 1,763 行 · 第 1/4 页
C
1,763 行
// Description:
// By Sarah Dean
// Email: sdean12@sdean12.org
// WWW: http://www.FreeOTFE.org/
//
// -----------------------------------------------------------------------------
//
// Note: List sorting not implemented; see parts marked with "[SORTRELATED]"
#include <windows.h>
#include <Windowsx.h> // Needed for GET_X_LPARAM, GET_Y_LPARAM macros
#include <Shellapi.h> // Needed for SHGetFileInfo(...)
#include <commctrl.h>
#include <stdlib.h> // Needed for itow(...)
#include <aygshell.h> // Required for SH... functions/definitions/etc
#pragma comment(lib, "aygshell") // Link in aygshell.lib
#include "SDUGeneral.h" // Required for SDUParsePath
#include "main.h"
#include "FreeOTFEDebug.h"
#include "FreeOTFElib.h"
#include "FreeOTFEGUIlib.h"
#include "FreeOTFE4PDAlib.h"
#include "dlgAbout.h"
#include "dlgNewVolWizard.h"
#include "dlgChpassKeyfileWizard.h"
#include "dlgDumpCDBWizard.h"
#include "dlgBackupRestore.h"
#include "dlgMount.h"
#include "dlgProperties.h"
#include "dlgOptions.h"
#include "wndMain.h"
#include "DriverInterface.h"
#include "FreeOTFEStats.h"
#include "FreeOTFE4PDAOptions.h"
#include "resource.h"
// Control ID of the main list view
#define IDC_MAIN_LISTVIEW 100
// Column indexes and widths
#define COL_IDX_MOUNTPOINT 0
#define COL_IDX_FILENAME 1
#define COL_WIDTH_MOUNTPOINT 100
#define COL_WIDTH_FILENAME 100
// When displaying "large icons", the indentation of the icon in pixels
// from the left
#define INDENT_ICON 2
// When displaying "large icons", the indentation of the text from the icon
#define INDENT_TEXT 5
// When displaying "large icons", the size of the icons used (fallback values
// if the size cannot be autodetermined)
#define ICON_FALLBACK_SIZE_X 32
#define ICON_FALLBACK_SIZE_Y 32
// Local to this file...
HMENU G_hMenuContext;
HWND G_hWndMenuBar;
HWND G_hWndListView;
// =========================================================================
// Forward declarations...
// [SORTRELATED]
int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
void wndMain_RefreshList(HWND hWnd);
HWND wndMain_CreateListDisplay(HWND hWnd);
void wndMain_SetupIconSize();
// =========================================================================
// Resize the listview to the maximum it can be displayed
void wndMain_SizeListView()
{
RECT rcClient;
if (G_hWndListView != NULL)
{
// Get size of display area...
GetClientRect(GetParent(G_hWndListView), &rcClient);
// Resize...
SetWindowPos(
G_hWndListView,
NULL,
0,
0,
rcClient.right,
rcClient.bottom,
SWP_NOZORDER
);
}
}
// =========================================================================
// Purge down any existing, create and size the listview
void wndMain_SetupListDisplay(HWND hWnd)
{
if (G_hWndListView != NULL)
{
DestroyWindow(G_hWndListView);
}
G_hWndListView = wndMain_CreateListDisplay(hWnd);
if(G_hWndListView == NULL)
{
MsgError(hWnd, TEXT("Could not create list display"));
}
else
{
wndMain_SizeListView();
wndMain_SetupIconSize();
wndMain_RefreshList(hWnd);
}
}
// =========================================================================
// Create new listview
// Returns: The handle to the listview created
HWND wndMain_CreateListDisplay(HWND hWnd)
{
HWND retval;
INITCOMMONCONTROLSEX icex;
DWORD dwStyle;
// Ensure that the common control DLL is loaded.
icex.dwSize = sizeof(icex);
icex.dwICC = ICC_LISTVIEW_CLASSES;
InitCommonControlsEx(&icex);
dwStyle = 0;
dwStyle = (
// [SORTRELATED]
// Note: These don't work with LVS_OWNERDRAW
// Note: These two don't work with WinCE versions
// up to v3.0! See MS KB article Q191295 for
// known MS bug
// LVS_SORTDESCENDING |
// LVS_SORTASCENDING |
WS_TABSTOP |
WS_CHILD |
WS_BORDER |
WS_VISIBLE |
LVS_AUTOARRANGE |
LVS_SHAREIMAGELISTS | // Vital! Shags the system
// imagelist if we omit this!
// (When the imagelist is
// destroyed, it destroys the
// system imagelist if this
// isn't set - a *really*
// silly thing to do as it
// makes all the system icons
// disappear!)
LVS_REPORT |
LVS_EX_FULLROWSELECT | // Can only be used with
// LVS_REPORT
LVS_SINGLESEL | // Only allow one item to be
// selected at once
LVS_ICON
// LVS_SMALLICON
);
if (G_Options->LargeIcons)
{
dwStyle |= LVS_OWNERDRAWFIXED;
dwStyle |= LVS_NOCOLUMNHEADER;
}
retval = CreateWindow(
WC_LISTVIEW,
L"XYZ", // Junk string required in order for the
// control to be displayed
dwStyle,
0, // Control will be repositioned later
0, // Control will be repositioned later
10, // Control will be resized later
10, // Control will be resized later
hWnd,
(HMENU)IDC_MAIN_LISTVIEW,
G_hInstance,
NULL
);
if (retval != NULL)
{
LVCOLUMN colDetails;
// Enable full row select
ListView_SetExtendedListViewStyle(
retval,
(
LVS_EX_FULLROWSELECT |
LVS_ICON
// LVS_SMALLICON
)
);
colDetails.mask = (
LVCF_FMT |
LVCF_TEXT |
LVCF_WIDTH |
LVCF_SUBITEM
);
colDetails.fmt = LVCFMT_LEFT;
colDetails.cx = COL_WIDTH_MOUNTPOINT; // Column width; reset later
colDetails.pszText = TEXT("Mountpoint");
colDetails.cchTextMax = wcslen(colDetails.pszText);
colDetails.iSubItem = COL_IDX_MOUNTPOINT;
ListView_InsertColumn(
retval,
COL_IDX_MOUNTPOINT,
&colDetails
);
colDetails.mask = (
LVCF_FMT |
LVCF_TEXT |
LVCF_WIDTH |
LVCF_SUBITEM
);
colDetails.fmt = LVCFMT_LEFT;
colDetails.cx = COL_WIDTH_FILENAME; // Column width; reset later
colDetails.pszText = TEXT("Volume");
colDetails.cchTextMax = wcslen(colDetails.pszText);
colDetails.iSubItem = COL_IDX_FILENAME;
ListView_InsertColumn(
retval,
COL_IDX_FILENAME,
&colDetails
);
}
return retval;
}
// =========================================================================
LRESULT CALLBACK wndMain_HandleMsg_WM_CREATE(HWND hWnd)
{
DEBUGOUTGUI(DEBUGLEV_ENTER, (TEXT("wndMain_HandleMsg_WM_CREATE\n")));
// Setup context menu...
G_hMenuContext = LoadMenu(G_hInstance, MAKEINTRESOURCE(IDR_MENU_CONTEXT));
// Setup menu/toolbar...
#ifdef FREEOTFE_STATS
G_hWndMenuBar = SetupMenu(hWnd, IDR_MENU_MAIN_DEBUG);
#else
#ifdef DEBUG
G_hWndMenuBar = SetupMenu(hWnd, IDR_MENU_MAIN_DEBUG);
#else
G_hWndMenuBar = SetupMenu(hWnd, IDR_MENU_MAIN);
#endif
#endif
// Button: New
MenuButtonAdd(
G_hWndMenuBar,
IDR_TOOLBAR_MAIN,
TOOLBAR_BITMAP_NEW,
ID_FILE_NEWVOL
);
// Button: Mount
MenuButtonAdd(
G_hWndMenuBar,
IDR_TOOLBAR_MAIN,
TOOLBAR_BITMAP_MOUNT,
ID_FILE_MOUNT
);
// Button: Dismount
MenuButtonAdd(
G_hWndMenuBar,
IDR_TOOLBAR_MAIN,
TOOLBAR_BITMAP_DISMOUNT,
ID_FILE_DISMOUNT
);
// Button: Dismount all
MenuButtonAdd(
G_hWndMenuBar,
IDR_TOOLBAR_MAIN,
TOOLBAR_BITMAP_DISMOUNT_ALL,
ID_FILE_DISMOUNTALL
);
// Setup listbox...
G_hWndListView = NULL;
wndMain_SetupListDisplay(hWnd);
DEBUGOUTGUI(DEBUGLEV_EXIT, (TEXT("wndMain_HandleMsg_WM_CREATE\n")));
return 0;
}
// =========================================================================
// Setup listview (column widths, etc)
// Note that the icons to use are setup as part of the wndMain_RefreshList(...)
void wndMain_SetupIconSize()
{
RECT rcClient;
int colWidthMountpoint;
int colWidthFilename;
SDUSetWndStyle(
G_hWndListView,
(G_Options->LargeIcons),
LVS_OWNERDRAWFIXED
);
SDUSetWndStyle(
G_hWndListView,
(G_Options->LargeIcons),
LVS_NOCOLUMNHEADER
);
if (G_Options->LargeIcons)
{
// Get size of display area...
GetClientRect(G_hWndListView, &rcClient);
// Large icons view only displays a single "column", which we
// draw. We set the width of the "filename" column to 0; if we
// didn't, the draw area would increase by this amount
// -2 to give a bit of a border on the right, and also to prevent the
// horizontal scrollbar from appearing automatically(!) when the list
// display is recreated after the Options dialog is displayed
colWidthMountpoint = ((rcClient.right - rcClient.left) - 2);
colWidthFilename = 0;
}
else
{
colWidthMountpoint = COL_WIDTH_MOUNTPOINT;
colWidthFilename = COL_WIDTH_FILENAME;
}
ListView_SetColumnWidth(
G_hWndListView,
COL_IDX_MOUNTPOINT,
colWidthMountpoint
);
ListView_SetColumnWidth(
G_hWndListView,
COL_IDX_FILENAME,
colWidthFilename
);
UpdateWindow(G_hWndListView);
}
// =========================================================================
LRESULT CALLBACK wndMain_HandleMsg_WM_SIZE(HWND hWnd)
{
DEBUGOUTGUI(DEBUGLEV_ENTER, (TEXT("wndMain_HandleMsg_WM_SIZE\n")));
// Just resize the list view...
wndMain_SizeListView();
DEBUGOUTGUI(DEBUGLEV_EXIT, (TEXT("wndMain_HandleMsg_WM_SIZE\n")));
return 0;
}
// =========================================================================
LRESULT CALLBACK wndMain_HandleMsg_WM_CLOSE(HWND hWnd)
{
DEBUGOUTGUI(DEBUGLEV_ENTER, (TEXT("wndMain_HandleMsg_WM_CLOSE\n")));
if (G_hMenuContext != NULL)
{
DestroyMenu(G_hMenuContext);
}
if (G_hWndMenuBar != NULL)
{
DestroyWindow(G_hWndMenuBar);
}
DestroyWindow(hWnd);
DEBUGOUTGUI(DEBUGLEV_EXIT, (TEXT("wndMain_HandleMsg_WM_CLOSE\n")));
return 0;
}
// =========================================================================
LRESULT CALLBACK wndMain_HandleMsg_WM_DESTROY()
{
DEBUGOUTGUI(DEBUGLEV_ENTER, (TEXT("wndMain_HandleMsg_WM_DESTROY\n")));
// Quit the application...
PostQuitMessage(0);
DEBUGOUTGUI(DEBUGLEV_EXIT, (TEXT("wndMain_HandleMsg_WM_DESTROY\n")));
return 0;
}
// =========================================================================
#ifdef DEBUG
BOOL TestOne(HWND hWnd)
{
return TRUE;
}
BOOL TestTwo(HWND hWnd)
{
return TRUE;
}
BOOL TestThree(HWND hWnd)
{
return TRUE;
}
#endif
// =========================================================================
void _wndMain_DismountAll(HWND hWnd)
{
BOOL allOK;
HCURSOR csrHourglass;
HCURSOR csrPrevious;
csrHourglass = LoadCursor(NULL, IDC_WAIT);
csrPrevious = SetCursor(csrHourglass);
// Try normal (unforced) dismount...
allOK = driver_DismountAll(FALSE);
wndMain_RefreshList(hWnd);
SetCursor(csrPrevious);
if (allOK)
{
MsgInfo(hWnd, TEXT("All volumes dismounted."));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?