📄 dlgcode.c
字号:
metric.cbSize = sizeof (metric);
SystemParametersInfoW (SPI_GETNONCLIENTMETRICS, sizeof(metric), &metric, 0);
metric.lfMessageFont.lfHeight = CompensateDPIFont (!font ? -11 : -font->Size);
metric.lfMessageFont.lfWidth = 0;
if (font && wcscmp (font->FaceName, L"default") != 0)
{
wcsncpy ((WCHAR *)metric.lfMessageFont.lfFaceName, font->FaceName, sizeof (metric.lfMessageFont.lfFaceName)/2);
}
else if (nCurrentOS == WIN_VISTA_OR_LATER)
{
// Vista's new default font (size and spacing) breaks compatibility with Windows 2k/XP applications.
// Force use of Tahoma (as Microsoft does in many dialogs) until a native Vista look is implemented.
wcsncpy ((WCHAR *)metric.lfMessageFont.lfFaceName, L"Tahoma", sizeof (metric.lfMessageFont.lfFaceName)/2);
}
hUserFont = CreateFontIndirectW (&metric.lfMessageFont);
metric.lfMessageFont.lfUnderline = TRUE;
hUserUnderlineFont = CreateFontIndirectW (&metric.lfMessageFont);
metric.lfMessageFont.lfUnderline = FALSE;
metric.lfMessageFont.lfWeight = FW_BOLD;
hUserBoldFont = CreateFontIndirectW (&metric.lfMessageFont);
metric.lfMessageFont.lfUnderline = TRUE;
metric.lfMessageFont.lfWeight = FW_BOLD;
hUserUnderlineBoldFont = CreateFontIndirectW (&metric.lfMessageFont);
// Fixed-size (hexadecimal digits)
nHeight = CompensateDPIFont (-12);
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;
wcscpy (lf.lfFaceName, L"Courier New");
hFixedDigitFont = CreateFontIndirectW (&lf);
if (hFixedDigitFont == NULL)
{
handleWin32Error (hwndDlg);
AbortProcess ("NOFONT");
}
// Bold
font = GetFont ("font_bold");
nHeight = CompensateDPIFont (!font ? -13 : -font->Size);
lf.lfHeight = nHeight;
lf.lfWeight = FW_BLACK;
wcsncpy (lf.lfFaceName, !font ? L"Arial" : font->FaceName, sizeof (lf.lfFaceName)/2);
hBoldFont = CreateFontIndirectW (&lf);
if (hBoldFont == NULL)
{
handleWin32Error (hwndDlg);
AbortProcess ("NOFONT");
}
// Title
font = GetFont ("font_title");
nHeight = CompensateDPIFont (!font ? -21 : -font->Size);
lf.lfHeight = nHeight;
lf.lfWeight = FW_REGULAR;
wcsncpy (lf.lfFaceName, !font ? L"Times New Roman" : font->FaceName, sizeof (lf.lfFaceName)/2);
hTitleFont = CreateFontIndirectW (&lf);
if (hTitleFont == NULL)
{
handleWin32Error (hwndDlg);
AbortProcess ("NOFONT");
}
// Fixed-size
font = GetFont ("font_fixed");
nHeight = CompensateDPIFont (!font ? -12 : -font->Size);
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;
wcsncpy (lf.lfFaceName, !font ? L"Lucida Console" : font->FaceName, sizeof (lf.lfFaceName)/2);
hFixedFont = CreateFontIndirectW (&lf);
if (hFixedFont == NULL)
{
handleWin32Error (hwndDlg);
AbortProcess ("NOFONT");
}
if (!aboutMenuAppended)
{
hMenu = GetSystemMenu (hwndDlg, FALSE);
AppendMenu (hMenu, MF_SEPARATOR, 0, NULL);
AppendMenuW (hMenu, MF_ENABLED | MF_STRING, IDC_ABOUT, GetString ("ABOUTBOX"));
aboutMenuAppended = TRUE;
}
}
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);
DeleteObject (picture);
ReleaseDC (hwnd, viewDC);
return dcMem;
}
/* Renders the specified bitmap at the specified location and stretches it to fit (anti-aliasing is applied).
If bDirectRender is FALSE and both nWidth and nHeight are zero, the width and height of hwndDest are
retrieved and adjusted according to screen DPI (the width and height of the resultant image are adjusted the
same way); furthermore, if bKeepAspectRatio is TRUE, the smaller DPI factor of the two (i.e. horiz. or vert.)
is used both for horiz. and vert. scaling (note that the overall GUI aspect ratio changes irregularly in
both directions depending on the DPI). If bDirectRender is TRUE, bKeepAspectRatio is ignored.
This function returns a handle to the scaled bitmap. When the bitmap is no longer needed, it should be
deleted by calling DeleteObject() with the handle passed as the parameter.
Known Windows issues:
- For some reason, anti-aliasing is not applied if the source bitmap contains less than 16K pixels.
- Windows 2000 may produce slightly inaccurate colors even when source, buffer, and target are 24-bit true color. */
HBITMAP RenderBitmap (char *resource, HWND hwndDest, int x, int y, int nWidth, int nHeight, BOOL bDirectRender, BOOL bKeepAspectRatio)
{
LRESULT lResult = 0;
HDC hdcSrc = CreateMemBitmap (hInst, hwndDest, resource);
HGDIOBJ picture = GetCurrentObject (hdcSrc, OBJ_BITMAP);
HBITMAP hbmpRescaled;
BITMAP bitmap;
HDC hdcRescaled;
if (!bDirectRender && nWidth == 0 && nHeight == 0)
{
RECT rec;
GetClientRect (hwndDest, &rec);
if (bKeepAspectRatio)
{
if (DlgAspectRatio > 1)
{
// Do not fix this, it's correct. We use the Y scale factor intentionally for both
// directions to maintain aspect ratio (see above for more info).
nWidth = CompensateYDPI (rec.right);
nHeight = CompensateYDPI (rec.bottom);
}
else
{
// Do not fix this, it's correct. We use the X scale factor intentionally for both
// directions to maintain aspect ratio (see above for more info).
nWidth = CompensateXDPI (rec.right);
nHeight = CompensateXDPI (rec.bottom);
}
}
else
{
nWidth = CompensateXDPI (rec.right);
nHeight = CompensateYDPI (rec.bottom);
}
}
GetObject (picture, sizeof (BITMAP), &bitmap);
hdcRescaled = CreateCompatibleDC (hdcSrc);
hbmpRescaled = CreateCompatibleBitmap (hdcSrc, nWidth, nHeight);
SelectObject (hdcRescaled, hbmpRescaled);
/* Anti-aliasing mode (HALFTONE is the only anti-aliasing algorithm natively supported by Windows 2000.
TODO: GDI+ offers higher quality -- InterpolationModeHighQualityBicubic) */
SetStretchBltMode (hdcRescaled, HALFTONE);
StretchBlt (hdcRescaled,
0,
0,
nWidth,
nHeight,
hdcSrc,
0,
0,
bitmap.bmWidth,
bitmap.bmHeight,
SRCCOPY);
DeleteDC (hdcSrc);
if (bDirectRender)
{
HDC hdcDest = GetDC (hwndDest);
BitBlt (hdcDest, x, y, nWidth, nHeight, hdcRescaled, 0, 0, SRCCOPY);
DeleteDC (hdcDest);
}
else
{
lResult = SendMessage (hwndDest, (UINT) STM_SETIMAGE, (WPARAM) IMAGE_BITMAP, (LPARAM) (HANDLE) hbmpRescaled);
}
if ((HGDIOBJ) lResult != NULL && (HGDIOBJ) lResult != (HGDIOBJ) hbmpRescaled)
DeleteObject ((HGDIOBJ) lResult);
DeleteDC (hdcRescaled);
return hbmpRescaled;
}
LRESULT CALLBACK
RedTick (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_CREATE)
{
}
else if (uMsg == WM_DESTROY)
{
}
else if (uMsg == WM_TIMER)
{
}
else if (uMsg == WM_PAINT)
{
PAINTSTRUCT tmp;
HPEN hPen;
HDC hDC;
BOOL bEndPaint;
RECT Rect;
if (GetUpdateRect (hwnd, NULL, FALSE))
{
hDC = BeginPaint (hwnd, &tmp);
bEndPaint = TRUE;
if (hDC == NULL)
return DefWindowProc (hwnd, uMsg, wParam, lParam);
}
else
{
hDC = GetDC (hwnd);
bEndPaint = FALSE;
}
GetClientRect (hwnd, &Rect);
hPen = CreatePen (PS_SOLID, 2, RGB (0, 255, 0));
if (hPen != NULL)
{
HGDIOBJ hObj = SelectObject (hDC, hPen);
WORD bx = LOWORD (GetDialogBaseUnits ());
WORD by = HIWORD (GetDialogBaseUnits ());
MoveToEx (hDC, (Rect.right - Rect.left) / 2, Rect.bottom, NULL);
LineTo (hDC, Rect.right, Rect.top);
MoveToEx (hDC, (Rect.right - Rect.left) / 2, Rect.bottom, NULL);
LineTo (hDC, (3 * bx) / 4, (2 * by) / 8);
SelectObject (hDC, hObj);
DeleteObject (hPen);
}
if (bEndPaint)
EndPaint (hwnd, &tmp);
else
ReleaseDC (hwnd, hDC);
return TRUE;
}
return DefWindowProc (hwnd, uMsg, wParam, lParam);
}
BOOL
RegisterRedTick (HINSTANCE hInstance)
{
WNDCLASS wc;
ULONG rc;
memset(&wc, 0 , sizeof wc);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.cbClsExtra = 0;
wc.cbWndExtra = 4;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wc.hCursor = NULL;
wc.hbrBackground = (HBRUSH) GetStockObject (LTGRAY_BRUSH);
wc.lpszClassName = "REDTICK";
wc.lpfnWndProc = &RedTick;
rc = (ULONG) RegisterClass (&wc);
return rc == 0 ? FALSE : TRUE;
}
BOOL
UnregisterRedTick (HINSTANCE hInstance)
{
return UnregisterClass ("REDTICK", hInstance);
}
LRESULT CALLBACK
SplashDlgProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
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;
}
void HandCursor ()
{
static HCURSOR hcHand;
if (hcHand == NULL)
hcHand = LoadCursor (NULL, IDC_HAND);
SetCursor (hcHand);
hCursor = hcHand;
}
void
AddComboPair (HWND hComboBox, char *lpszItem, int value)
{
LPARAM nIndex;
nIndex = SendMessage (hComboBox, CB_ADDSTRING, 0, (LPARAM) lpszItem);
nIndex = SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) value);
}
void
AddComboPairW (HWND hComboBox, wchar_t *lpszItem, int value)
{
LPARAM nIndex;
nIndex = SendMessageW (hComboBox, CB_ADDSTRING, 0, (LPARAM) lpszItem);
nIndex = SendMessage (hComboBox, CB_SETITEMDATA, nIndex, (LPARAM) value);
}
void
SelectAlgo (HWND hComboBox, int *algo_id)
{
LPARAM nCount = SendMessage (hComboBox, CB_GETCOUNT, 0, 0);
LPARAM x, i;
for (i = 0; i < nCount; i++)
{
x = SendMessage (hComboBox, CB_GETITEMDATA, i, 0);
if (x == (LPARAM) *algo_id)
{
SendMessage (hComboBox, CB_SETCURSEL, i, 0);
return;
}
}
/* Something went wrong ; couldn't find the requested algo id so we drop
back to a default */
*algo_id = SendMessage (hComboBox, CB_GETITEMDATA, 0, 0);
SendMessage (hComboBox, CB_SETCURSEL, 0, 0);
}
void PopulateWipeModeCombo (HWND hComboBox, BOOL bNA)
{
if (bNA)
{
AddComboPairW (hComboBox, GetString ("N_A_UISTR"), TC_WIPE_NONE);
}
else
{
AddComboPairW (hComboBox, GetString ("WIPE_MODE_NONE"), TC_WIPE_NONE);
AddComboPairW (hComboBox, GetString ("WIPE_MODE_3_DOD_5220"), TC_WIPE_3_DOD_5220);
AddComboPairW (hComboBox, GetString ("WIPE_MODE_7_DOD_5220"), TC_WIPE_7_DOD_5220);
AddComboPairW (hComboBox, GetString ("WIPE_MODE_35_GUTMANN"), TC_WIPE_35_GUTMANN);
}
}
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);
}
void ExceptionHandlerThread (void *ept)
{
#define MAX_RET_ADDR_COUNT 8
EXCEPTION_POINTERS *ep = (EXCEPTION_POINTERS *) ept;
DWORD addr, retAddr[MAX_RET_ADDR_COUNT];
DWORD exCode = ep->ExceptionRecord->ExceptionCode;
SYSTEM_INFO si;
wchar_t msg[8192];
char modPath[MAX_PATH];
int crc = 0;
char url[MAX_URL_LENGTH];
char lpack[128];
int i;
addr = (DWORD) ep->ExceptionRecord->ExceptionAddress;
ZeroMemory (retAddr, sizeof (retAddr));
switch (exCode)
{
case 0x80000003:
case 0x80000004:
case 0xc0000006:
case 0xc000001d:
case 0xc000001e:
case 0xc0000096:
case 0xeedfade:
// Exception not caused by TrueCrypt
MessageBoxW (0, GetString ("EXCEPTION_REPORT_EXT"),
GetString ("EXCEPTION_REPORT_TITLE"),
MB_ICONERROR | MB_OK | MB_SETFOREGROUND | MB_TOPMOST);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -