📄 dlgcode.c
字号:
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));
}
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;
/* 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");
}
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);
}
#ifndef SETUP
/* Setup the service if it's not present */
if (CheckService ()== FALSE)
AbortProcess (IDS_NOSERVICE);
#endif
}
BOOL
InstallService (SC_HANDLE schSCManager, char *SZSERVICENAME, char *SZSERVICEDISPLAYNAME)
{
SC_HANDLE schService;
schService = CreateService (
schSCManager, /* SCManager database */
SZSERVICENAME, /* name of service */
SZSERVICEDISPLAYNAME, /* name to display */
SERVICE_ALL_ACCESS, /* desired access */
SERVICE_WIN32_OWN_PROCESS, /* service type */
SERVICE_AUTO_START, /* start type */
SERVICE_ERROR_NORMAL, /* error control type */
"TrueCryptService.exe", /* service's binary */
NULL, /* no load ordering
group */
NULL, /* no tag identifier */
"", /* dependencies */
NULL, /* LocalSystem account */
NULL); /* no password */
if (schService != NULL)
{
CloseServiceHandle (schService);
return TRUE;
}
return FALSE;
}
BOOL
CheckService ()
{
SC_HANDLE schService = NULL;
SC_HANDLE schSCManager = NULL;
BOOL bInstall = FALSE;
BOOL bAdmin = TRUE;
BOOL bResult = TRUE;
if (nCurrentOS != WIN_NT)
return TRUE;
schSCManager = OpenSCManager (
NULL, /* machine (NULL ==
local) */
NULL, /* database (NULL ==
default) */
SC_MANAGER_ALL_ACCESS /* access required */
);
if (schSCManager == NULL)
{
schSCManager = OpenSCManager (
NULL, /* machine (NULL ==
local) */
NULL, /* database (NULL ==
default) */
SC_MANAGER_CONNECT | SC_MANAGER_ENUMERATE_SERVICE | SC_MANAGER_QUERY_LOCK_STATUS /* access required */
);
bAdmin = FALSE;
}
if (schSCManager == NULL)
goto error;
if (bAdmin == TRUE)
schService = OpenService (schSCManager, "TrueCryptService", SERVICE_ALL_ACCESS);
else
schService = OpenService (schSCManager, "TrueCryptService", SERVICE_QUERY_STATUS);
if (schService == NULL)
{
BOOL bOK;
if (bAdmin == FALSE)
{
handleWin32Error (NULL);
CloseServiceHandle (schSCManager);
#ifndef SETUP
AbortProcess (IDS_NOSERVICE);
#else
return FALSE;
#endif
}
if (bInstall == TRUE)
goto error;
bInstall = TRUE;
bOK = InstallService (schSCManager, "TrueCryptService", "TrueCrypt Service");
if (bOK == FALSE)
goto error;
schService = OpenService (schSCManager, "TrueCryptService", SERVICE_ALL_ACCESS);
}
if (schService != NULL)
{
SERVICE_STATUS status;
BOOL bOK;
int i;
bOK = QueryServiceStatus (schService, &status);
if (bOK == FALSE)
goto error;
if (status.dwCurrentState == SERVICE_RUNNING || status.dwCurrentState == SERVICE_START_PENDING)
goto success;
if (bAdmin == FALSE)
{
CloseServiceHandle (schService);
CloseServiceHandle (schSCManager);
#ifndef SETUP
AbortProcess (IDS_SERVICE_NOT_RUNNING);
#else
return FALSE;
#endif
}
bOK = StartService (schService, 0, NULL);
if (bOK == FALSE)
goto error;
#define WAIT_PERIOD 3
for (i = 0; i < WAIT_PERIOD; i++)
{
Sleep (1000);
bOK = QueryServiceStatus (schService, &status);
if (bOK == FALSE)
goto error;
if (status.dwCurrentState == SERVICE_RUNNING)
break;
}
if (i == WAIT_PERIOD)
bOK = FALSE;
if (bOK == FALSE)
goto error;
else
goto success;
}
error:
if (GetLastError ()!= 0)
handleWin32Error (NULL);
bResult = FALSE;
success:
if (schService != NULL)
CloseServiceHandle (schService);
if (schSCManager != NULL)
CloseServiceHandle (schSCManager);
return bResult;
}
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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -