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 module dgui.core.windowclass; 10 11 import std.utf: toUTFz; 12 import dgui.core.charset; 13 import dgui.core.winapi; 14 import dgui.core.exception; 15 import dgui.core.utils; 16 import dgui.canvas; 17 18 enum 19 { 20 // Windows Classes 21 WC_BUTTON = "Button", 22 WC_COMBOBOXEX = "ComboBoxEx32", 23 WC_LISTBOX = "ListBox", 24 WC_LISTVIEW = "SysListView32", 25 WC_PROGRESSBAR = "msctls_progress32", 26 WC_RICHEDIT = "RichEdit20W", 27 WC_STATUSBAR = "msctls_statusbar32", 28 WC_TABCONTROL = "SysTabControl32", 29 WC_EDIT = "EDIT", 30 WC_TOOLBAR = "ToolBarWindow32", 31 WC_TRACKBAR = "msctls_trackbar32", 32 WC_TOOLTIP = "tooltips_class32", 33 WC_TREEVIEW = "SysTreeView32", 34 //WC_STATIC = "STATIC", 35 36 // DGui Classes 37 WC_DPANEL = "DPanel", 38 WC_FORM = "DForm", 39 WC_DBUTTON = "DButton", 40 WC_DCHECKBOX = "DCheckBox", 41 WC_DRADIOBUTTON = "DRadioButton", 42 WC_DCOMBOBOX = "DComboBox", 43 WC_DLABEL = "DLabel", 44 WC_DLISTBOX = "DListBox", 45 WC_DPICTUREBOX = "DPicturebox", 46 WC_DLISTVIEW = "DListView", 47 WC_DPROGRESSBAR = "DProgressBar", 48 WC_DRICHEDIT = "DRichTextBox", 49 WC_DSTATUSBAR = "DStatusBar", 50 WC_DTABCONTROL = "DTabControl", 51 WC_DEDIT = "DTextBox", 52 WC_DTOOLBAR = "DToolBar", 53 WC_DTRACKBAR = "DTrackBar", 54 WC_DTOOLTIP = "DToolTip", 55 WC_DTREEVIEW = "DTreeView", 56 WC_DGRIDPANEL = "DGridPanel", 57 WC_DSPLITPANEL = "DSplitPanel", 58 } 59 60 enum ClassStyles: uint 61 { 62 none = 0x00000000, 63 vRedraw = 0x00000001, 64 hRedraw = 0x00000002, 65 keyCVTWindow = 0x00000004, 66 doubleClicks = 0x00000008, 67 ownDC = 0x00000020, 68 classDC = 0x00000040, 69 parentDC = 0x00000080, 70 noKeyCVT = 0x00000100, 71 noClose = 0x00000200, 72 saveBits = 0x00000800, 73 byteAlignClient = 0x00001000, 74 byteAlignWindow = 0x00002000, 75 globalClass = 0x00004000, 76 IME = 0x00010000, 77 } 78 79 final class WindowClass 80 { 81 public static void register(string className, ClassStyles classStyle, Cursor cursor, WNDPROC wndProc) 82 { 83 WNDCLASSEXW wc; 84 wc.cbSize = WNDCLASSEXW.sizeof; 85 86 if(!getClassInfoEx(className, &wc)) 87 { 88 if(!registerClassEx(className, cursor ? cursor.handle : SystemCursors.arrow.handle, null, wndProc, classStyle)) 89 { 90 throwException!(Win32Exception)("Windows Class '%s' not created", className); 91 } 92 } 93 } 94 95 public static WNDPROC superclass(string oldClassName, string newClassName, WNDPROC newWndProc) 96 { 97 WNDCLASSEXW oldWc = void, newWc = void; 98 99 oldWc.cbSize = WNDCLASSEXW.sizeof; 100 newWc.cbSize = WNDCLASSEXW.sizeof; 101 102 const(wchar)* pNewClassName = toUTFz!(const(wchar)*)(newClassName); 103 getClassInfoEx(oldClassName, &oldWc); 104 105 if(!getClassInfoEx(newClassName, &newWc)) // IF Class Non Found THEN 106 { 107 newWc = oldWc; 108 newWc.style &= ~ClassStyles.globalClass; // Remove Global Class 109 110 newWc.lpfnWndProc = newWndProc; 111 newWc.lpszClassName = pNewClassName; 112 newWc.hInstance = getHInstance(); 113 //newWc.hbrBackground = null; 114 115 if(!registerClassEx(&newWc)) 116 { 117 throwException!(Win32Exception)("Windows Class '%s' not created", newClassName); 118 } 119 } 120 121 return oldWc.lpfnWndProc; //Back to the original window procedure 122 } 123 }