Type Item_Check EXTENDS Item_Node Declare Sub Destroy() End Type Sub Item_Check.Destroy() ID = "" : Title = "" DestroyWindow(whwnd) whwnd = 0 End Sub Function CreateCheckBox(byref ItemHandle as Item, byval px as Integer, byval py as Integer, byval txt as String="", byval TextAlign as Integer = TextRight) as Item Dim as UInteger ExStyle = WS_EX_TRANSPARENT Dim as UInteger Style = WS_VISIBLE OR WS_CHILD OR WS_CLIPSIBLINGS OR WS_TABSTOP OR BS_AUTOCHECKBOX If (ItemHandle = 0) Then return NULL Dim as RECT prect Dim as HWND phwnd Dim as Integer rx, ry If (ItemHandle -> ID = WindowID) Then phwnd = ItemHandle -> whwnd rx = px : ry = py ElseIf (ItemHandle -> ID = GroupBoxID) Then phwnd = GetParent(ItemHandle -> whwnd) GetClientRect(ItemHandle -> whwnd, @prect) MapWindowPoints(ItemHandle -> whwnd, phwnd, Cast(LPPOINT, @prect),2) rx = prect.left + px : ry = prect.top + py Else LOGSTRING(Time & " | ERROR | Parent is not an valid Item.") Return NULL End If '*** Calculate Size of CheckBox 'http://msdn.microsoft.com/en-us/library/aa511279.aspx#controlsizing 'http://msdn.microsoft.com/en-us/library/ms997619.aspx 'CheckBox has 10 Dialog Units 'http://support.microsoft.com/kb/145994 'pixelX = (dialogunitX * baseunitX) / 4 'pixelY = (dialogunitY * baseunitY) / 8 Dim as Integer baseunits = GetDialogBaseUnits() Dim as Integer baseunitX = loword(baseunits) Dim as Integer baseunitY = hiword(baseunits) Dim as Integer rbtnX = (10 * baseunitX) / 4 '20? Dim as Integer rbtnY = (10 * baseunitY) / 8 '20? '*** Calculate Size of Text Dim as SIZE cSIZE Dim as HDC cDC = GetDC(phwnd) Dim as String dtxt = txt GetTextExtentPoint32(cDC,dtxt,len(txt),@cSIZE) 'http://forums.codeguru.com/showthread.php?258701-Should-ReleaseDC%28%29-after-each-GetDC%28%29 ReleaseDC(phwnd, cDC) '*** Caculate Button+Text Width'n'Height Dim as Integer btnW = rbtnX + cSize.CX Dim as Integer btnH = IIF(rbtnY>cSize.CY, rbtnY, cSize.CY) If TextAlign=TextLeft Then Style = Style OR BS_RIGHTBUTTON 'same as BS_LEFTTEXT Dim as Item_Check ptr newCheckBox = new Item_Check newCheckBox -> whwnd = CreateWindowEx(NULL, "BUTTON", txt, Style, rx, ry, btnW, btnH, phwnd, NULL, Globals.hInstance, newCheckBox) If (NewCheckBox -> whwnd = 0) Then Delete newCheckBox LOGSTRING(Time & " | ERROR | Failed to create " & CheckBoxID) MessageBox(NULL,"Failed to create " & CheckBoxID, "Error", NULL) Return NULL End If SendMessage(newCheckBox -> whwnd, WM_SETFONT, Cast(WPARAM, Globals.hFont), Cast(LPARAM,TRUE)) SetWindowLongPtr(newCheckBox -> whwnd, GWLP_USERDATA, Cast(LONG_PTR, newCheckBox)) newCheckBox -> ID = CheckBoxID newCheckBox -> Title = txt LOGSTRING(Time & " | INFO | " & CheckBoxID & " " & newCheckBox -> Title & " created on " & ItemHandle -> ID & " " & ItemHandle -> Title & ".") Globals.ItemList.AddItem(newCheckBox) return newCheckBox End Function 'Works with CheckBox and RadioButton (same as GetRadioButtonState()) Function GetCheckBoxState(byref ItemHandle as Item) as Integer If ItemHandle Then If ItemHandle -> ID = CheckBoxID orelse ItemHandle -> ID = RadioButtonID Then If SendMessage(ItemHandle -> whwnd, BM_GETCHECK, NULL, NULL) Then return TRUE End If End If return FALSE End Function 'Works with CheckBox only Sub SetCheckBoxState(byref ItemHandle as Item, byval State as Integer) If ItemHandle Then If ItemHandle -> ID = CheckBoxID Then Dim as Integer newState = IIF(State, BST_CHECKED, BST_UNCHECKED) SendMessage(ItemHandle -> whwnd, BM_SETCHECK, Cast(WPARAM, newState), NULL) End If End If End Sub