|
|
1.1 root 1: /* Copyright (C) 2004 TrueCrypt Team, truecrypt.org
2: This product uses components written by Paul Le Roux <[email protected]> */
3:
4: #include "TCdefs.h"
5:
6: #include <stdlib.h>
7:
8: #include "resource.h"
9: #include "crypto.h"
10: #include "apidrvr.h"
11: #include "dlgcode.h"
12:
13: char szHelpFile[TC_MAX_PATH];
14: HFONT hSmallFont = NULL;
15: HFONT hBoldFont = NULL;
16: HFONT hSmallBoldFont = NULL;
17: HFONT hTitleFont = NULL;
18: HFONT hFixedFont = NULL;
19:
20: HFONT hUserFont = NULL;
21: HFONT hUserUnderlineFont = NULL;
22: HFONT hUserBoldFont = NULL;
23:
24: char *lpszTitle = NULL;
25: int nCurrentOS = 0;
26: int CurrentOSMajor = 0;
27: int CurrentOSMinor = 0;
28:
29: /* Handle to the device driver */
30: HANDLE hDriver = INVALID_HANDLE_VALUE;
31: HINSTANCE hInst = NULL;
32: HANDLE hMutex = NULL;
33: HCURSOR hCursor = NULL;
34:
35: ATOM hDlgClass, hSplashClass;
36:
37: /* Windows dialog class */
38: #define WINDOWS_DIALOG_CLASS "#32770"
39:
40: /* Custom class names */
41: #define TC_DLG_CLASS "CustomDlg"
42: #define TC_SPLASH_CLASS "SplashDlg"
43:
44: void
45: cleanup ()
46: {
47: /* Cleanup the GDI fonts */
48: if (hFixedFont != NULL)
49: DeleteObject (hFixedFont);
50: if (hSmallFont != NULL)
51: DeleteObject (hSmallFont);
52: if (hBoldFont != NULL)
53: DeleteObject (hBoldFont);
54: if (hSmallBoldFont != NULL)
55: DeleteObject (hSmallBoldFont);
56: if (hTitleFont != NULL)
57: DeleteObject (hTitleFont);
58: if (hUserFont != NULL)
59: DeleteObject (hUserFont);
60: if (hUserUnderlineFont != NULL)
61: DeleteObject (hUserUnderlineFont);
62: if (hUserBoldFont != NULL)
63: DeleteObject (hUserBoldFont);
64: /* Cleanup our dialog class */
65: if (hDlgClass)
66: UnregisterClass (TC_DLG_CLASS, hInst);
67: if (hSplashClass)
68: UnregisterClass (TC_SPLASH_CLASS, hInst);
69: /* Close the device driver handle */
70: if (hDriver != INVALID_HANDLE_VALUE)
71: {
72: CloseHandle (hDriver);
73: }
74:
75: if (hMutex != NULL)
76: {
77: CloseHandle (hMutex);
78: }
79: }
80:
81: void
82: LowerCaseCopy (char *lpszDest, char *lpszSource)
83: {
84: int i = strlen (lpszSource);
85:
86: lpszDest[i] = 0;
87: while (--i >= 0)
88: {
89: lpszDest[i] = (char) tolower (lpszSource[i]);
90: }
91:
92: }
93:
94: void
95: UpperCaseCopy (char *lpszDest, char *lpszSource)
96: {
97: int i = strlen (lpszSource);
98:
99: lpszDest[i] = 0;
100: while (--i >= 0)
101: {
102: lpszDest[i] = (char) toupper (lpszSource[i]);
103: }
104: }
105:
106: void
107: CreateFullVolumePath (char *lpszDiskFile, char *lpszFileName, BOOL * bDevice)
108: {
109: if (strcmp (lpszFileName, "Floppy (A:)") == 0)
110: strcpy (lpszFileName, "\\Device\\Floppy0");
111: else if (strcmp (lpszFileName, "Floppy (B:)") == 0)
112: strcpy (lpszFileName, "\\Device\\Floppy1");
113:
114: UpperCaseCopy (lpszDiskFile, lpszFileName);
115:
116: *bDevice = FALSE;
117:
118: if (memcmp (lpszDiskFile, "\\DEVICE", sizeof (char) * 7) == 0)
119: {
120: *bDevice = TRUE;
121: }
122:
123: strcpy (lpszDiskFile, lpszFileName);
124:
125: #if _DEBUG
126: OutputDebugString ("CreateFullVolumePath: ");
127: OutputDebugString (lpszDiskFile);
128: OutputDebugString ("\n");
129: #endif
130:
131: }
132:
133: int
134: FakeDosNameForDevice (char *lpszDiskFile, char *lpszDosDevice, char *lpszCFDevice, BOOL bNameOnly)
135: {
136: BOOL bDosLinkCreated = TRUE;
137: sprintf (lpszDosDevice, "truecrypt%lu", GetCurrentProcessId ());
138:
139: if (bNameOnly == FALSE)
140: bDosLinkCreated = DefineDosDevice (DDD_RAW_TARGET_PATH, lpszDosDevice, lpszDiskFile);
141:
142: if (bDosLinkCreated == FALSE)
143: {
144: return ERR_OS_ERROR;
145: }
146: else
147: sprintf (lpszCFDevice, "\\\\.\\%s", lpszDosDevice);
148:
149: return 0;
150: }
151:
152: int
153: RemoveFakeDosName (char *lpszDiskFile, char *lpszDosDevice)
154: {
155: BOOL bDosLinkRemoved = DefineDosDevice (DDD_RAW_TARGET_PATH | DDD_EXACT_MATCH_ON_REMOVE |
156: DDD_REMOVE_DEFINITION, lpszDosDevice, lpszDiskFile);
157: if (bDosLinkRemoved == FALSE)
158: {
159: return ERR_OS_ERROR;
160: }
161:
162: return 0;
163: }
164:
165: char *
166: getstr (UINT nID)
167: {
168: static char szMsg[256];
169: if (LoadString (hInst, nID, szMsg, sizeof (szMsg)) == 0)
170: return "";
171: else
172: return szMsg;
173: }
174:
175: char *
176: getmultilinestr (UINT nID[4])
177: {
178: static char szMsg[1024];
179: if (nID[0])
180: strcpy (szMsg, getstr (nID[0]));
181: if (nID[1])
182: strcat (szMsg, getstr (nID[1]));
183: if (nID[2])
184: strcat (szMsg, getstr (nID[2]));
185: if (nID[3])
186: strcat (szMsg, getstr (nID[3]));
187: return szMsg;
188:
189: }
190:
191: void
192: AbortProcess (UINT nID)
193: {
194: MessageBeep (MB_ICONEXCLAMATION);
195: MessageBox (NULL, getstr (nID), lpszTitle, ICON_HAND);
196: exit (1);
197: }
198:
199: void *
200: err_malloc (size_t size)
201: {
202: void *z = (void *) TCalloc (size);
203: if (z)
204: return z;
205: AbortProcess (IDS_OUTOFMEMORY);
206: return 0;
207: }
208:
209: char *
210: err_strdup (char *lpszText)
211: {
212: int j = (strlen (lpszText) + 1) * sizeof (char);
213: char *z = (char *) err_malloc (j);
214: memmove (z, lpszText, j);
215: return z;
216: }
217:
218: void
219: handleWin32Error (HWND hwndDlg)
220: {
221: LPVOID lpMsgBuf;
222: DWORD dwError = GetLastError ();
223:
224: FormatMessage (
225: FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
226: NULL,
227: dwError,
228: MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
229: (char *) &lpMsgBuf,
230: 0,
231: NULL
232: );
233:
234: MessageBox (hwndDlg, lpMsgBuf, lpszTitle, ICON_HAND);
235: LocalFree (lpMsgBuf);
236: }
237:
238: BOOL
239: translateWin32Error (char *lpszMsgBuf, int nSizeOfBuf)
240: {
241: DWORD dwError = GetLastError ();
242:
243: if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError,
244: MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
245: lpszMsgBuf, nSizeOfBuf, NULL))
246: return TRUE;
247: else
248: return FALSE;
249: }
250:
251: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
252: should return nonzero if it processes the message, and zero if it does
253: not. - see DialogProc */
254: BOOL WINAPI
255: AboutDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
256: {
257: WORD lw = LOWORD (wParam);
258: if (lParam); /* remove warning */
259:
260: switch (msg)
261: {
262:
263: case WM_INITDIALOG:
264: {
265: char szTmp[32];
266:
267: SetDefaultUserFont (hwndDlg);
268: SendMessage (GetDlgItem (hwndDlg, ID_WEBSITE), WM_SETFONT, (WPARAM) hUserUnderlineFont, 0);
269: SendMessage (GetDlgItem (hwndDlg, IDT_ABOUT_VERSION), WM_SETFONT, (WPARAM) hUserBoldFont, 0);
270:
271: sprintf (szTmp, "TrueCrypt %s", VERSION_STRING);
272: SetDlgItemText (hwndDlg, IDT_ABOUT_VERSION, szTmp);
273: return 1;
274: }
275:
276: case WM_COMMAND:
277: if (lw == IDOK || lw == IDCANCEL)
278: {
279: EndDialog (hwndDlg, 0);
280: return 1;
281: }
282:
283: if (lw == ID_WEBSITE)
284: {
285: ArrowWaitCursor ();
286: ShellExecute (NULL, "open", "http://www.truecrypt.org", NULL, NULL, SW_SHOWNORMAL);
287: Sleep (200);
288: NormalCursor ();
289: return 1;
290: }
291: return 0;
292:
293: case WM_CLOSE:
294: EndDialog (hwndDlg, 0);
295: return 1;
296: }
297:
298: return 0;
299: }
300:
301: /* Except in response to the WM_INITDIALOG message, the dialog box procedure
302: should return nonzero if it processes the message, and zero if it does
303: not. - see DialogProc */
304: BOOL WINAPI
305: WarningDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
306: {
307: WORD lw = LOWORD (wParam);
308: if (lParam); /* remove warning */
309:
310: switch (msg)
311: {
312: case WM_INITDIALOG:
313: SetDefaultUserFont (hwndDlg);
314: SetWindowText (GetDlgItem (hwndDlg, IDC_WARNING_TEXT), (char*) lParam);
315: return 1;
316: case WM_COMMAND:
317: if (lw == IDOK || lw == IDCANCEL)
318: {
319: BOOL x = IsButtonChecked (GetDlgItem (hwndDlg, IDC_NEVER_SHOW));
320: if (x == TRUE)
321: EndDialog (hwndDlg, IDOK);
322: else
323: EndDialog (hwndDlg, IDCANCEL);
324: return 1;
325: }
326: return 0;
327: case WM_CLOSE:
328: EndDialog (hwndDlg, 0);
329: return 1;
330: }
331:
332: return 0;
333: }
334:
335: BOOL
336: IsButtonChecked (HWND hButton)
337: {
338: if (SendMessage (hButton, BM_GETCHECK, 0, 0) == BST_CHECKED)
339: return TRUE;
340: else
341: return FALSE;
342: }
343:
344: void
345: CheckButton (HWND hButton)
346: {
347: SendMessage (hButton, BM_SETCHECK, BST_CHECKED, 0);
348: }
349:
350:
351: /*****************************************************************************
352: ToSBCS: converts a unicode string to Single Byte Character String (SBCS).
353: ***************************************************************************/
354:
355: void
356: ToSBCS (LPWSTR lpszText)
357: {
358: int j = wcslen (lpszText);
359: if (j == 0)
360: {
361: strcpy ((char *) lpszText, "");
362: return;
363: }
364: else
365: {
366: char *lpszNewText = (char *) err_malloc (j + 1);
367: j = WideCharToMultiByte (CP_ACP, 0L, lpszText, -1, lpszNewText, j + 1, NULL, NULL);
368: if (j > 0)
369: strcpy ((char *) lpszText, lpszNewText);
370: else
371: strcpy ((char *) lpszText, "");
372: free (lpszNewText);
373: }
374: }
375:
376: /*****************************************************************************
377: ToUNICODE: converts a SBCS string to a UNICODE string.
378: ***************************************************************************/
379:
380: void
381: ToUNICODE (char *lpszText)
382: {
383: int j = strlen (lpszText);
384: if (j == 0)
385: {
386: wcscpy ((LPWSTR) lpszText, (LPWSTR) WIDE (""));
387: return;
388: }
389: else
390: {
391: LPWSTR lpszNewText = (LPWSTR) err_malloc ((j + 1) * 2);
392: j = MultiByteToWideChar (CP_ACP, 0L, lpszText, -1, lpszNewText, j + 1);
393: if (j > 0)
394: wcscpy ((LPWSTR) lpszText, lpszNewText);
395: else
396: wcscpy ((LPWSTR) lpszText, (LPWSTR) "");
397: free (lpszNewText);
398: }
399: }
400:
401: /* InitDialog - initialize the applications main dialog, this function should
402: be called only once in the dialogs WM_INITDIALOG message handler */
403: void
404: InitDialog (HWND hwndDlg)
405: {
406: HDC hDC;
407: int nHeight;
408: LOGFONT lf;
409: HMENU hMenu;
410:
411: hDC = GetDC (hwndDlg);
412:
413: nHeight = -((8 * GetDeviceCaps (hDC, LOGPIXELSY)) / 72);
414: lf.lfHeight = nHeight;
415: lf.lfWidth = 0;
416: lf.lfEscapement = 0;
417: lf.lfOrientation = 0;
418: lf.lfWeight = FW_LIGHT;
419: lf.lfItalic = FALSE;
420: lf.lfUnderline = FALSE;
421: lf.lfStrikeOut = FALSE;
422: lf.lfCharSet = DEFAULT_CHARSET;
423: lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
424: lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
425: lf.lfQuality = PROOF_QUALITY;
426: lf.lfPitchAndFamily = FF_DONTCARE;
427: strcpy (lf.lfFaceName, "Courier");
428: hSmallFont = CreateFontIndirect (&lf);
429: if (hSmallFont == NULL)
430: {
431: handleWin32Error (hwndDlg);
432: AbortProcess (IDS_NOFONT);
433: }
434:
435: nHeight = -((10 * GetDeviceCaps (hDC, LOGPIXELSY)) / 72);
436: lf.lfHeight = nHeight;
437: lf.lfWeight = FW_BLACK;
438: strcpy (lf.lfFaceName, "Arial");
439: hSmallBoldFont = CreateFontIndirect (&lf);
440: if (hSmallBoldFont == NULL)
441: {
442: handleWin32Error (hwndDlg);
443: AbortProcess (IDS_NOFONT);
444: }
445:
446: nHeight = -((16 * GetDeviceCaps (hDC, LOGPIXELSY)) / 72);
447: lf.lfHeight = nHeight;
448: lf.lfWeight = FW_BOLD;
449: strcpy (lf.lfFaceName, "Times");
450: hBoldFont = CreateFontIndirect (&lf);
451: if (hBoldFont == NULL)
452: {
453: handleWin32Error (hwndDlg);
454: AbortProcess (IDS_NOFONT);
455: }
456:
457: nHeight = -((16 * GetDeviceCaps (hDC, LOGPIXELSY)) / 72);
458: lf.lfHeight = nHeight;
459: lf.lfWeight = FW_REGULAR;
460: hTitleFont = CreateFontIndirect (&lf);
461: if (hTitleFont == NULL)
462: {
463: handleWin32Error (hwndDlg);
464: AbortProcess (IDS_NOFONT);
465: }
466:
467: nHeight = -((9 * GetDeviceCaps (hDC, LOGPIXELSY)) / 72);
468: lf.lfHeight = nHeight;
469: lf.lfWidth = 0;
470: lf.lfEscapement = 0;
471: lf.lfOrientation = 0;
472: lf.lfWeight = FW_NORMAL;
473: lf.lfItalic = FALSE;
474: lf.lfUnderline = FALSE;
475: lf.lfStrikeOut = FALSE;
476: lf.lfCharSet = DEFAULT_CHARSET;
477: lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
478: lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
479: lf.lfQuality = PROOF_QUALITY;
480: lf.lfPitchAndFamily = FF_DONTCARE;
481: strcpy (lf.lfFaceName, "Lucida Console");
482: hFixedFont = CreateFontIndirect (&lf);
483: if (hFixedFont == NULL)
484: {
485: handleWin32Error (hwndDlg);
486: AbortProcess (IDS_NOFONT);
487: }
488:
489: hMenu = GetSystemMenu (hwndDlg, FALSE);
490: AppendMenu (hMenu, MF_SEPARATOR, 0, NULL);
491: AppendMenu (hMenu, MF_ENABLED | MF_STRING, IDC_ABOUT, getstr (IDS_ABOUTBOX));
492: }
493:
494: HDC
495: CreateMemBitmap (HINSTANCE hInstance, HWND hwnd, char *resource)
496: {
497: HBITMAP picture = LoadBitmap (hInstance, resource);
498: HDC viewDC = GetDC (hwnd), dcMem;
499:
500: dcMem = CreateCompatibleDC (viewDC);
501:
502: SetMapMode (dcMem, MM_TEXT);
503:
504: SelectObject (dcMem, picture);
505:
506: ReleaseDC (hwnd, viewDC);
507:
508: return dcMem;
509: }
510:
511: /* Draw the specified bitmap at the specified location - Stretch to fit. */
512: void
513: PaintBitmap (HDC pdcMem, int x, int y, int nWidth, int nHeight, HDC hDC)
514: {
515: HGDIOBJ picture = GetCurrentObject (pdcMem, OBJ_BITMAP);
516:
517: BITMAP bitmap;
518: GetObject (picture, sizeof (BITMAP), &bitmap);
519:
520: BitBlt (hDC, x, y, nWidth, nHeight, pdcMem, 0, 0, SRCCOPY);
521: }
522:
523: LRESULT CALLBACK
524: SplashDlgProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
525: {
526:
527: //if (uMsg == WM_ERASEBKGND)
528: //{
529: // NONCLIENTMETRICS metric;
530: // HFONT font;
531:
532:
533: // HDC hDC = (HDC) wParam;
534: // char szTmp[64];
535: // HGDIOBJ obj;
536: // WORD bx = LOWORD (GetDialogBaseUnits ());
537: // WORD by = HIWORD (GetDialogBaseUnits ());
538:
539:
540: // DefDlgProc (hwnd, uMsg, wParam, lParam);
541:
542: // SetBkMode (hDC, TRANSPARENT);
543: // SetTextColor (hDC, RGB (0, 0, 100));
544: // obj = SelectObject (hDC, hTitleFont);
545:
546: // metric.cbSize = sizeof (NONCLIENTMETRICS);
547: // SystemParametersInfo (SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &metric, 0);
548: // font = CreateFontIndirect (&metric.lfMessageFont);
549: // obj = SelectObject (hDC, font);
550:
551: // TextOut (hDC, (12 * bx) / 4, (70 * by) / 8, szTmp, strlen (szTmp));
552:
553: // SelectObject (hDC, obj);
554: // return TRUE;
555: //}
556:
557: return DefDlgProc (hwnd, uMsg, wParam, lParam);
558: }
559:
560: void
561: WaitCursor ()
562: {
563: static HCURSOR hcWait;
564: if (hcWait == NULL)
565: hcWait = LoadCursor (NULL, IDC_WAIT);
566: SetCursor (hcWait);
567: hCursor = hcWait;
568: }
569:
570: void
571: NormalCursor ()
572: {
573: static HCURSOR hcArrow;
574: if (hcArrow == NULL)
575: hcArrow = LoadCursor (NULL, IDC_ARROW);
576: SetCursor (hcArrow);
577: hCursor = NULL;
578: }
579:
580: void
581: ArrowWaitCursor ()
582: {
583: static HCURSOR hcArrowWait;
584: if (hcArrowWait == NULL)
585: hcArrowWait = LoadCursor (NULL, IDC_APPSTARTING);
586: SetCursor (hcArrowWait);
587: hCursor = hcArrowWait;
588: }
589:
590: LRESULT CALLBACK
591: CustomDlgProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
592: {
593: if (uMsg == WM_SETCURSOR && hCursor != NULL)
594: {
595: SetCursor (hCursor);
596: return TRUE;
597: }
598:
599: return DefDlgProc (hwnd, uMsg, wParam, lParam);
600: }
601:
602: /* InitApp - initialize the application, this function is called once in the
603: applications WinMain function, but before the main dialog has been created */
604: void
605: InitApp (HINSTANCE hInstance)
606: {
607: WNDCLASS wc;
608: char *lpszTmp;
609: OSVERSIONINFO os;
610:
611: /* Save the instance handle for later */
612: hInst = hInstance;
613:
614: /* Pull down the windows version */
615: os.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
616: if (GetVersionEx (&os) == FALSE)
617: AbortProcess (IDS_NO_OS_VER);
618: else if (os.dwPlatformId == VER_PLATFORM_WIN32_NT)
619: nCurrentOS = WIN_NT;
620: else if (os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && os.dwMajorVersion == 4 && os.dwMinorVersion == 0)
621: nCurrentOS = WIN_95;
622: else if (os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && os.dwMajorVersion == 4 && os.dwMinorVersion == 10)
623: nCurrentOS = WIN_98;
624: else {
625: /* AbortProcess (IDS_NO_OS_VER); */
626: nCurrentOS = WIN_98;
627: }
628:
629: CurrentOSMajor = os.dwMajorVersion;
630: CurrentOSMinor = os.dwMinorVersion;
631:
632: /* Get the attributes for the standard dialog class */
633: if ((GetClassInfo (hInst, WINDOWS_DIALOG_CLASS, &wc)) == 0)
634: AbortProcess (IDS_INIT_REGISTER);
635:
636: #ifndef SETUP
637: wc.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_TRUECRYPT_ICON));
638: #else
639: #include "../setup/resource.h"
640: wc.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (IDI_SETUP));
641: #endif
642: wc.lpszClassName = TC_DLG_CLASS;
643: wc.lpfnWndProc = &CustomDlgProc;
644: wc.hCursor = LoadCursor (NULL, IDC_ARROW);
645: wc.cbWndExtra = DLGWINDOWEXTRA;
646:
647: hDlgClass = RegisterClass (&wc);
648: if (hDlgClass == 0)
649: AbortProcess (IDS_INIT_REGISTER);
650:
651: wc.lpszClassName = TC_SPLASH_CLASS;
652: wc.lpfnWndProc = &SplashDlgProc;
653: wc.hCursor = LoadCursor (NULL, IDC_ARROW);
654: wc.cbWndExtra = DLGWINDOWEXTRA;
655:
656: hSplashClass = RegisterClass (&wc);
657: if (hSplashClass == 0)
658: AbortProcess (IDS_INIT_REGISTER);
659:
660: GetModuleFileName (NULL, szHelpFile, sizeof (szHelpFile));
661: lpszTmp = strrchr (szHelpFile, '\\');
662: if (lpszTmp)
663: {
664: strcpy (++lpszTmp, "TrueCrypt User Guide.pdf");
665: }
666:
667: hMutex = CreateMutex (NULL, TRUE, lpszTitle);
668: if (hMutex == NULL)
669: {
670: handleWin32Error (NULL);
671: AbortProcess (IDS_INIT_MUTEX);
672: }
673:
674: if (GetLastError ()== ERROR_ALREADY_EXISTS)
675: {
676: // If executed twice, just top the first instance and exit
677: HWND h = FindWindow (0, lpszTitle);
678: if (h != 0)
679: {
680: ShowWindow (h, SW_SHOWNORMAL);
681: SetForegroundWindow (h);
682: exit (1);
683: }
684: else
685: AbortProcess (IDS_TWO_INSTANCES);
686: }
687:
688: #ifndef SETUP
689: /* Setup the service if it's not present */
690: if (CheckService ()== FALSE)
691: AbortProcess (IDS_NOSERVICE);
692: #endif
693:
694: }
695:
696: BOOL
697: InstallService (SC_HANDLE schSCManager, char *SZSERVICENAME, char *SZSERVICEDISPLAYNAME)
698: {
699: SC_HANDLE schService;
700:
701: schService = CreateService (
702: schSCManager, /* SCManager database */
703: SZSERVICENAME, /* name of service */
704: SZSERVICEDISPLAYNAME, /* name to display */
705: SERVICE_ALL_ACCESS, /* desired access */
706: SERVICE_WIN32_OWN_PROCESS, /* service type */
707: SERVICE_AUTO_START, /* start type */
708: SERVICE_ERROR_NORMAL, /* error control type */
709: "TrueCryptService.exe", /* service's binary */
710: NULL, /* no load ordering
711: group */
712: NULL, /* no tag identifier */
713: "", /* dependencies */
714: NULL, /* LocalSystem account */
715: NULL); /* no password */
716:
717: if (schService != NULL)
718: {
719: CloseServiceHandle (schService);
720: return TRUE;
721: }
722:
723: return FALSE;
724: }
725:
726: BOOL
727: CheckService ()
728: {
729:
730: SC_HANDLE schService = NULL;
731: SC_HANDLE schSCManager = NULL;
732: BOOL bInstall = FALSE;
733: BOOL bAdmin = TRUE;
734: BOOL bResult = TRUE;
735:
736: if (nCurrentOS != WIN_NT)
737: return TRUE;
738:
739: schSCManager = OpenSCManager (
740: NULL, /* machine (NULL ==
741: local) */
742: NULL, /* database (NULL ==
743: default) */
744: SC_MANAGER_ALL_ACCESS /* access required */
745: );
746:
747: if (schSCManager == NULL)
748: {
749: schSCManager = OpenSCManager (
750: NULL, /* machine (NULL ==
751: local) */
752: NULL, /* database (NULL ==
753: default) */
754: SC_MANAGER_CONNECT | SC_MANAGER_ENUMERATE_SERVICE | SC_MANAGER_QUERY_LOCK_STATUS /* access required */
755: );
756:
757: bAdmin = FALSE;
758: }
759:
760: if (schSCManager == NULL)
761: goto error;
762:
763: if (bAdmin == TRUE)
764: schService = OpenService (schSCManager, "TrueCryptService", SERVICE_ALL_ACCESS);
765: else
766: schService = OpenService (schSCManager, "TrueCryptService", SERVICE_QUERY_STATUS);
767:
768: if (schService == NULL)
769: {
770: BOOL bOK;
771:
772: if (bAdmin == FALSE)
773: {
774: handleWin32Error (NULL);
775: CloseServiceHandle (schSCManager);
776: #ifndef SETUP
777: AbortProcess (IDS_NOSERVICE);
778: #else
779: return FALSE;
780: #endif
781: }
782:
783: if (bInstall == TRUE)
784: goto error;
785:
786: bInstall = TRUE;
787:
788: bOK = InstallService (schSCManager, "TrueCryptService", "TrueCrypt Service");
789:
790: if (bOK == FALSE)
791: goto error;
792:
793: schService = OpenService (schSCManager, "TrueCryptService", SERVICE_ALL_ACCESS);
794: }
795:
796: if (schService != NULL)
797: {
798: SERVICE_STATUS status;
799: BOOL bOK;
800: int i;
801:
802: bOK = QueryServiceStatus (schService, &status);
803:
804: if (bOK == FALSE)
805: goto error;
806:
807: if (status.dwCurrentState == SERVICE_RUNNING || status.dwCurrentState == SERVICE_START_PENDING)
808: goto success;
809:
810: if (bAdmin == FALSE)
811: {
812: CloseServiceHandle (schService);
813: CloseServiceHandle (schSCManager);
814: #ifndef SETUP
815: AbortProcess (IDS_SERVICE_NOT_RUNNING);
816: #else
817: return FALSE;
818: #endif
819:
820: }
821:
822: bOK = StartService (schService, 0, NULL);
823:
824: if (bOK == FALSE)
825: goto error;
826:
827: #define WAIT_PERIOD 3
828:
829: for (i = 0; i < WAIT_PERIOD; i++)
830: {
831: Sleep (1000);
832: bOK = QueryServiceStatus (schService, &status);
833:
834: if (bOK == FALSE)
835: goto error;
836:
837:
838: if (status.dwCurrentState == SERVICE_RUNNING)
839: break;
840: }
841:
842: if (i == WAIT_PERIOD)
843: bOK = FALSE;
844:
845: if (bOK == FALSE)
846: goto error;
847: else
848: goto success;
849: }
850:
851:
852: error:
853: if (GetLastError ()!= 0)
854: handleWin32Error (NULL);
855:
856: bResult = FALSE;
857:
858: success:
859: if (schService != NULL)
860: CloseServiceHandle (schService);
861:
862: if (schSCManager != NULL)
863: CloseServiceHandle (schSCManager);
864:
865: return bResult;
866: }
867:
868: BOOL
869: OpenDevice (char *lpszPath, OPEN_TEST_STRUCT * driver)
870: {
871: DWORD dwResult;
872: BOOL bResult;
873:
874: strcpy ((char *) &driver->wszFileName[0], lpszPath);
875:
876: if (nCurrentOS == WIN_NT)
877: ToUNICODE ((char *) &driver->wszFileName[0]);
878:
879: bResult = DeviceIoControl (hDriver, OPEN_TEST,
880: driver, sizeof (OPEN_TEST_STRUCT),
881: &driver, sizeof (OPEN_TEST_STRUCT),
882: &dwResult, NULL);
883:
884: if (bResult == FALSE)
885: {
886: dwResult = GetLastError ();
887: if (dwResult == ERROR_SHARING_VIOLATION)
888: return TRUE;
889: else
890: return FALSE;
891: }
892: else
893: {
894: if (nCurrentOS == WIN_NT)
895: return TRUE;
896: else if (driver->nReturnCode == 0)
897: return TRUE;
898: else
899: {
900: SetLastError (ERROR_FILE_NOT_FOUND);
901: return FALSE;
902: }
903: }
904: }
905:
906: UINT _stdcall
907: win9x_io (HFILE hFile, char *lpBuffer, UINT uBytes)
908: {
909: DISKIO_STRUCT *win9x_r0 = (DISKIO_STRUCT *) hFile;
910: DWORD dwResult;
911: BOOL bResult;
912: LONG secs;
913:
914: win9x_r0->bufferad = (void *) lpBuffer;
915:
916: secs = uBytes / SECTOR_SIZE;
917:
918: win9x_r0->sectorlen = secs;
919:
920: bResult = DeviceIoControl (hDriver, DISKIO, win9x_r0, sizeof (DISKIO_STRUCT), win9x_r0,
921: sizeof (DISKIO_STRUCT), &dwResult, NULL);
922:
923: if (bResult == FALSE || win9x_r0->nReturnCode != 0)
924: return (UINT) HFILE_ERROR;
925:
926: win9x_r0->sectorstart += secs;
927:
928: return uBytes;
929: }
930:
931: int
932: GetAvailableFixedDisks (HWND hComboBox, char *lpszRootPath)
933: {
934: int i, n;
935: int line = 0;
936:
937: for (i = 0; i < 64; i++)
938: {
939: BOOL drivePresent = FALSE;
940:
941: for (n = 1; n <= 32; n++)
942: {
943: char szTmp[TC_MAX_PATH], item1[100]={0}, item2[100]={0};
944: OPEN_TEST_STRUCT driver;
945:
946: sprintf (szTmp, lpszRootPath, i, n);
947: if (OpenDevice (szTmp, &driver) == TRUE)
948: {
949: int nDosLinkCreated;
950: HANDLE dev;
951: DWORD dwResult;
952: BOOL bResult;
953: PARTITION_INFORMATION diskInfo;
954:
955: LVITEM LvItem;
956:
957: char szDosDevice[TC_MAX_PATH], szCFDevice[TC_MAX_PATH];
958:
959: if(!drivePresent)
960: {
961: LVITEM LvItem;
962: memset(&LvItem,0,sizeof(LvItem));
963: LvItem.mask=LVIF_TEXT;
964: LvItem.iItem= line++;
965:
966: sprintf(szDosDevice, " Harddisk %d:", i);
967: LvItem.pszText = szDosDevice;
968: SendMessage(hComboBox, LVM_INSERTITEM, 0, (LPARAM)&LvItem);
969: }
970: drivePresent = TRUE;
971:
972: if (nCurrentOS == WIN_NT)
973: {
974: nDosLinkCreated = FakeDosNameForDevice (szTmp, szDosDevice,
975: szCFDevice, FALSE);
976:
977: dev = CreateFile (szCFDevice, GENERIC_READ, FILE_SHARE_WRITE , NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
978:
979: bResult = DeviceIoControl (dev, IOCTL_DISK_GET_PARTITION_INFO, NULL, 0,
980: &diskInfo, sizeof (diskInfo), &dwResult, NULL);
981:
982: RemoveFakeDosName(szTmp, szDosDevice);
983: CloseHandle(dev);
984:
985: if (bResult == TRUE)
986: {
987: char partType[100];
988:
989: switch(diskInfo.PartitionType)
990: {
991: case PARTITION_ENTRY_UNUSED: strcpy(partType, "Empty"); break;
992: case PARTITION_EXTENDED: strcpy(partType, "Extended"); break;
993: case PARTITION_HUGE: strcpy(partType, "FAT"); break;
994: case PARTITION_FAT_12: strcpy(partType, "FAT12"); break;
995: case PARTITION_FAT_16: strcpy(partType, "FAT16"); break;
996: case PARTITION_FAT32:
997: case PARTITION_FAT32_XINT13: strcpy(partType, "FAT32"); break;
998: case 0x11:
999: case 0x14:
1000: case 0x16:
1001: case 0x1b:
1002: case 0x1c:
1003: case 0x1e: strcpy(partType, "Hidden FAT"); break;
1004: case PARTITION_IFS: strcpy(partType, "NTFS"); break;
1005: case 0x17: strcpy(partType, "Hidden NTFS"); break;
1006: case PARTITION_LDM: strcpy(partType, "LDM"); break;
1007: case PARTITION_UNIX: strcpy(partType, "UNIX"); break;
1008: case 0x83: strcpy(partType, "Linux"); break;
1009: case 0x82: strcpy(partType, "Linux Swap"); break;
1010:
1011: default: sprintf(partType, "Unknown (0x%02x)", diskInfo.PartitionType); break;
1012: }
1013:
1014: if(diskInfo.PartitionLength.QuadPart > 1024I64*1024*1024)
1015: sprintf (item1,"%.1f GB",(double)(diskInfo.PartitionLength.QuadPart/1024.0/1024/1024));
1016: else
1017: sprintf (item1,"%d MB", diskInfo.PartitionLength.QuadPart/1024/1024);
1018:
1019: strcpy (item2, partType);
1020: }
1021: }
1022:
1023: memset(&LvItem,0,sizeof(LvItem));
1024: LvItem.mask=LVIF_TEXT;
1025: LvItem.iItem= line++;
1026:
1027: LvItem.pszText=szTmp;
1028: SendMessage(hComboBox,LVM_INSERTITEM,0,(LPARAM)&LvItem);
1029:
1030: LvItem.iSubItem=1;
1031: LvItem.pszText=item1;
1032: SendMessage(hComboBox,LVM_SETITEM,0,(LPARAM)&LvItem);
1033:
1034: LvItem.iSubItem=2;
1035: LvItem.pszText=item2;
1036: SendMessage(hComboBox,LVM_SETITEM,0,(LPARAM)&LvItem);
1037: }
1038: else
1039: {
1040: if(drivePresent)
1041: {
1042: LVITEM LvItem;
1043: memset(&LvItem,0,sizeof(LvItem));
1044: LvItem.mask=LVIF_TEXT;
1045: LvItem.iItem= line++;
1046:
1047: LvItem.pszText="";
1048: SendMessage(hComboBox,LVM_INSERTITEM,0,(LPARAM)&LvItem);
1049: }
1050:
1051: if (n == 1)
1052: i = 64;
1053: break;
1054: }
1055: }
1056: }
1057:
1058: i = SendMessage (hComboBox, LVM_GETITEMCOUNT, 0, 0);
1059: if (i != CB_ERR)
1060: return i;
1061: else
1062: return 0;
1063: }
1064:
1065: int
1066: GetAvailableRemovables (HWND hComboBox, char *lpszRootPath)
1067: {
1068: char szTmp[TC_MAX_PATH];
1069: int i;
1070: LVITEM LvItem;
1071:
1072: if (lpszRootPath); /* Remove unused parameter warning */
1073:
1074: if (nCurrentOS != WIN_NT)
1075: return 0;
1076:
1077: memset(&LvItem,0,sizeof(LvItem));
1078: LvItem.mask = LVIF_TEXT;
1079: LvItem.iItem = SendMessage (hComboBox, LVM_GETITEMCOUNT, 0, 0)+1;
1080:
1081: if (QueryDosDevice ("A:", szTmp, sizeof (szTmp)) != 0)
1082: {
1083: LvItem.pszText="Floppy (A:)";
1084: SendMessage(hComboBox,LVM_INSERTITEM,0,(LPARAM)&LvItem);
1085: }
1086: if (QueryDosDevice ("B:", szTmp, sizeof (szTmp)) != 0)
1087: {
1088: LvItem.pszText="Floppy (B:)";
1089: SendMessage(hComboBox,LVM_INSERTITEM,0,(LPARAM)&LvItem);
1090: }
1091:
1092: i = SendMessage (hComboBox, LVM_GETITEMCOUNT, 0, 0);
1093: if (i != CB_ERR)
1094: return i;
1095: else
1096: return 0;
1097: }
1098:
1099: BOOL WINAPI
1100: RawDevicesDlgProc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
1101: {
1102: static char *lpszFileName;
1103: WORD lw = LOWORD (wParam);
1104:
1105: if (lParam); /* remove warning */
1106:
1107: switch (msg)
1108: {
1109: case WM_INITDIALOG:
1110: {
1111: int nCount;
1112: LVCOLUMN LvCol;
1113: HWND hList = GetDlgItem (hwndDlg, IDC_DEVICELIST);
1114:
1115: SetDefaultUserFont (hwndDlg);
1116:
1117: SendMessage(hList,LVM_SETEXTENDEDLISTVIEWSTYLE,0,
1118: LVS_EX_FULLROWSELECT|LVS_EX_HEADERDRAGDROP|LVS_EX_TWOCLICKACTIVATE
1119: );
1120:
1121: memset(&LvCol,0,sizeof(LvCol));
1122: LvCol.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM|LVCF_FMT;
1123: LvCol.pszText = "Device";
1124: LvCol.cx =160;
1125: LvCol.fmt = LVCFMT_LEFT;
1126: SendMessage(hList,LVM_INSERTCOLUMN,0,(LPARAM)&LvCol);
1127:
1128: LvCol.pszText = "Size";
1129: LvCol.cx = 64;
1130: LvCol.fmt = LVCFMT_RIGHT;
1131: SendMessage(hList,LVM_INSERTCOLUMN,1,(LPARAM)&LvCol);
1132:
1133: LvCol.pszText = "Type";
1134: LvCol.cx = 92;
1135: LvCol.fmt = LVCFMT_LEFT;
1136: SendMessage(hList,LVM_INSERTCOLUMN,2,(LPARAM)&LvCol);
1137:
1138: nCount = GetAvailableFixedDisks (hList, "\\Device\\Harddisk%d\\Partition%d");
1139: nCount += GetAvailableRemovables (hList, "\\Device\\Floppy%d");
1140:
1141: if (nCount == 0)
1142: {
1143: handleWin32Error (hwndDlg);
1144: MessageBox (hwndDlg, getstr (IDS_RAWDEVICES), lpszTitle, ICON_HAND);
1145: EndDialog (hwndDlg, IDCANCEL);
1146: }
1147:
1148: lpszFileName = (char *) lParam;
1149: return 1;
1150: }
1151:
1152: case WM_COMMAND:
1153: case WM_NOTIFY:
1154:
1155: // catch non-device line selected
1156: if (msg == WM_NOTIFY && ((LPNMHDR) lParam)->code == LVN_ITEMCHANGED && (((LPNMLISTVIEW) lParam)->uNewState & LVIS_FOCUSED ))
1157: {
1158: LVITEM LvItem;
1159: memset(&LvItem,0,sizeof(LvItem));
1160: LvItem.mask = LVIF_TEXT;
1161: LvItem.iItem = ((LPNMLISTVIEW) lParam)->iItem;
1162: LvItem.pszText = lpszFileName;
1163: LvItem.cchTextMax = TC_MAX_PATH;
1164:
1165: SendMessage (GetDlgItem (hwndDlg, IDC_DEVICELIST), LVM_GETITEMTEXT, LvItem.iItem, (LPARAM) &LvItem);
1166: EnableWindow (GetDlgItem ((HWND) hwndDlg, IDOK), lpszFileName[0] != 0 && lpszFileName[0] != ' ');
1167: return 1;
1168: }
1169:
1170: if (msg == WM_COMMAND && lw == IDOK || msg == WM_NOTIFY && ((NMHDR *)lParam)->code == LVN_ITEMACTIVATE)
1171: {
1172: LVITEM LvItem;
1173: memset(&LvItem,0,sizeof(LvItem));
1174: LvItem.mask = LVIF_TEXT;
1175: LvItem.iItem = SendMessage (GetDlgItem (hwndDlg, IDC_DEVICELIST), LVM_GETSELECTIONMARK, 0, 0);
1176: LvItem.pszText = lpszFileName;
1177: LvItem.cchTextMax = TC_MAX_PATH;
1178:
1179: SendMessage (GetDlgItem (hwndDlg, IDC_DEVICELIST), LVM_GETITEMTEXT, LvItem.iItem, (LPARAM) &LvItem);
1180:
1181: if(lpszFileName[0]==0 || lpszFileName[0]==' ')
1182: break; // non-device line selected
1183:
1184: EndDialog (hwndDlg, IDOK);
1185: return 0;
1186: }
1187:
1188: if (lw == IDCANCEL)
1189: {
1190: EndDialog (hwndDlg, IDCANCEL);
1191: return 0;
1192: }
1193: return 0;
1194: }
1195:
1196: return 0;
1197: }
1198:
1199: int
1200: DriverAttach (void)
1201: {
1202: /* Try to open a handle to the device driver. It will be closed
1203: later. */
1204:
1205: if (nCurrentOS == WIN_NT)
1206: hDriver = CreateFile (WIN32_ROOT_PREFIX, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
1207: else
1208: hDriver = CreateFile (WIN9X_DRIVER_NAME, 0, 0, NULL, OPEN_EXISTING, 0, NULL);
1209:
1210: if (hDriver == INVALID_HANDLE_VALUE)
1211: {
1212: return ERR_OS_ERROR;
1213: }
1214: #ifndef SETUP // Don't check version during setup to allow removal of older version
1215: else
1216: {
1217: LONG driver = 0;
1218: DWORD dwResult;
1219:
1220: BOOL bResult = DeviceIoControl (hDriver, DRIVER_VERSION,
1221: &driver, 4, &driver, 4, &dwResult, NULL);
1222:
1223: if (bResult == FALSE)
1224: return ERR_OS_ERROR;
1225: else if (driver != VERSION_NUM)
1226: return ERR_DRIVER_VERSION;
1227: }
1228: #endif
1229:
1230: if (nCurrentOS == WIN_98)
1231: {
1232: DWORD dwResult;
1233: DeviceIoControl (hDriver, ALLOW_FAST_SHUTDOWN, NULL, 0, NULL, 0, &dwResult, NULL);
1234: }
1235:
1236: return 0;
1237: }
1238:
1239: BOOL
1240: BrowseFiles (HWND hwndDlg, UINT nTitleID, char *lpszFileName)
1241: {
1242: OPENFILENAME ofn;
1243: char szFileTitle[TC_MAX_PATH];
1244: ZeroMemory (&ofn, sizeof (OPENFILENAME));
1245:
1246: *szFileTitle = *lpszFileName = 0;
1247: ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; //sizeof (OPENFILENAME);
1248: ofn.hwndOwner = hwndDlg;
1249: ofn.lpstrFilter = "All Files (*.*)\0*.*\0TrueCrypt Volumes (*.tc)\0*.tc\0";
1250: ofn.lpstrCustomFilter = NULL;
1251: ofn.nFilterIndex = 1;
1252: ofn.lpstrFile = lpszFileName;
1253: ofn.nMaxFile = TC_MAX_PATH;
1254: ofn.lpstrFileTitle = szFileTitle;
1255: ofn.nMaxFileTitle = TC_MAX_PATH;
1256: ofn.lpstrInitialDir = NULL;
1257: ofn.lpstrTitle = getstr (nTitleID);
1258: ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
1259: //ofn.lpstrDefExt = "tc";
1260:
1261: if (!GetOpenFileName (&ofn))
1262: return FALSE;
1263: else
1264: return TRUE;
1265: }
1266:
1267:
1268: void
1269: handleError (HWND hwndDlg, int code)
1270: {
1271: char szTmp[512];
1272:
1273: switch (code)
1274: {
1275: case ERR_OS_ERROR:
1276: handleWin32Error (hwndDlg);
1277: break;
1278: case ERR_OUTOFMEMORY:
1279: MessageBox (hwndDlg, getstr (IDS_OUTOFMEMORY), lpszTitle, ICON_HAND);
1280: break;
1281: case ERR_PASSWORD_WRONG:
1282: MessageBox (hwndDlg, getstr (IDS_PASSWORD_WRONG), lpszTitle, MB_ICONEXCLAMATION);
1283: break;
1284: case ERR_VOL_FORMAT_BAD:
1285: MessageBox (hwndDlg, getstr (IDS_VOL_FORMAT_BAD), lpszTitle, ICON_HAND);
1286: break;
1287: case ERR_BAD_DRIVE_LETTER:
1288: MessageBox (hwndDlg, getstr (IDS_BAD_DRIVE_LETTER), lpszTitle, ICON_HAND);
1289: break;
1290: case ERR_DRIVE_NOT_FOUND:
1291: MessageBox (hwndDlg, getstr (IDS_NOT_FOUND), lpszTitle, ICON_HAND);
1292: break;
1293: case ERR_FILES_OPEN:
1294: MessageBox (hwndDlg, getstr (IDS_OPENFILES_DRIVER), lpszTitle, ICON_HAND);
1295: break;
1296: case ERR_FILES_OPEN_LOCK:
1297: MessageBox (hwndDlg, getstr (IDS_OPENFILES_LOCK), lpszTitle, ICON_HAND);
1298: break;
1299: case ERR_VOL_SIZE_WRONG:
1300: MessageBox (hwndDlg, getstr (IDS_VOL_SIZE_WRONG), lpszTitle, ICON_HAND);
1301: break;
1302: case ERR_COMPRESSION_NOT_SUPPORTED:
1303: MessageBox (hwndDlg, getstr (IDS_COMPRESSION_NOT_SUPPORTED), lpszTitle, ICON_HAND);
1304: break;
1305: case ERR_PASSWORD_CHANGE_VOL_TYPE:
1306: MessageBox (hwndDlg, getstr (IDS_WRONG_VOL_TYPE), lpszTitle, ICON_HAND);
1307: break;
1308: case ERR_PASSWORD_CHANGE_VOL_VERSION:
1309: MessageBox (hwndDlg, getstr (IDS_WRONG_VOL_VERSION), lpszTitle, ICON_HAND);
1310: break;
1311: case ERR_VOL_SEEKING:
1312: MessageBox (hwndDlg, getstr (IDS_VOL_SEEKING), lpszTitle, ICON_HAND);
1313: break;
1314: case ERR_VOL_WRITING:
1315: MessageBox (hwndDlg, getstr (IDS_VOL_WRITING), lpszTitle, ICON_HAND);
1316: break;
1317: case ERR_VOL_READING:
1318: MessageBox (hwndDlg, getstr (IDS_VOL_READING), lpszTitle, ICON_HAND);
1319: break;
1320: case ERR_VOL_ALREADY_MOUNTED:
1321: MessageBox (hwndDlg, getstr (IDS_VOL_ALREADY_MOUNTED), lpszTitle, ICON_HAND);
1322: break;
1323: case ERR_FILE_OPEN_FAILED:
1324: MessageBox (hwndDlg, getstr (IDS_FILE_OPEN_FAILED), lpszTitle, ICON_HAND);
1325: break;
1326: case ERR_VOL_MOUNT_FAILED:
1327: MessageBox (hwndDlg, getstr (IDS_VOL_MOUNT_FAILED), lpszTitle, MB_ICONEXCLAMATION);
1328: break;
1329: case ERR_NO_FREE_SLOTS:
1330: MessageBox (hwndDlg, getstr (IDS_NO_FREE_SLOTS), lpszTitle, ICON_HAND);
1331: break;
1332: case ERR_NO_FREE_DRIVES:
1333: MessageBox (hwndDlg, getstr (IDS_NO_FREE_DRIVES), lpszTitle, ICON_HAND);
1334: break;
1335: case ERR_INVALID_DEVICE:
1336: MessageBox (hwndDlg, getstr (IDS_INVALID_DEVICE), lpszTitle, ICON_HAND);
1337: break;
1338: case ERR_ACCESS_DENIED:
1339: MessageBox (hwndDlg, getstr (IDS_ACCESS_DENIED), lpszTitle, ICON_HAND);
1340: break;
1341:
1342: case ERR_DRIVER_VERSION:
1343: sprintf (szTmp, getstr (IDS_DRIVER_VERSION), VERSION_STRING);
1344: MessageBox (hwndDlg, szTmp, lpszTitle, ICON_HAND);
1345: break;
1346:
1347: case ERR_NEW_VERSION_REQUIRED:
1348: MessageBox (hwndDlg, getstr (IDS_NEW_VERSION_REQUIRED), lpszTitle, ICON_HAND);
1349: break;
1350:
1351: default:
1352: sprintf (szTmp, getstr (IDS_UNKNOWN), code);
1353: MessageBox (hwndDlg, szTmp, lpszTitle, ICON_HAND);
1354:
1355: }
1356: }
1357:
1358: static BOOL CALLBACK SetDefaultUserFontEnum( HWND hwnd, LPARAM font)
1359: {
1360: SendMessage (hwnd, WM_SETFONT, (WPARAM) font, 0);
1361: return TRUE;
1362: }
1363:
1364: void SetDefaultUserFont (HWND hwnd)
1365: {
1366: NONCLIENTMETRICS metric;
1367:
1368: if (hUserFont == 0)
1369: {
1370: metric.cbSize = sizeof (NONCLIENTMETRICS);
1371: SystemParametersInfo (SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &metric, 0);
1372:
1373: hUserFont = CreateFontIndirect (&metric.lfMessageFont);
1374:
1375: metric.lfMessageFont.lfUnderline = TRUE;
1376: hUserUnderlineFont = CreateFontIndirect (&metric.lfMessageFont);
1377:
1378: metric.lfMessageFont.lfUnderline = FALSE;
1379: metric.lfMessageFont.lfWeight = FW_BOLD;
1380: hUserBoldFont = CreateFontIndirect (&metric.lfMessageFont);
1381: }
1382:
1383: EnumChildWindows (hwnd, SetDefaultUserFontEnum, (LPARAM) hUserFont);
1384: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.