Bert Posted September 19, 2006 Share Posted September 19, 2006 I'm trying to make a button that is colored and is multi lined. I'm using Gary's GuiButton.au3. I can make buttons no problem. When I try to make it multi lined, the output looks like this: I need it to looke like this, but with the colors like my first example: The function that makes the button that Gary made is this: Func _GuiCtrlCreateButton($s_text, $x, $y, $width, $height, $text_color = -1, $back_color = -1, $b_RGB = True) Local $button_id = GUICtrlCreateButton("", $x, $y, $width, $height) If $text_color = -1 Then $text_color = 0x000000 If $back_color = -1 Then $back_color = 0xd3d3d3 If $b_RGB Then Local $tc = Hex(String($text_color), 6) $text_color = '0x' & StringMid($tc, 5, 2) & StringMid($tc, 3, 2) & StringMid($tc, 1, 2) $tc = Hex(String($back_color), 6) $back_color = '0x' & StringMid($tc, 5, 2) & StringMid($tc, 3, 2) & StringMid($tc, 1, 2) EndIf If Number($Button_Info[UBound($Button_Info) - 1][0]) <> 0 Then ReDim $Button_Info[UBound($Button_Info) + 1][4] $Button_Info[UBound($Button_Info) - 1][0] = $button_id $Button_Info[UBound($Button_Info) - 1][1] = $s_text $Button_Info[UBound($Button_Info) - 1][2] = $text_color $Button_Info[UBound($Button_Info) - 1][3] = $back_color GUICtrlSetStyle($button_id, BitOR($WS_TABSTOP, $BS_NOTIFY, $BS_OWNERDRAW)) ; Set the ownerdrawn flag Return $button_id EndFunc ;==>_GuiC On the line: Local $button_id = GUICtrlCreateButton("", $x, $y, $width, $height), I tried to add $BS_MULTILINE to fix the problem, but it didn't work. Thoughts? The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
CoePSX Posted September 19, 2006 Share Posted September 19, 2006 Try adding the $BS_MULTILINE style. [quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"]╔══════════════════════════════╗║░░██░░░░░░░░██░░███░░░████░░░█║║░█░░█░░██░░█░░█░█░░█░█░░░░█░█░║║░█░░░░█░░█░████░███░░░██░░░█░░║║░█░░█░█░░█░█░░░░█░░░░░░░█░█░█░║║░░██░░░██░░░██░░█░░░░███░█░░░█║╚══════════════════════════════╝[/font] Link to comment Share on other sites More sharing options...
Bert Posted September 19, 2006 Author Share Posted September 19, 2006 I tried that already. I have to add it in the GuiButton.au3, and you can see in my first post I explain this. When you use _GuiCtrlCreateButton as defined in GuiButton.au3, there is no place to add an extended style _GuiCtrlCreateButton($s_text, $x, $y, $width, $height, $text_color = -1, $back_color = -1, $b_RGB = True) I have to add it in the function. The problem is, when I add it, It makes no difference. The code in the function is somewhat more advanced than my skills, so I was hoping someone ( @ Gary) would take pity on me and help a fellow coder out. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
BitRot Posted September 19, 2006 Share Posted September 19, 2006 (edited) On the line: Local $button_id = GUICtrlCreateButton("", $x, $y, $width, $height), I tried to add $BS_MULTILINE to fix the problem, but it didn't work. Thoughts?Strange. I just added that "$bs_multiline" to the style (not to the ex_style), and it worked o.k. for me ... [edit] I realized, after going to bed, that I used a simple GUICtrlCreateButton(...), and not that script you've shown (that allso changes the controls attributes). So, YMMV. Suggestion : Try a simple button first (as I did), and than try what happens when you do the same in the script. Allso try what happens when you disable that GUICtrlSetStyle(...) at the bottom. Edited September 20, 2006 by BitRot Link to comment Share on other sites More sharing options...
Bert Posted September 20, 2006 Author Share Posted September 20, 2006 hmmm, I will test it again in the morning. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Bert Posted September 20, 2006 Author Share Posted September 20, 2006 OK, I got it to do an multi line with what you suggested. Now I have a second problem, and puzzled on how to fix it. I changed in GuiButton.au3 the following line in the function from this: expandcollapse popupGUICtrlSetStyle($button_id, BitOR($WS_TABSTOP, $BS_NOTIFY, $BS_OWNERDRAW))oÝ÷ ÚÚºÚ"µÍÕRPÝÙ]Ý[J ÌÍØ]ÛÚY]Ô ÌÍÕÔ×ÕPÕÔ ÌÍÐ×ÓÕQK ÌÍÐ×ÓÕÓTUË ÌÍÐ×ÓUSSSJJoÝ÷ Øfiק¡Ø}êÞÇj[(¶¸wMú%BÔÄE©ÝÓ~H! LDm¢êÚÛaj×bv}ý· +èêÇz·¢²Ø^{¦¦W¬r¸©´f«É׬ Þtýë"hµë-Â+ajëh×6#include <GUIConstants.au3> #include "GuiButton.au3" Opt("MustDeclareVars", 1) Global $nButton, $nButton2, $nButton3 _Main() Func _Main() Local $GUIMsg $hGUI = GUICreate("My Ownerdrawn Created Button", 300, 200) $nButton = _GuiCtrlCreateButton ("My Button", 90, 50, 120, 30, 0x800080, 0x00ffff) $nButton2 = _GuiCtrlCreateButton ("Another" & @CRLF & "Button", 90, 90, 120, 30, 0x00ffff, 0x800000, False) $nButton3 = _GuiCtrlCreateButton ("Owner Drawn 3rd", 90, 130, 120, 30) GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND") ; WM_DRAWITEM has to registered before showing GUI otherwise the initial drawing isn't done GUIRegisterMsg($WM_DRAWITEM, "MY_WM_DRAWITEM") GUISetState() While 1 $GUIMsg = GUIGetMsg() Switch $GUIMsg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Exit EndFunc ;==>_Main Func Button_Click(ByRef $ctrl_id) Switch $ctrl_id Case $nButton _DebugPrint("Button - with colors") Case $nButton2 _DebugPrint("Button - Another button with colors") Case $nButton3 _DebugPrint("Button - And Another button with colors") EndSwitch EndFunc ;==>Button_Click Here is GuiButton.au3. I have changed line 460 to fix the multi line problem, and you will see where I commented out the original line. (total lines: 463) CODE#include-once ;=============================================================================== ; ; Description: Create Owner drawn buttons ; Author(s): Gary Frost (custompcs@charter.net) modified from the help file ; Note(s): ; ;=============================================================================== Global $hGUI Global $Button_Count = 0 Global $Button_Info[1][4];=[[0],[-999,"",0x000000,0xd3d3d3]] Global Const $WM_DRAWITEM = 0x002B Global Const $WM_COMMAND = 0x0111 Global Const $GWL_STYLE = -16 Global Const $BS_OWNERDRAW = 0x0000000B Global Const $BS_NOTIFY = 0x00004000 Global Const $COLOR_BTNTEXT = 18 Global Const $COLOR_BTNFACE = 15 Global Const $COLOR_BTNSHADOW = 16 Global Const $COLOR_HIGHLIGHTTEXT = 14 Global Const $COLOR_GRAYTEXT = 17 Global Const $DT_CENTER = 0x00000001 Global Const $DT_RIGHT = 0x00000002 Global Const $DT_VCENTER = 0x00000004 Global Const $DT_BOTTOM = 0x00000008 Global Const $DT_WORDBREAK = 0x00000010 Global Const $DT_SINGLELINE = 0x00000020 Global Const $DT_EXPANDTABS = 0x00000040 Global Const $DT_TABSTOP = 0x00000080 Global Const $DT_NOCLIP = 0x00000100 Global Const $DT_EXTERNALLEADING = 0x00000200 Global Const $DT_CALCRECT = 0x00000400 Global Const $DT_NOPREFIX = 0x00000800 Global Const $DT_INTERNAL = 0x00001000 Global Const $ODS_SELECTED = 0x0001 Global Const $ODS_GRAYED = 0x0002 Global Const $ODS_DISABLED = 0x0004 Global Const $ODS_CHECKED = 0x0008 Global Const $ODS_FOCUS = 0x0010 Global Const $ODS_HOTLIGHT = 0x0040 Global Const $ODS_INACTIVE = 0x0080 Global Const $ODS_NOACCEL = 0x0100 Global Const $ODS_NOFOCUSRECT = 0x0200 Global Const $ODT_BUTTON = 4 Global Const $DFC_BUTTON = 4 Global Const $DFCS_BUTTONPUSH = 0x0010 Global Const $BN_CLICKED = 0; Global Const $BN_PAINT = 1; Global Const $BN_HILITE = 2; Global Const $BN_PUSHED = $BN_HILITE; Global Const $BN_UNHILITE = 3; Global Const $BN_UNPUSHED = $BN_UNHILITE; Global Const $BN_DISABLE = 4; Global Const $BN_DOUBLECLICKED = 5; Global Const $BN_DBLCLK = $BN_DOUBLECLICKED; Global Const $BN_SETFOCUS = 6; Global Const $BN_KILLFOCUS = 7; ; React on a button click Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam) Local $nNotifyCode = BitShift($wParam, 16) Local $nID = BitAND($wParam, 0x0000FFFF) Local $hCtrl = $lParam If $nID <> 2 Then Switch $nNotifyCode Case $BN_CLICKED _DebugPrint("$BN_CLICKED: " & @LF & "GUIHWnd" & @TAB & ":" & $hwnd & @LF & _ "MsgID" & @TAB & ":" & $Msg & @LF & _ "wParam" & @TAB & ":" & $wParam & @LF & _ "lParam" & @TAB & ":" & $lParam & @LF & @LF & _ "WM_COMMAND - Infos:" & @LF & _ "-----------------------------" & @LF & _ "Code" & @TAB & ":" & $nNotifyCode & @LF & _ "CtrlID" & @TAB & ":" & $nID & @LF & _ "CtrlHWnd" & @TAB & ":" & $hCtrl) ; Ownerdrawn buttons don't send something by pressing ENTER ; So IDOK - 1 comes up, now check for the control that has the current focus If $nID = 1 Then Local $hFocus = DllCall("user32.dll", "hwnd", "GetFocus") Local $nCtrlID = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $hFocus[0]) PostButtonclick($hFocus[0], $nCtrlID[0]) Else Button_Click ($nID) ;~ Msgbox(0, "MY_WM_COMMAND", "GUIHWnd" & @TAB & ":" & $hwnd & @LF & _ ;~ "MsgID" & @TAB & ":" & $Msg & @LF & _ ;~ "wParam" & @TAB & ":" & $wParam & @LF & _ ;~ "lParam" & @TAB & ":" & $lParam & @LF & @LF & _ ;~ "WM_COMMAND - Infos:" & @LF & _ ;~ "-----------------------------" & @LF & _ ;~ "Code" & @TAB & ":" & $nNotifyCode & @LF & _ ;~ "CtrlID" & @TAB & ":" & $nID & @LF & _ ;~ "CtrlHWnd" & @TAB & ":" & $hCtrl) EndIf Case $BN_PAINT _DebugPrint("$BN_PAINT") Case $BN_PUSHED, $BN_HILITE _DebugPrint("$BN_PUSHED, $BN_HILITE") Case $BN_UNPUSHED, $BN_UNHILITE _DebugPrint("$BN_UNPUSHED") Case $BN_DISABLE _DebugPrint("$BN_DISABLE") Case $BN_DBLCLK, $BN_DOUBLECLICKED _DebugPrint("$BN_DBLCLK, $BN_DOUBLECLICKED") Case $BN_SETFOCUS _DebugPrint("$BN_SETFOCUS") Case $BN_KILLFOCUS _DebugPrint("$BN_KILLFOCUS") EndSwitch ;~ Return 0 ; Only workout clicking on the button EndIf ; Proceed the default Autoit3 internal message commands. ; You also can complete let the line out. ; !!! But only 'Return' (without any value) will not proceed ; the default Autoit3-message in the future !!! Return $GUI_RUNDEFMSG EndFunc ;==>MY_WM_COMMAND Func _DebugPrint($s_text) ConsoleWrite( _ "!===========================================================" & @LF & _ "+===========================================================" & @LF & _ "-->" & $s_text & @LF & _ "+===========================================================" & @LF) EndFunc ;==>_DebugPrint ; RePost a WM_COMMAND message to a ctrl in a gui window Func PostButtonclick($hWnd, $nCtrlID) DllCall("user32.dll", "int", "PostMessage", _ "hwnd", $hGUI, _ "int", $WM_COMMAND, _ "int", BitAND($nCtrlID, 0x0000FFFF), _ "hwnd", GUICtrlGetHandle($nCtrlID)) EndFunc ;==>PostButtonclick ; Draw the button Func MY_WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam) Local $stDrawItem = DllStructCreate("uint;uint;uint;uint;uint;uint;uint;int[4];dword", $lParam) Local $nCtlType, $nCtrlID, $nItemState, $hCtrl, $hDC, $nLeft, $nTop, $nRight, $nBottom, $sText Local $nTextColor, $nBackColor $nCtlType = DllStructGetData($stDrawItem, 1) If $nCtlType = $ODT_BUTTON Then $nCtrlID = DllStructGetData($stDrawItem, 2) $nItemState = DllStructGetData($stDrawItem, 5) $hCtrl = DllStructGetData($stDrawItem, 6) $hDC = DllStructGetData($stDrawItem, 7) $nLeft = DllStructGetData($stDrawItem, 8, 1) $nTop = DllStructGetData($stDrawItem, 8, 2) $nRight = DllStructGetData($stDrawItem, 8, 3) $nBottom = DllStructGetData($stDrawItem, 8, 4) Local $x For $x = 0 To UBound($Button_Info) - 1 If $nCtrlID = $Button_Info[$x][0] Then $sText = $Button_Info[$x][1] $nTextColor = $Button_Info[$x][2] $nBackColor = $Button_Info[$x][3] ExitLoop EndIf Next DrawButton($hWnd, $hCtrl, $hDC, $nLeft, $nTop, $nRight, $nBottom, $nItemState, $sText, $nTextColor, $nBackColor) $stDrawItem = 0 Return 1 EndIf $stDrawItem = 0 Return $GUI_RUNDEFMSG ; Proceed the default Autoit3 internal message commands EndFunc ;==>MY_WM_DRAWITEM ; The main drawing procedure Func DrawButton($hWnd, $hCtrl, $hDC, $nLeft, $nTop, $nRight, $nBottom, $nItemState, $sText, $nTextColor, $nBackColor) ;Local $bDefault = FALSE Local $bChecked = BitAND($nItemState, $ODS_CHECKED) Local $bFocused = BitAND($nItemState, $ODS_FOCUS) Local $bGrayed = BitAND($nItemState, BitOR($ODS_GRAYED, $ODS_DISABLED)) Local $bSelected = BitAND($nItemState, $ODS_SELECTED) Local $nClrTxt, $hBrush, $nClrSel, $nClrBk, $hOldBrush, $nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom Local $uFlags, $hBrushSel Local $stRect = DllStructCreate("int;int;int;int") DllStructSetData($stRect, 1, $nLeft) DllStructSetData($stRect, 2, $nTop) DllStructSetData($stRect, 3, $nRight) DllStructSetData($stRect, 4, $nBottom) If $bGrayed Then $nClrTxt = SetTextColor($hDC, GetSysColor($COLOR_HIGHLIGHTTEXT)) ElseIf $nTextColor = -1 Then $nClrTxt = SetTextColor($hDC, GetSysColor($COLOR_BTNTEXT)) Else $nClrTxt = SetTextColor($hDC, $nTextColor) EndIf If $nBackColor = -1 Then $hBrush = GetSysColorBrush($COLOR_BTNFACE) $nClrSel = GetSysColor($COLOR_BTNFACE) Else $hBrush = CreateSolidBrush($nBackColor) $nClrSel = $nBackColor; EndIf $nClrBk = SetBkColor($hDC, $nClrSel) $hOldBrush = SelectObject($hDC, $hBrush) $nTmpLeft = $nLeft $nTmpTop = $nTop $nTmpRight = $nRight $nTmpBottom = $nBottom If $bSelected Then InflateRect($nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, -1, -1) $hBrushSel = CreateSolidBrush(GetSysColor($COLOR_BTNSHADOW)) FrameRect($hDC, $nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, $hBrushSel) DeleteObject($hBrushSel) Else If $bFocused And Not $bSelected Then InflateRect($nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, -1, -1) DrawFrameControl($hDC, $nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, $DFC_BUTTON, $DFCS_BUTTONPUSH) EndIf $nTmpLeft = $nLeft $nTmpTop = $nTop $nTmpRight = $nRight $nTmpBottom = $nBottom If $bSelected Then InflateRect($nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, -2, -2) Else If $bFocused And Not $bSelected Then InflateRect($nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, -3, -3) $nTmpLeft -= 1 $nTmpTop -= 1 Else InflateRect($nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, -2, -2) $nTmpLeft -= 1 $nTmpTop -= 1 EndIf EndIf FillRect($hDC, $nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, $hBrush) If $bSelected Or $bGrayed Then $nTmpLeft = $nTmpLeft + 2 $nTmpTop = $nTmpTop + 2 EndIf $uFlags = BitOR($DT_NOCLIP, $DT_CENTER, $DT_VCENTER) If Not BitAND(GetWindowLong($hCtrl, $GWL_STYLE), $BS_MULTILINE) Then $uFlags = BitOR($uFlags, $DT_SINGLELINE) DrawText($hDC, $sText, $nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, $uFlags) If $bGrayed Then $nTmpLeft = $nLeft $nTmpTop = $nTop $nTmpRight = $nRight $nTmpBottom = $nBottom $nTmpLeft -= 1 $nClrTxt = SetTextColor($hDC, GetSysColor($COLOR_GRAYTEXT)) DrawText($hDC, $sText, $nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, BitOR($DT_NOCLIP, $DT_CENTER, $DT_VCENTER, $DT_SINGLELINE)) EndIf $nTmpLeft = $nLeft $nTmpTop = $nTop $nTmpRight = $nRight $nTmpBottom = $nBottom If $bFocused Then $hBrush = CreateSolidBrush(0) FrameRect($hDC, $nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, $hBrush) $nTmpLeft = $nLeft $nTmpTop = $nTop $nTmpRight = $nRight $nTmpBottom = $nBottom InflateRect($nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom, -4, -4) DrawFocusRect($hDC, $nTmpLeft, $nTmpTop, $nTmpRight, $nTmpBottom) EndIf SelectObject($hDC, $hOldBrush) DeleteObject($hBrush) SetTextColor($hDC, $nClrTxt) SetBkColor($hDC, $nClrBk) Return 1 EndFunc ;==>DrawButton ; Some graphic / windows functions Func CreateSolidBrush($nColor) Local $hBrush = DllCall("gdi32.dll", "hwnd", "CreateSolidBrush", "int", $nColor) Return $hBrush[0] EndFunc ;==>CreateSolidBrush Func GetSysColor($nIndex) Local $nColor = DllCall("user32.dll", "int", "GetSysColor", "int", $nIndex) Return $nColor[0] EndFunc ;==>GetSysColor Func GetSysColorBrush($nIndex) Local $hBrush = DllCall("user32.dll", "hwnd", "GetSysColorBrush", "int", $nIndex) Return $hBrush[0] EndFunc ;==>GetSysColorBrush Func DrawFrameControl($hDC, $nLeft, $nTop, $nRight, $nBottom, $nType, $nState) Local $stRect = DllStructCreate("int;int;int;int") DllStructSetData($stRect, 1, $nLeft) DllStructSetData($stRect, 2, $nTop) DllStructSetData($stRect, 3, $nRight) DllStructSetData($stRect, 4, $nBottom) DllCall("user32.dll", "int", "DrawFrameControl", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "int", $nType, "int", $nState) $stRect = 0 EndFunc ;==>DrawFrameControl Func DrawFocusRect($hDC, $nLeft, $nTop, $nRight, $nBottom) Local $stRect = DllStructCreate("int;int;int;int") DllStructSetData($stRect, 1, $nLeft) DllStructSetData($stRect, 2, $nTop) DllStructSetData($stRect, 3, $nRight) DllStructSetData($stRect, 4, $nBottom) DllCall("user32.dll", "int", "DrawFocusRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect)) $stRect = 0 EndFunc ;==>DrawFocusRect Func DrawText($hDC, $sText, $nLeft, $nTop, $nRight, $nBottom, $nFormat) Local $nLen = StringLen($sText) Local $stRect = DllStructCreate("int;int;int;int") DllStructSetData($stRect, 1, $nLeft) DllStructSetData($stRect, 2, $nTop) DllStructSetData($stRect, 3, $nRight) DllStructSetData($stRect, 4, $nBottom) Local $stText = DllStructCreate("char[260]") DllStructSetData($stText, 1, $sText) DllCall("user32.dll", "int", "DrawText", "hwnd", $hDC, "ptr", DllStructGetPtr($stText), "int", $nLen, "ptr", DllStructGetPtr($stRect), "int", $nFormat) $stRect = 0 $stText = 0 EndFunc ;==>DrawText Func FillRect($hDC, $nLeft, $nTop, $nRight, $nBottom, $hBrush) Local $stRect = DllStructCreate("int;int;int;int") DllStructSetData($stRect, 1, $nLeft) DllStructSetData($stRect, 2, $nTop) DllStructSetData($stRect, 3, $nRight) DllStructSetData($stRect, 4, $nBottom) DllCall("user32.dll", "int", "FillRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush) $stRect = 0 EndFunc ;==>FillRect Func FrameRect($hDC, $nLeft, $nTop, $nRight, $nBottom, $hBrush) Local $stRect = DllStructCreate("int;int;int;int") DllStructSetData($stRect, 1, $nLeft) DllStructSetData($stRect, 2, $nTop) DllStructSetData($stRect, 3, $nRight) DllStructSetData($stRect, 4, $nBottom) DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush) $stRect = 0 EndFunc ;==>FrameRect Func InflateRect(ByRef $nLeft, ByRef $nTop, ByRef $nRight, ByRef $nBottom, $nX, $nY) Local $stRect = DllStructCreate("int;int;int;int") DllStructSetData($stRect, 1, $nLeft) DllStructSetData($stRect, 2, $nTop) DllStructSetData($stRect, 3, $nRight) DllStructSetData($stRect, 4, $nBottom) DllCall("user32.dll", "int", "InflateRect", "ptr", DllStructGetPtr($stRect), "int", $nX, "int", $nY) $nLeft = DllStructGetData($stRect, 1) $nTop = DllStructGetData($stRect, 2) $nRight = DllStructGetData($stRect, 3) $nBottom = DllStructGetData($stRect, 4) $stRect = 0 EndFunc ;==>InflateRect Func SetBkColor($hDC, $nColor) Local $nOldColor = DllCall("gdi32.dll", "int", "SetBkColor", "hwnd", $hDC, "int", $nColor) Return $nOldColor[0] EndFunc ;==>SetBkColor Func SetTextColor($hDC, $nColor) Local $nOldColor = DllCall("gdi32.dll", "int", "SetTextColor", "hwnd", $hDC, "int", $nColor) Return $nOldColor[0] EndFunc ;==>SetTextColor Func SelectObject($hDC, $hObj) Local $hOldObj = DllCall("gdi32.dll", "hwnd", "SelectObject", "hwnd", $hDC, "hwnd", $hObj) Return $hOldObj[0] EndFunc ;==>SelectObject Func DeleteObject($hObj) Local $nResult = DllCall("gdi32.dll", "hwnd", "DeleteObject", "hwnd", $hObj) EndFunc ;==>DeleteObject Func GetWindowLong($hWnd, $nIndex) Local $nVal = DllCall("user32.dll", "int", "GetWindowLong", "hwnd", $hWnd, "int", $nIndex) Return $nVal[0] EndFunc ;==>GetWindowLong Func _GuiCtrlCreateButton($s_text, $x, $y, $width, $height, $text_color = -1, $back_color = -1, $b_RGB = True) Local $button_id = GUICtrlCreateButton("", $x, $y, $width, $height) If $text_color = -1 Then $text_color = 0x000000 If $back_color = -1 Then $back_color = 0xd3d3d3 If $b_RGB Then Local $tc = Hex(String($text_color), 6) $text_color = '0x' & StringMid($tc, 5, 2) & StringMid($tc, 3, 2) & StringMid($tc, 1, 2) $tc = Hex(String($back_color), 6) $back_color = '0x' & StringMid($tc, 5, 2) & StringMid($tc, 3, 2) & StringMid($tc, 1, 2) EndIf If Number($Button_Info[uBound($Button_Info) - 1][0]) <> 0 Then ReDim $Button_Info[uBound($Button_Info) + 1][4] $Button_Info[uBound($Button_Info) - 1][0] = $button_id $Button_Info[uBound($Button_Info) - 1][1] = $s_text $Button_Info[uBound($Button_Info) - 1][2] = $text_color $Button_Info[uBound($Button_Info) - 1][3] = $back_color GUICtrlSetStyle($button_id, BitOR($WS_TABSTOP, $BS_NOTIFY, $BS_OWNERDRAW, $BS_MULTILINE, $BS_VCENTER, $BS_CENTER)) ; Set the ownerdrawn flag ;GUICtrlSetStyle($button_id, BitOR($WS_TABSTOP, $BS_NOTIFY, $BS_OWNERDRAW)) ; Set the ownerdrawn flag Return $button_id EndFunc ;==>_GuiC The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
BitRot Posted September 20, 2006 Share Posted September 20, 2006 Now I have a second problem, and puzzled on how to fix it. ... When I ran my test script to see how the button would look, I got this: <snip> You notice I now have the text on the other 2 buttons not being centered.Thanks for posting the full code. It was very helpfull in finding both the cause, and a solution <thumbs up> The solution is actually quite simple, and I'm almost sure you will at least have a smile when I tell you : don't add the "$BS_MULTILINE" flag when you do not have multiple lines. The resulting code could look something like this : Func _GuiCtrlCreateButton($s_text, $x, $y, $width, $height, $text_color = -1, $back_color = -1, $b_RGB = True) Local $button_id = GUICtrlCreateButton("", $x, $y, $width, $height), $bits=BitOR($WS_TABSTOP, $BS_NOTIFY, $BS_OWNERDRAW) ;<### If $text_color = -1 Then $text_color = 0x000000 If $back_color = -1 Then $back_color = 0xd3d3d3 If $b_RGB Then Local $tc = Hex(String($text_color), 6) $text_color = '0x' & StringMid($tc, 5, 2) & StringMid($tc, 3, 2) & StringMid($tc, 1, 2) $tc = Hex(String($back_color), 6) $back_color = '0x' & StringMid($tc, 5, 2) & StringMid($tc, 3, 2) & StringMid($tc, 1, 2) EndIf If Number($Button_Info[UBound($Button_Info) - 1][0]) <> 0 Then ReDim $Button_Info[UBound($Button_Info) + 1][4] $Button_Info[UBound($Button_Info) - 1][0] = $button_id $Button_Info[UBound($Button_Info) - 1][1] = $s_text $Button_Info[UBound($Button_Info) - 1][2] = $text_color $Button_Info[UBound($Button_Info) - 1][3] = $back_color if StringInStr($s_text,@crlf)>0 then $bits=BitOr($bits,$BS_MULTILINE) ;<### GUICtrlSetStyle($button_id, $bits) ; Set the ownerdrawn flag ;<### Return $button_id EndFunc ;==>_GuiC(Changes marked with "<###") Link to comment Share on other sites More sharing options...
Bert Posted September 21, 2006 Author Share Posted September 21, 2006 Sounds like I will need to have more than one function to solve this for I need to have it both ways. (Buttons with one line, and buttons with 2. Should be pretty simple to do. THANKS! The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
BitRot Posted September 21, 2006 Share Posted September 21, 2006 (edited) Sounds like I will need to have more than one function to solve this for I need to have it both ways. (Buttons with one line, and buttons with 2. Should be pretty simple to do. THANKS! Actually, the code I've posted in my previous message allready takes care of that : only if the text contains a @crlf combination it adds the $bs_multiline -bit. So, you can create both multi and single-line buttons with the same _GuiCtrlCreateButton code. In other words : the code I posted is ment as a full replacement of the code you currently have there. Edited September 21, 2006 by BitRot Link to comment Share on other sites More sharing options...
Bert Posted September 21, 2006 Author Share Posted September 21, 2006 I changed GuiButton.au3 so it will do multi and also center the text. Func _GuiCtrlCreateButton($multiline,$s_text, $x, $y, $width, $height, $text_color = -1, $back_color = -1, $b_RGB = True) Local $button_id = GUICtrlCreateButton("", $x, $y, $width, $height) If $text_color = -1 Then $text_color = 0x000000 If $back_color = -1 Then $back_color = 0xd3d3d3 If $b_RGB Then Local $tc = Hex(String($text_color), 6) $text_color = '0x' & StringMid($tc, 5, 2) & StringMid($tc, 3, 2) & StringMid($tc, 1, 2) $tc = Hex(String($back_color), 6) $back_color = '0x' & StringMid($tc, 5, 2) & StringMid($tc, 3, 2) & StringMid($tc, 1, 2) EndIf If Number($Button_Info[UBound($Button_Info) - 1][0]) <> 0 Then ReDim $Button_Info[UBound($Button_Info) + 1][4] $Button_Info[UBound($Button_Info) - 1][0] = $button_id $Button_Info[UBound($Button_Info) - 1][1] = $s_text $Button_Info[UBound($Button_Info) - 1][2] = $text_color $Button_Info[UBound($Button_Info) - 1][3] = $back_color if $multiline = 1 then GUICtrlSetStyle($button_id, BitOR($WS_TABSTOP, $BS_NOTIFY, $BS_OWNERDRAW)) ; Set the ownerdrawn flag elseif $multiline = 2 then GUICtrlSetStyle($button_id, BitOR($WS_TABSTOP, $BS_NOTIFY, $BS_OWNERDRAW, $BS_MULTILINE)) else ConsoleWriteError("_GuiCtrlCreateButton($multiline - Error: parameter must be either 1 for single line, or 2 for multiline") exit endif Return $button_id EndFunc ;==>_GuiCtrlCreateButton The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
BitRot Posted September 21, 2006 Share Posted September 21, 2006 I changed GuiButton.au3 so it will do multi and also center the text. <snip>Yep, that's another way to do it (adding another argument) But that way you have two arguments saying exactly the same : your "$multiline" argument (which should be 1 or 2), and the "$s_text" (which is, or is not multi-line (does, or does not contain a @crlf -combination) ).In other words : with those two arguments you can create four combinations, of which just two are valid :"$multiline" =1 , "$s_text" is single-line --> O.k."$multiline" =2 , "$s_text" is single-line --> Faulty"$multiline" =1 , "$s_text" is multi-line --> Faulty"$multiline" =2 , "$s_text" is multi-line --> O.K.Its not what I call "user friendly" Link to comment Share on other sites More sharing options...
Bert Posted September 21, 2006 Author Share Posted September 21, 2006 ? you lost me on that one. Could you show me how you would do it? Odds are it would make much more sense to me if I see a example of the way you are refering to. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
BitRot Posted September 21, 2006 Share Posted September 21, 2006 ? you lost me on that one.Simply said, you have now two arguments, named "$multiline" and "$s_text" in which both indicate the button should be multi-line (or not). The "$multiline" variable should be set to 2, and and the "$s_text" variable should contain a multi-line string (containing a line-break : @crlf). If variables do not match the result will be a "wrong" button appearance.Could you show me how you would do it? Odds are it would make much more sense to me if I see a example of the way you are refering to.I allready did : the code in the reply at position #7. It checks if the "$s_text" argument contains a @crlf -combination, and sets the button to multi-line if so. Link to comment Share on other sites More sharing options...
Bert Posted September 21, 2006 Author Share Posted September 21, 2006 I'm a idiot! I didn't see it! Thanks! The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
BitRot Posted September 21, 2006 Share Posted September 21, 2006 I'm a idiot! I didn't see it! Thanks!You're welcome Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now