Update Turkish translation
[dasher.git] / Src / Win32 / Common / WinHelper.cpp
blob4eb3cddee4a2d7a089be9e02c5765c0ea3957bb0
1 // WinHelper.cpp
2 //
3 /////////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (c) 2002 Iain Murray, Inference Group, Cavendish, Cambridge.
6 //
7 /////////////////////////////////////////////////////////////////////////////
9 #include "WinCommon.h"
11 // Track memory leaks on Windows to the line that new'd the memory
12 #ifdef _WIN32
13 #ifdef _DEBUG
14 #define DEBUG_NEW new( _NORMAL_BLOCK, THIS_FILE, __LINE__ )
15 #define new DEBUG_NEW
16 #undef THIS_FILE
17 static char THIS_FILE[] = __FILE__;
18 #endif
19 #endif
21 namespace WinHelper {
22 HINSTANCE hInstApp;
23 } void WinHelper::LastWindowsError() {
24 LPVOID lpMsgBuf;
25 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
26 (LPTSTR) & lpMsgBuf, 0, NULL);
27 MessageBox(NULL, (LPCTSTR) lpMsgBuf, TEXT("Error"), MB_OK | MB_ICONINFORMATION);
28 LocalFree(lpMsgBuf);
31 namespace {
32 bool CommonControlsInited = false;
35 void WinHelper::InitCommonControlLib() {
36 if(CommonControlsInited)
37 return;
39 INITCOMMONCONTROLSEX iccex;
40 iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);
41 iccex.dwICC = ICC_BAR_CLASSES | ICC_COOL_CLASSES;
42 InitCommonControlsEx(&iccex);
43 CommonControlsInited = true;
46 namespace {
47 // For SHGetSpecialFolderPath.
48 #include "shlobj.h"
51 void WinHelper::GetUserDirectory(Tstring *Output) {
52 Tstring & UserData = *Output;
53 TCHAR Buffer[MAX_PATH];
54 // My documentation says SHGetSpecialFolderPath returns NOERROR if successful
55 // With my headers NOERROR==0 and this function returns TRUE==1 as docs online say.
56 // Not sure I trust the return value, so I'm just going to assume if I have a string
57 // it is probably correct :)
58 Buffer[0] = TEXT('\0');
59 SHGetSpecialFolderPath(NULL, Buffer, CSIDL_APPDATA, 0);
60 UserData = Buffer;
61 if(UserData[UserData.size() - 1] != TEXT('\\'))
62 UserData += TEXT('\\');
65 void WinHelper::GetAppDirectory(Tstring *Output) {
66 Tstring & AppLocation = *Output;
68 TCHAR Buffer[MAX_PATH];
69 if(0 != GetModuleFileName(NULL, Buffer, MAX_PATH)) {
70 TCHAR *pos = _tcsrchr(Buffer, TEXT('\\')); // 3 line hack to remove filename
71 pos++; //
72 *pos = TEXT('\0'); //
73 AppLocation = Buffer;
75 else
76 AppLocation = TEXT(""); // Cop out. Current directory may be elsewhere.
77 // Hopefully it won't come to this...