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