📄 dlgcode.c
字号:
LPWSTR lpszNewText = (LPWSTR) err_malloc ((j + 1) * 2);
j = MultiByteToWideChar (CP_ACP, 0L, lpszText, -1, lpszNewText, j + 1);
if (j > 0)
wcscpy ((LPWSTR) lpszText, lpszNewText);
else
wcscpy ((LPWSTR) lpszText, (LPWSTR) "");
free (lpszNewText);
}
}
/* InitDialog - initialize the applications main dialog, this function should
be called only once in the dialogs WM_INITDIALOG message handler */
void
InitDialog (HWND hwndDlg)
{
HDC hDC;
int nHeight;
LOGFONT lf;
HMENU hMenu;
hDC = GetDC (hwndDlg);
nHeight = -((8 * GetDeviceCaps (hDC, LOGPIXELSY)) / 72);
lf.lfHeight = nHeight;
lf.lfWidth = 0;
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = FW_LIGHT;
lf.lfItalic = FALSE;
lf.lfUnderline = FALSE;
lf.lfStrikeOut = FALSE;
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = PROOF_QUALITY;
lf.lfPitchAndFamily = FF_DONTCARE;
strcpy (lf.lfFaceName, "Courier");
hSmallFont = CreateFontIndirect (&lf);
if (hSmallFont == NULL)
{
handleWin32Error (hwndDlg);
AbortProcess (IDS_NOFONT);
}
nHeight = -((10 * GetDeviceCaps (hDC, LOGPIXELSY)) / 72);
lf.lfHeight = nHeight;
lf.lfWeight = FW_BLACK;
strcpy (lf.lfFaceName, "Arial");
hSmallBoldFont = CreateFontIndirect (&lf);
if (hSmallBoldFont == NULL)
{
handleWin32Error (hwndDlg);
AbortProcess (IDS_NOFONT);
}
nHeight = -((16 * GetDeviceCaps (hDC, LOGPIXELSY)) / 72);
lf.lfHeight = nHeight;
lf.lfWeight = FW_BOLD;
strcpy (lf.lfFaceName, "Times");
hBoldFont = CreateFontIndirect (&lf);
if (hBoldFont == NULL)
{
handleWin32Error (hwndDlg);
AbortProcess (IDS_NOFONT);
}
nHeight = -((16 * GetDeviceCaps (hDC, LOGPIXELSY)) / 72);
lf.lfHeight = nHeight;
lf.lfWeight = FW_REGULAR;
hTitleFont = CreateFontIndirect (&lf);
if (hTitleFont == NULL)
{
handleWin32Error (hwndDlg);
AbortProcess (IDS_NOFONT);
}
nHeight = -((9 * GetDeviceCaps (hDC, LOGPIXELSY)) / 72);
lf.lfHeight = nHeight;
lf.lfWidth = 0;
lf.lfEscapement = 0;
lf.lfOrientation = 0;
lf.lfWeight = FW_NORMAL;
lf.lfItalic = FALSE;
lf.lfUnderline = FALSE;
lf.lfStrikeOut = FALSE;
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = PROOF_QUALITY;
lf.lfPitchAndFamily = FF_DONTCARE;
strcpy (lf.lfFaceName, "Lucida Console");
hFixedFont = CreateFontIndirect (&lf);
if (hFixedFont == NULL)
{
handleWin32Error (hwndDlg);
AbortProcess (IDS_NOFONT);
}
hMenu = GetSystemMenu (hwndDlg, FALSE);
AppendMenu (hMenu, MF_SEPARATOR, 0, NULL);
AppendMenu (hMenu, MF_ENABLED | MF_STRING, IDC_ABOUT, getstr (IDS_ABOUTBOX));
SetDefaultUserFont(hwndDlg);
}
HDC
CreateMemBitmap (HINSTANCE hInstance, HWND hwnd, char *resource)
{
HBITMAP picture = LoadBitmap (hInstance, resource);
HDC viewDC = GetDC (hwnd), dcMem;
dcMem = CreateCompatibleDC (viewDC);
SetMapMode (dcMem, MM_TEXT);
SelectObject (dcMem, picture);
ReleaseDC (hwnd, viewDC);
return dcMem;
}
/* Draw the specified bitmap at the specified location - Stretch to fit. */
void
PaintBitmap (HDC pdcMem, int x, int y, int nWidth, int nHeight, HDC hDC)
{
HGDIOBJ picture = GetCurrentObject (pdcMem, OBJ_BITMAP);
BITMAP bitmap;
GetObject (picture, sizeof (BITMAP), &bitmap);
BitBlt (hDC, x, y, nWidth, nHeight, pdcMem, 0, 0, SRCCOPY);
}
LRESULT CALLBACK
SplashDlgProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
//if (uMsg == WM_ERASEBKGND)
//{
// NONCLIENTMETRICS metric;
// HFONT font;
// HDC hDC = (HDC) wParam;
// char szTmp[64];
// HGDIOBJ obj;
// WORD bx = LOWORD (GetDialogBaseUnits ());
// WORD by = HIWORD (GetDialogBaseUnits ());
// DefDlgProc (hwnd, uMsg, wParam, lParam);
// SetBkMode (hDC, TRANSPARENT);
// SetTextColor (hDC, RGB (0, 0, 100));
// obj = SelectObject (hDC, hTitleFont);
// metric.cbSize = sizeof (NONCLIENTMETRICS);
// SystemParametersInfo (SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &metric, 0);
// font = CreateFontIndirect (&metric.lfMessageFont);
// obj = SelectObject (hDC, font);
// TextOut (hDC, (12 * bx) / 4, (70 * by) / 8, szTmp, strlen (szTmp));
// SelectObject (hDC, obj);
// return TRUE;
//}
return DefDlgProc (hwnd, uMsg, wParam, lParam);
}
void
WaitCursor ()
{
static HCURSOR hcWait;
if (hcWait == NULL)
hcWait = LoadCursor (NULL, IDC_WAIT);
SetCursor (hcWait);
hCursor = hcWait;
}
void
NormalCursor ()
{
static HCURSOR hcArrow;
if (hcArrow == NULL)
hcArrow = LoadCursor (NULL, IDC_ARROW);
SetCursor (hcArrow);
hCursor = NULL;
}
void
ArrowWaitCursor ()
{
static HCURSOR hcArrowWait;
if (hcArrowWait == NULL)
hcArrowWait = LoadCursor (NULL, IDC_APPSTARTING);
SetCursor (hcArrowWait);
hCursor = hcArrowWait;
}
LRESULT CALLBACK
CustomDlgProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_SETCURSOR && hCursor != NULL)
{
SetCursor (hCursor);
return TRUE;
}
return DefDlgProc (hwnd, uMsg, wParam, lParam);
}
/* InitApp - initialize the application, this function is called once in the
applications WinMain function, but before the main dialog has been created */
void
InitApp (HINSTANCE hInstance)
{
WNDCLASS wc;
char *lpszTmp;
OSVERSIONINFO os;
/* Save the instance handle for later */
hInst = hInstance;
/* Pull down the windows version */
os.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
if (GetVersionEx (&os) == FALSE)
AbortProcess (IDS_NO_OS_VER);
else if (os.dwPlatformId == VER_PLATFORM_WIN32_NT)
nCurrentOS = WIN_NT;
else if (os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && os.dwMajorVersion == 4 && os.dwMinorVersion == 0)
nCurrentOS = WIN_95;
else if (os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && os.dwMajorVersion == 4 && os.dwMinorVersion == 10)
nCurrentOS = WIN_98;
else {
/* AbortProcess (IDS_NO_OS_VER); */
nCurrentOS = WIN_98;
}
CurrentOSMajor = os.dwMajorVersion;
CurrentOSMinor = os.dwMinorVersion;
// OS version check
if (CurrentOSMajor < 5)
{
MessageBox (NULL, "TrueCrypt does not support this operating system.", lpszTitle, MB_ICONSTOP);
exit (1);
}
/* Get the attributes for the standard dialog class */
if ((GetClassInfo (hInst, WINDOWS_DIALOG_CLASS, &wc)) == 0)
AbortProcess (IDS_INIT_REGISTER);
#ifndef SETUP
wc.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_TRUECRYPT_ICON));
#else
#include "../setup/resource.h"
wc.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_SETUP));
#endif
wc.lpszClassName = TC_DLG_CLASS;
wc.lpfnWndProc = &CustomDlgProc;
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.cbWndExtra = DLGWINDOWEXTRA;
hDlgClass = RegisterClass (&wc);
if (hDlgClass == 0)
AbortProcess (IDS_INIT_REGISTER);
wc.lpszClassName = TC_SPLASH_CLASS;
wc.lpfnWndProc = &SplashDlgProc;
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.cbWndExtra = DLGWINDOWEXTRA;
hSplashClass = RegisterClass (&wc);
if (hSplashClass == 0)
AbortProcess (IDS_INIT_REGISTER);
GetModuleFileName (NULL, szHelpFile, sizeof (szHelpFile));
lpszTmp = strrchr (szHelpFile, '\\');
if (lpszTmp)
{
strcpy (++lpszTmp, "TrueCrypt User Guide.pdf");
}
#ifndef VOLFORMAT
hMutex = CreateMutex (NULL, TRUE, lpszTitle);
if (hMutex == NULL)
{
handleWin32Error (NULL);
AbortProcess (IDS_INIT_MUTEX);
}
if (GetLastError ()== ERROR_ALREADY_EXISTS)
{
// If executed twice, just top the first instance and exit
HWND h = FindWindow (0, lpszTitle);
if (h != 0)
{
ShowWindow (h, SW_SHOWNORMAL);
SetForegroundWindow (h);
exit (1);
}
else
AbortProcess (IDS_TWO_INSTANCES);
}
#endif
}
BOOL
OpenDevice (char *lpszPath, OPEN_TEST_STRUCT * driver)
{
DWORD dwResult;
BOOL bResult;
strcpy ((char *) &driver->wszFileName[0], lpszPath);
if (nCurrentOS == WIN_NT)
ToUNICODE ((char *) &driver->wszFileName[0]);
bResult = DeviceIoControl (hDriver, OPEN_TEST,
driver, sizeof (OPEN_TEST_STRUCT),
&driver, sizeof (OPEN_TEST_STRUCT),
&dwResult, NULL);
if (bResult == FALSE)
{
dwResult = GetLastError ();
if (dwResult == ERROR_SHARING_VIOLATION)
return TRUE;
else
return FALSE;
}
else
{
if (nCurrentOS == WIN_NT)
return TRUE;
else if (driver->nReturnCode == 0)
return TRUE;
else
{
SetLastError (ERROR_FILE_NOT_FOUND);
return FALSE;
}
}
}
UINT _stdcall
win9x_io (HFILE hFile, char *lpBuffer, UINT uBytes)
{
DISKIO_STRUCT *win9x_r0 = (DISKIO_STRUCT *) hFile;
DWORD dwResult;
BOOL bResult;
LONG secs;
win9x_r0->bufferad = (void *) lpBuffer;
secs = uBytes / SECTOR_SIZE;
win9x_r0->sectorlen = secs;
bResult = DeviceIoControl (hDriver, DISKIO, win9x_r0, sizeof (DISKIO_STRUCT), win9x_r0,
sizeof (DISKIO_STRUCT), &dwResult, NULL);
if (bResult == FALSE || win9x_r0->nReturnCode != 0)
return (UINT) HFILE_ERROR;
win9x_r0->sectorstart += secs;
return uBytes;
}
int
GetAvailableFixedDisks (HWND hComboBox, char *lpszRootPath)
{
int i, n;
int line = 0;
LVITEM LvItem;
__int64 deviceSize = 0;
for (i = 0; i < 64; i++)
{
BOOL drivePresent = FALSE;
BOOL removable = FALSE;
for (n = 0; n <= 32; n++)
{
char szTmp[TC_MAX_PATH], item1[100]={0}, item2[100]={0};
OPEN_TEST_STRUCT driver;
sprintf (szTmp, lpszRootPath, i, n);
if (OpenDevice (szTmp, &driver) == TRUE)
{
int nDosLinkCreated;
HANDLE dev;
DWORD dwResult;
BOOL bResult;
PARTITION_INFORMATION diskInfo;
DISK_GEOMETRY driveInfo;
char szDosDevice[TC_MAX_PATH], szCFDevice[TC_MAX_PATH];
drivePresent = TRUE;
if (nCurrentOS == WIN_NT)
{
nDosLinkCreated = FakeDosNameForDevice (szTmp, szDosDevice,
szCFDevice, FALSE);
dev = CreateFile (szCFDevice, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE , NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
bResult = DeviceIoControl (dev, IOCTL_DISK_GET_PARTITION_INFO, NULL, 0,
&diskInfo, sizeof (diskInfo), &dwResult, NULL);
// Test if device is removable
if (n == 0 && DeviceIoControl (dev, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,
&driveInfo, sizeof (driveInfo), &dwResult, NULL))
removable = driveInfo.MediaType == RemovableMedia;
RemoveFakeDosName(szTmp, szDosDevice);
CloseHandle(dev);
if (bResult == TRUE)
{
char partType[100];
// System creates a virtual partition1 for some storage devices without
// partition table. We try to detect this case by comparing sizes of
// partition0 and partition1. If they match, no partition of the device
// is displayed to the user to avoid confusion. Drive letter assigned by
// system to partition1 is displayed as subitem of partition0
if (n == 1 && diskInfo.PartitionLength.QuadPart == deviceSize)
{
char drive[] = { 0, ':', 0 };
char device[MAX_PATH * 2];
int driveNo;
// Drive letter
strcpy (device, szTmp);
ToUNICODE (device);
driveNo = GetDiskDeviceDriveLetter ((PWSTR) device);
drive[0] = driveNo == -1 ? 0 : 'A' + driveNo;
LvItem.iSubItem = 1;
LvItem.pszText = drive;
SendMessage (hComboBox,LVM_SETITEM,0,(LPARAM)&LvItem);
break;
}
switch(diskInfo.PartitionType)
{
case PARTITION_ENTRY_UNUSED: strcpy(partType, "Empty/unused"); break;
case PARTITION_XINT13_EXTENDED:
case PARTITION_EXTENDED: strcpy(partType, "Extended"); break;
case PARTITION_HUGE: sprintf(partType, "Unformatted (0x%02X)", diskInfo.PartitionType); break;
case PARTITION_FAT_12: strcpy(partType, "FAT12"); break;
case PARTITION_FAT_16: strcpy(partType, "FAT16"); break;
case PARTITION_FAT32:
case PARTITION_FAT32_XINT13: strcpy(partType, "FAT32"); break;
case 0x08: strcpy(partType, "DELL (spanning)"); break;
case 0x12: strcpy(partType, "Config/diagnostics"); break;
case 0x11:
case 0x14:
case 0x16:
case 0x1b:
case 0x1c:
case 0x1e: strcpy(partType, "Hidden FAT"); break;
case PARTITION_IFS: strcpy(partType, "NTFS"); break;
case 0x17: strcpy(partType, "Hidden NTFS"); break;
case 0x3c: strcpy(partType, "PMagic recovery"); break;
case 0x3d: strcpy(partType, "Hidden NetWare"); break;
case 0x41: strcpy(partType, "Linux/MINIX"); break;
case 0x42: strcpy(partType, "SFS/LDM/Linux Swap"); break;
case 0x51:
case 0x64:
case 0x65:
case 0x66:
case 0x67:
case 0x68:
case 0x69: strcpy(partType, "Novell"); break;
case 0x55: strcpy(partType, "EZ-Drive"); break;
case PARTITION_OS2BOOTMGR: strcpy(partType, "OS/2 BM"); break;
case PARTITION_XENIX_1:
case PARTITION_XENIX_2: strcpy(partType, "Xenix"); break;
case PARTITION_UNIX: strcpy(partType, "UNIX"); break;
case 0x74: strcpy(partType, "Scramdisk"); break;
case 0x78: strcpy(partType, "XOSL FS"); break;
case 0x80:
case 0x81: strcpy(partType, "MINIX"); break;
case 0x82: strcpy(partType, "Linux Swap"); break;
case 0x43:
case 0x83: strcpy(partType, "Linux"); break;
case 0xc2:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -