Sub Item_RadioButton.Destroy() ID = "" : Title = "" DestroyWindow(whwnd) ghwnd = 0 : mhwnd = 0 FirstID = 0 : LastID = 0 : NowID = 0 End Sub Function CreateRadioButton(byref ItemHandle as Item , byref GroupHandle as Item, _ byval px as Integer , byval py as Integer, _ byval txt as String="", byval TextAlign as UInteger = TextRight) as Item Dim as UInteger ExStyle = WS_EX_TRANSPARENT Dim as UInteger BStyle = WS_VISIBLE OR WS_CHILD OR WS_CLIPSIBLINGS OR BS_AUTORADIOBUTTON OR BS_TEXT Dim as UInteger GStyle = WS_TABSTOP OR WS_GROUP Dim as UInteger Style = IIF(GroupHandle, BStyle, BStyle OR GStyle) Dim as Integer RBID If (ItemHandle = 0) Then return NULL If GroupHandle Then If GroupHandle -> ID <> RadioButtonID Then LOGSTRING(Time & " | ERROR | GroupHandle is not an valid RadioButton Item.") return NULL End If End If 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 RadioButton 'http://msdn.microsoft.com/en-us/library/aa511279.aspx#controlsizing 'http://msdn.microsoft.com/en-us/library/ms997619.aspx 'RadioButton 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) ReleaseDC(phwnd, cDC) '*** Caculate Button+Text With'n'Height Dim as Integer btnW = rbtnX + cSize.CX Dim as Integer btnH = IIF(rbtnY>cSize.CY, rbtnY, cSize.CY) Dim as Item_RadioButton ptr newRadioButton = new Item_RadioButton If GroupHandle Then 'Gen/Get ID and set Text align Flag RBID = Cast(Item_RadioButton ptr, GroupHandle) -> LastID + 1 If Cast(Item_RadioButton ptr, GroupHandle) -> TextAlign = TextLeft Then Style = Style OR BS_RIGHTBUTTON Else RBID = Cast(Integer, newRadioButton) If TextAlign=TextLeft Then Style = Style OR BS_RIGHTBUTTON 'same as BS_LEFTTEXT End If newRadioButton -> whwnd = CreateWindowEx(ExStyle, "BUTTON", txt, Style, rx, ry, btnW, btnH, phwnd, Cast(HMENU,RBID), Globals.hInstance, newRadioButton) If (newRadioButton -> whwnd = 0) Then Delete newRadioButton LOGSTRING(Time & " | ERROR | Failed to create " & RadioButtonID) MessageBox(NULL,"Failed to create " & RadioButtonID, "Error", NULL) Return NULL End If If GroupHandle = 0 Then SendMessage(newRadioButton -> whwnd, BM_SETCHECK, Cast(WPARAM, BST_CHECKED), NULL) SendMessage(newRadioButton -> whwnd, WM_SETFONT, Cast(WPARAM, Globals.hFont), Cast(LPARAM,TRUE)) SetWindowLongPtr(newRadioButton -> whwnd, GWLP_USERDATA, Cast(LONG_PTR, newRadioButton)) newRadioButton -> ID = RadioButtonID newRadioButton -> Title = txt newRadioButton -> NowID = RBID 'First'n'Last RadioButton ID will only set to the GroupStart RadioButton If GroupHandle Then Cast(Item_RadioButton ptr, GroupHandle) -> LastID = RBID newRadioButton -> ghwnd = GroupHandle Else newRadioButton -> ghwnd = newRadioButton newRadioButton -> mhwnd = ItemHandle newRadioButton -> FirstID = RBID newRadioButton -> LastID = RBID newRadioButton -> TextAlign = TextAlign End If LOGSTRING(Time & " | INFO | " & RadioButtonID & " " & newRadioButton -> Title & " created on " & ItemHandle -> ID & " " & ItemHandle -> Title & ".") Globals.ItemList.AddItem(newRadioButton) return newRadioButton End Function Function RadioButtonGroup(byref ItemHandle as Item, byval px as Integer, byval py as Integer, byval txt as String="", byval TextAlign as Integer = TextRight) as Item return CreateRadioButton(ItemHandle, NULL, px, py, txt, TextAlign) End Function Function RadioButtonAdd(byref GroupHandle as Item, byval px as Integer, byval py as Integer, byval txt as String="") as Item Dim as Item ItemHandle If GroupHandle andalso GroupHandle -> ID = RadioButtonID Then ItemHandle = Cast(Item_RadioButton ptr, GroupHandle) -> mhwnd return CreateRadioButton(ItemHandle, GroupHandle, px, py, txt) End If End Function 'Works with CheckBox and RadioButton (same as GetCheckBoxState()) Function GetRadioButtonState(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 RadioButton only Sub SetRadioButtonState(byref ItemHandle as Item, byval State as Integer) Dim as Item_RadioButton ptr RadioGroup If ItemHandle andalso ItemHandle -> ID = RadioButtonID Then If State Then If SendMessage(ItemHandle -> whwnd, BM_GETCHECK, NULL, NULL) = 0 Then If Cast(Item_RadioButton ptr, ItemHandle) -> ghwnd Then RadioGroup = Cast(Item_RadioButton ptr, Cast(Item_RadioButton ptr, ItemHandle) -> ghwnd) Else RadioGroup = Cast(Item_RadioButton ptr, ItemHandle) End If CheckRadioButton(GetParent(RadioGroup -> whwnd), RadioGroup -> FirstID, RadioGroup -> LastID, Cast(Item_RadioButton ptr, ItemHandle) -> NowID) End If Else SendMessage(ItemHandle -> whwnd, BM_SETCHECK, Cast(WPARAM,BST_UNCHECKED), NULL) End If End If End Sub