3 /////////////////////////////////////////////////////////////////////////////
5 // Copyright (c) 2002 Iain Murray, Inference Group, Cavendish, Cambridge.
7 /////////////////////////////////////////////////////////////////////////////
11 #include "WinHelper.h"
13 // Track memory leaks on Windows to the line that new'd the memory
16 #define DEBUG_NEW new( _NORMAL_BLOCK, THIS_FILE, __LINE__ )
19 static char THIS_FILE
[] = __FILE__
;
25 } void WinHelper::LastWindowsError() {
27 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS
, NULL
, GetLastError(), MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), // Default language
28 (LPTSTR
) & lpMsgBuf
, 0, NULL
);
29 MessageBox(NULL
, (LPCTSTR
) lpMsgBuf
, TEXT("Error"), MB_OK
| MB_ICONINFORMATION
);
34 bool CommonControlsInited
= false;
37 void WinHelper::InitCommonControlLib() {
38 if(CommonControlsInited
)
44 INITCOMMONCONTROLSEX iccex
;
45 iccex
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
46 iccex
.dwICC
= ICC_BAR_CLASSES
| ICC_COOL_CLASSES
;
47 InitCommonControlsEx(&iccex
);
50 CommonControlsInited
= true;
55 // For SHGetSpecialFolderPath. Needs IE 4.0 or above (Win98+ always ok).
60 void WinHelper::GetUserDirectory(Tstring
*Output
) {
61 Tstring
& UserData
= *Output
;
64 // Not a lot else I can do :(
65 GetAppDirectory(Output
);
66 #elif defined DASHER_WINCE
67 GetAppDirectory(Output
);
70 TCHAR Buffer
[MAX_PATH
];
71 // My documentation says SHGetSpecialFolderPath returns NOERROR if successful
72 // With my headers NOERROR==0 and this function returns TRUE==1 as docs online say.
73 // Not sure I trust the return value, so I'm just going to assume if I have a string
74 // it is probably correct :)
75 Buffer
[0] = TEXT('\0');
76 SHGetSpecialFolderPath(NULL
, Buffer
, CSIDL_APPDATA
, 0);
78 if(UserData
[UserData
.size() - 1] != TEXT('\\'))
79 UserData
+= TEXT('\\');
85 void WinHelper::GetAppDirectory(Tstring
*Output
) {
86 Tstring
& AppLocation
= *Output
;
88 TCHAR Buffer
[MAX_PATH
];
89 if(0 != GetModuleFileName(NULL
, Buffer
, MAX_PATH
)) {
90 TCHAR
*pos
= _tcsrchr(Buffer
, TEXT('\\')); // 3 line hack to remove filename
96 AppLocation
= TEXT(""); // Cop out. Current directory may be elsewhere.
97 // Hopefully it won't come to this...