@@ -272,87 +272,81 @@ class _BtnColor extends Gui.Button
272272 case CDDS_PREPAINT :
273273 {
274274 isPressed := GetKeyState (" LButton" , " P" )
275+ isHot := (lpnmCD.uItemState & CDIS_HOT)
275276 corner := (roundedCorner ?? (IS_WIN11 ? 9 : 0 ))
276277 drawFocused := (showFocusedBorder && ! first && gCtrl.Focused && ! isPressed)
277- brushColor := (! (lpnmCD.uItemState & CDIS_HOT) || first ? clr : isPressed ? pushedColor : hoverColor)
278- penColor := (drawFocused ? 0xFFFFFF : brushColor)
279278
280- InflateRect(rc := lpnmCD.rc, - 4 , - 4 )
281- SetWindowRgn(gCtrl.hwnd, rcRgn := CreateRoundRectRgn(rc.left , rc.top, rc.right , rc.bottom, corner, corner), 1 )
279+ brushColor := (! isHot || first ? clr : isPressed ? pushedColor : hoverColor)
280+ penColor := (drawFocused ? 0xFFFFFF : brushColor)
281+
282+ rc := lpnmCD.rc
283+ rcRgn := CreateRoundRectRgn(rc.left , rc.top, rc.right , rc.bottom, corner, corner)
284+ SetWindowRgn(gCtrl.hwnd, rcRgn, 1 )
285+ DeleteObject(rcRgn)
282286
283287 SelectObject(lpnmCD.hdc, DC_BRUSH)
284288 SetDCBrushColor(lpnmCD.hdc, brushColor)
289+
285290 SelectObject(lpnmCD.hdc, DC_PEN)
286291 SetDCPenColor(lpnmCD.hdc, penColor)
292+
287293 SetBkMode(lpnmCD.hdc, 0 )
288294
289- if drawFocused {
290- InflateRect(lpnmCD.rc, - 1 , - 1 )
291- DrawFocusRect(lpnmCD.hdc, lpnmCD.rc)
292- }
295+ if drawFocused
296+ FrameRgn(lpnmCD.hdc, rcRgn, DC_PEN, rc.Width, rc.Height)
293297
294- RoundRect(lpnmCD.hdc, lpnmCD.rc.left , lpnmCD.rc.top, lpnmCD.rc.right , lpnmCD.rc.bottom, corner, corner)
295- DeleteObject(rcRgn)
298+ RoundRect(lpnmCD.hdc, rc.left , rc.top, rc.right - 1 , rc.bottom- 1 , corner, corner)
296299
297300 if first
298301 first := 0
299302
300- SetWindowPos(this.hwnd, 0 ,,,, , 0x4043 )
303+ SetWindowPos(this.hwnd, 0 , 0 , 0 , 0 , 0 , 0x4043 )
301304
302305 return CDRF_NOTIFYPOSTPAINT
303306 }}
304307
305308 return CDRF_DODEFAULT
306309 }
307310
308- RgbToBgr(color ) => (IsInteger(color ) ? ((Color >> 16 ) & 0xFF ) | (Color & 0x00FF00 ) | ((Color & 0xFF ) << 16 ) : NUMBER(RegExReplace (STRING(color ), " Si)c?(?:0x)?(?<R>\w{2})(?<G>\w{2})(?<B>\w{2})" , " 0x${B}${G}${R}" )))
311+ BrightenColor(clr, perc := 5 ) => ((p := perc / 100 + 1 ), RGB(Round (Min(255 , (clr >> 16 & 0xFF ) * p)), Round (Min(255 , (clr >> 8 & 0xFF ) * p)), Round (Min(255 , (clr & 0xFF ) * p))))
312+
313+ ColorHex(clr) => Number((! InStr (clr, " 0x" ) ? " 0x" : "" ) clr)
309314
310315 CreateRoundRectRgn(nLeftRect, nTopRect, nRightRect, nBottomRect, nWidthEllipse, nHeightEllipse) => DllCall ('Gdi32\CreateRoundRectRgn', 'int', nLeftRect, 'int', nTopRect, 'int', nRightRect, 'int', nBottomRect, 'int', nWidthEllipse, 'int', nHeightEllipse, 'ptr')
311316
312317 CreateSolidBrush(crColor) => DllCall ('Gdi32\CreateSolidBrush', 'uint', crColor, 'ptr')
313318
314- ColorHex(clr ) => Number(( ! InStr (clr, " 0x " ) ? " 0x " : "" ) clr )
319+ DeleteObject(hObject ) => DllCall ('Gdi32\DeleteObject', 'ptr', hObject, 'int' )
315320
316- DrawFocusRect(hDC, lprc ) => DllCall (" User32\DrawFocusRect " , " ptr" , hDC, " ptr" , lprc, " int" )
321+ FrameRgn(hdc, hrgn, hbr, nWidth, nHeight ) => DllCall ('Gdi32\FrameRgn', ' ptr', hdc, ' ptr', hrgn, 'ptr', hbr, ' int', nWidth, 'int', nHeight, 'int' )
317322
318323 GetStockObject(fnObject) => DllCall ('Gdi32\GetStockObject', 'int', fnObject, 'ptr')
319324
320- InflateRect(lprc, dx, dy) => DllCall ( " User32\InflateRect " , " ptr " , lprc, " int " , dx, " int " , dy, " int " )
325+ IsColorDark(clr) => ((clr >> 16 & 0xFF ) / 255 * 0.2126 + (clr >> 8 & 0xFF ) / 255 * 0.7152 + (clr & 0xFF ) / 255 * 0.0722 < 0.5 )
321326
322- SetWindowPos(hWnd, hWndInsertAfter, X := 0 , Y := 0 , cx := 0 , cy := 0 , uFlags := 0x40 ) => DllCall ( " User32\SetWindowPos " , " ptr " , hWnd, " ptr " , hWndInsertAfter, " int " , X, " int " , Y, " int " , cx, " int " , cy, " uint " , uFlags, " int " )
327+ RGB(R := 255 , G := 255 , B := 255 ) => ((R << 16 ) | (G << 8 ) | B )
323328
324- SetDCPenColor(hdc, crColor ) => DllCall ('Gdi32\SetDCPenColor', 'ptr', hdc, 'uint', crColor, 'uint' )
329+ RgbToBgr( color ) => (IsInteger( color ) ? (( Color >> 16 ) & 0xFF ) | ( Color & 0x00FF00 ) | (( Color & 0xFF ) << 16 ) : NUMBER( RegExReplace (STRING( color ), " Si)c?(?:0x)?(?<R>\w{2})(?<G>\w{2})(?<B>\w{2}) " , " 0x${B}${G}${R} " )) )
325330
326- SetDCBrushColor (hdc, crColor ) => DllCall ('Gdi32\SetDCBrushColor ', 'ptr', hdc, 'uint ', crColor , 'uint ')
331+ RoundRect (hdc, nLeftRect, nTopRect, nRightRect, nBottomRect, nWidth, nHeight ) => DllCall ('Gdi32\RoundRect ', 'ptr', hdc, 'int ', nLeftRect , 'int', nTopRect, 'int', nRightRect, 'int', nBottomRect, 'int', nWidth, 'int', nHeight, 'int ')
327332
328- SetWindowRgn(hWnd, hRgn, bRedraw ) => DllCall (" User32\SetWindowRgn " , " ptr" , hWnd, " ptr" , hRgn, " int " , bRedraw, " int " )
333+ SelectObject(hdc, hgdiobj ) => DllCall ('Gdi32\SelectObject', ' ptr', hdc, ' ptr', hgdiobj, 'ptr' )
329334
330- DeleteObject (hObject ) {
331- DllCall ('Gdi32\DeleteObject', 'ptr', hObject, 'int')
332- }
335+ SetBkColor(hdc, crColor) => DllCall ('Gdi32\SetBkColor', 'ptr', hdc, 'uint', crColor, 'uint')
333336
334- FillRect(hDC, lprc, hbr ) => DllCall (" User32\FillRect " , " ptr" , hDC, " ptr " , lprc, " ptr " , hbr, " int" )
337+ SetBkMode(hdc, iBkMode ) => DllCall ('Gdi32\SetBkMode', ' ptr', hdc, 'int', iBkMode, ' int' )
335338
336- IsColorDark(clr) =>
337- ( (clr >> 16 & 0xFF ) / 255 * 0.2126
338- + (clr >> 8 & 0xFF ) / 255 * 0.7152
339- + (clr & 0xFF ) / 255 * 0.0722 < 0.5 )
339+ SetDCBrushColor(hdc, crColor) => DllCall ('Gdi32\SetDCBrushColor', 'ptr', hdc, 'uint', crColor, 'uint')
340340
341- RGB(R := 255 , G := 255 , B := 255 ) => ((R << 16 ) | (G << 8 ) | B)
342-
343- BrightenColor(clr, perc := 5 ) => ((p := perc / 100 + 1 ), RGB(Round (Min(255 , (clr >> 16 & 0xFF ) * p)), Round (Min(255 , (clr >> 8 & 0xFF ) * p)), Round (Min(255 , (clr & 0xFF ) * p))))
341+ SetDCPenColor(hdc, crColor) => DllCall ('Gdi32\SetDCPenColor', 'ptr', hdc, 'uint', crColor, 'uint')
344342
345- RoundRect(hdc, nLeftRect, nTopRect, nRightRect, nBottomRect, nWidth, nHeight) => DllCall ('Gdi32\RoundRect', 'ptr', hdc, 'int', nLeftRect, 'int', nTopRect, 'int', nRightRect, 'int', nBottomRect, 'int', nWidth, 'int', nHeight, 'int')
346-
347343 SetTextColor(hdc, color ) => DllCall (" SetTextColor" , " Ptr" , hdc, " UInt" , color )
348-
344+
345+ SetWindowPos(hWnd, hWndInsertAfter, X := 0 , Y := 0 , cx := 0 , cy := 0 , uFlags := 0x40 ) => DllCall (" User32\SetWindowPos" , " ptr" , hWnd, " ptr" , hWndInsertAfter, " int" , X, " int" , Y, " int" , cx, " int" , cy, " uint" , uFlags, " int" )
346+
347+ SetWindowRgn(hWnd, hRgn, bRedraw) => DllCall (" User32\SetWindowRgn" , " ptr" , hWnd, " ptr" , hRgn, " int" , bRedraw, " int" )
348+
349349 SetWindowTheme(hwnd, appName, subIdList?) => DllCall (" uxtheme\SetWindowTheme" , " ptr" , hwnd, " ptr" , StrPtr(appName), " ptr" , subIdList ?? 0 )
350-
351- SelectObject(hdc, hgdiobj) => DllCall ('Gdi32\SelectObject', 'ptr', hdc, 'ptr', hgdiobj, 'ptr')
352-
353- SetBkColor(hdc, crColor) => DllCall ('Gdi32\SetBkColor', 'ptr', hdc, 'uint', crColor, 'uint')
354-
355- SetBkMode(hdc, iBkMode) => DllCall ('Gdi32\SetBkMode', 'ptr', hdc, 'int', iBkMode, 'int')
356350 }
357351}
358352
@@ -361,8 +355,12 @@ myGui := Gui()
361355myGui.SetFont(" cWhite s20" , " Segoe UI" )
362356myGui.BackColor := 0x2c2c2c
363357
358+ btnL := myGui.AddButton(" w300 Background" myGui.BackColor, " Default Button" )
359+ btnD := myGui.AddButton(" wp Background" myGui.BackColor, " Default Button" )
360+ DllCall (" uxtheme\SetWindowTheme" , " ptr" , btnD.hwnd, " ptr" , StrPtr(" DarkMode_Explorer" ), " ptr" , 0 )
361+
364362/** @type {_BtnColor} */
365- btn := myGui.AddButton("w300 ", "Rounded Button")
363+ btn := myGui.AddButton("wp ", "Rounded Button")
366364btn.SetBackColor(0xaa2031,, 9)
367365
368366/** @type {_BtnColor} */
0 commit comments