1 // winutil.h
2 //
3 // Copyright (C) 2002, Chris Laurel <claurel@shatters.net>
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9
10 #include "winutil.h"
11
SetMouseCursor(LPCTSTR lpCursor)12 void SetMouseCursor(LPCTSTR lpCursor)
13 {
14 HCURSOR hNewCrsr;
15
16 if (hNewCrsr = LoadCursor(NULL, lpCursor))
17 SetCursor(hNewCrsr);
18 }
19
CenterWindow(HWND hParent,HWND hWnd)20 void CenterWindow(HWND hParent, HWND hWnd)
21 {
22 //Center window with hWnd handle relative to hParent.
23 if (hParent && hWnd)
24 {
25 RECT or, ir;
26 if (GetWindowRect(hParent, &or))
27 {
28 if (GetWindowRect(hWnd, &ir))
29 {
30 int x, y;
31
32 x = or.left + (or.right - or.left - (ir.right - ir.left)) / 2;
33 y = or.top + (or.bottom - or.top - (ir.bottom - ir.top)) / 2;;
34 SetWindowPos(hWnd, HWND_TOP, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
35 }
36 }
37 }
38 }
39
RemoveButtonDefaultStyle(HWND hWnd)40 void RemoveButtonDefaultStyle(HWND hWnd)
41 {
42 SetWindowLong(hWnd, GWL_STYLE,
43 ::GetWindowLong(hWnd, GWL_STYLE) & ~BS_DEFPUSHBUTTON);
44 InvalidateRect(hWnd, NULL, TRUE);
45 }
46
AddButtonDefaultStyle(HWND hWnd)47 void AddButtonDefaultStyle(HWND hWnd)
48 {
49 SetWindowLong(hWnd, GWL_STYLE,
50 ::GetWindowLong(hWnd, GWL_STYLE) | BS_DEFPUSHBUTTON);
51 InvalidateRect(hWnd, NULL, TRUE);
52 }
53
CurrentCP()54 const char* CurrentCP()
55 {
56 static bool set = false;
57 static char cp[20] = "CP";
58 if (!set) {
59 GetLocaleInfo(GetThreadLocale(), LOCALE_IDEFAULTANSICODEPAGE, cp+2, 18);
60 set = true;
61 }
62 return cp;
63 }
64
UTF8ToCurrentCP(const string & str)65 string UTF8ToCurrentCP(const string& str)
66 {
67 string localeStr;
68 LPWSTR wout = new wchar_t[str.length() + 1];
69 LPSTR out = new char[str.length() + 1];
70 int wlength = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, wout, str.length() + 1);
71 WideCharToMultiByte(CP_ACP, 0, wout, -1, out, str.length() + 1, NULL, NULL);
72 localeStr = out;
73 delete [] wout;
74 delete [] out;
75 return localeStr;
76 }
77