1 /** DGui project file. 2 3 Copyright: Trogu Antonio Davide 2011-2013 4 5 License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0). 6 7 Authors: Trogu Antonio Davide 8 */ 9 10 /* ANSI <-> UNICODE bridge module */ 11 12 module dguihub.core.charset; 13 14 import std.conv : to; 15 public import std.utf : toUTFz; 16 import dguihub.core.winapi; 17 import dguihub.core.utils; 18 19 /** 20 * $(B) Unicode Wrapper of CreateWindowEx API $(B) 21 */ 22 public HWND createWindowEx(DWORD exStyle, string className, string windowName, 23 DWORD style, int x, int y, int nWidth, int nHeight, HWND hWndParent, LPVOID lpParam) { 24 return CreateWindowExW(exStyle, toUTFz!(wchar*)(className), 25 toUTFz!(wchar*)(windowName), style, x, y, nWidth, nHeight, hWndParent, 26 null, getHInstance(), lpParam); 27 } 28 29 public BOOL getClassInfoEx(string className, WNDCLASSEXW* pWndClassEx) { 30 return GetClassInfoExW(getHInstance(), toUTFz!(wchar*)(className), pWndClassEx); 31 } 32 33 public string getModuleFileName(HMODULE hModule) { 34 wchar[MAX_PATH + 1] path = void; 35 36 int len = GetModuleFileNameW(hModule, path.ptr, path.length); 37 return to!(string)(path[0 .. len]); 38 } 39 40 public HICON extractAssociatedIcon(string s, WORD* pIcon) { 41 return ExtractAssociatedIconW(getHInstance(), toUTFz!(wchar*)(s), pIcon); 42 } 43 44 public HANDLE loadImage(HINSTANCE hInstance, string s, UINT uType, int cxDesired, 45 int cyDesired, UINT fuLoad) { 46 return LoadImageW(hInstance, toUTFz!(wchar*)(s), uType, cxDesired, cyDesired, fuLoad); 47 } 48 49 public HANDLE loadImage(HINSTANCE hInstance, wchar* pResID, UINT uType, 50 int cxDesired, int cyDesired, UINT fuLoad) { 51 return LoadImageW(hInstance, pResID, uType, cxDesired, cyDesired, fuLoad); 52 } 53 54 public int drawTextEx(HDC hdc, string s, RECT* lprc, UINT dwDTFormat, DRAWTEXTPARAMS* lpDTParams) { 55 return DrawTextExW(hdc, toUTFz!(wchar*)(s), -1, lprc, dwDTFormat, lpDTParams); 56 } 57 58 public HMODULE loadLibrary(string s) { 59 return LoadLibraryW(toUTFz!(wchar*)(s)); 60 } 61 62 public HMODULE getModuleHandle(string s) { 63 return GetModuleHandleW(toUTFz!(wchar*)(s)); 64 } 65 66 public void getTempPath(ref string s) { 67 wchar[MAX_PATH + 1] path = void; 68 69 int len = GetTempPathW(MAX_PATH, path.ptr); 70 s = to!(string)(path[0 .. len]); 71 } 72 73 public int getWindowTextLength(HWND hWnd) { 74 return GetWindowTextLengthW(hWnd); 75 } 76 77 public string getWindowText(HWND hWnd) { 78 int len = getWindowTextLength(hWnd); 79 80 if (!len) { 81 return null; 82 } 83 84 len++; 85 86 wchar[] t = new wchar[len]; 87 len = GetWindowTextW(hWnd, t.ptr, len); 88 return to!(string)(t[0 .. len]); 89 } 90 91 public BOOL setWindowText(HWND hWnd, string s) { 92 return SetWindowTextW(hWnd, toUTFz!(wchar*)(s)); 93 } 94 95 public HFONT createFontIndirect(LOGFONTW* lf) { 96 return CreateFontIndirectW(lf); 97 } 98 99 public HFONT createFontIndirect(string s, LOGFONTW* lf) { 100 if (s.length >= LF_FACESIZE) { 101 s = s[0 .. LF_FACESIZE - 1]; 102 } 103 104 wstring ws = to!(wstring)(s); 105 106 foreach (int i, wchar wch; ws) { 107 lf.lfFaceName[i] = wch; 108 } 109 110 lf.lfFaceName[ws.length] = '\0'; 111 112 return CreateFontIndirectW(lf); 113 } 114 115 public DWORD getClassLong(HWND hWnd, int nIndex) { 116 return GetClassLongW(hWnd, nIndex); 117 } 118 119 public DWORD setWindowLong(HWND hWnd, int nIndex, LONG dwNewLong) { 120 return SetWindowLongW(hWnd, nIndex, dwNewLong); 121 } 122 123 public LONG getWindowLong(HWND hWnd, int nIndex) { 124 return GetWindowLongW(hWnd, nIndex); 125 } 126 127 public ATOM registerClassEx(string className, HCURSOR hCursor, HBRUSH hBackground, 128 WNDPROC wndProc, uint style) { 129 WNDCLASSEXW wc; 130 131 wc.cbSize = WNDCLASSEXW.sizeof; 132 wc.lpszClassName = toUTFz!(wchar*)(className); 133 wc.hCursor = hCursor; 134 wc.hInstance = getHInstance(); 135 wc.hbrBackground = hBackground; 136 wc.lpfnWndProc = wndProc; 137 wc.style = style; 138 139 return RegisterClassExW(&wc); 140 } 141 142 public ATOM registerClassEx(WNDCLASSEXW* wc) { 143 return RegisterClassExW(wc); 144 }