November 25, 2020, 07:55:51 AM

Author Topic: [bb] skinnable windows by dan_upright [ 1+ years ago ]  (Read 523 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] skinnable windows by dan_upright [ 1+ years ago ]
« on: June 29, 2017, 12:28:39 AM »
Title : skinnable windows
Author : dan_upright
Posted : 1+ years ago

Description : setup the two .decls files and then pass the function your window handle, an image (which should be the same size as the window) and a mask colour and it'll make the window shape match the non-masked areas of the image

Code :
Code: BlitzBasic
  1. user32.decls:
  2. ----
  3. .lib "user32.dll"
  4.  
  5. SetWindowRgn%(hWnd%, hRgn%, bRedraw%)
  6. ----
  7.  
  8. gdi32.decls:
  9. ----
  10. .lib "gdi32.dll"
  11.  
  12. CreateRectRgn%(X1%, Y1%, X2%, Y2%)
  13. CombineRgn%(hDestRgn%, hSrcRgn1%, hSrcRgn2%, nCombineMode%)
  14. DeleteObject%(hObject%)
  15. ----
  16.  
  17. and the blitz function:
  18. ----
  19. Function skin_window(window, img, r, g, b)
  20.  
  21.         w = ImageWidth(img)
  22.         h = ImageHeight(img)
  23.         LockBuffer ImageBuffer(img)
  24.         mask = (255 Shl 24) + (r Shl 16) + (g Shl 8) + b
  25.  
  26.         hWnd = QueryObject(window, 1)
  27.         hRgn = CreateRectRgn(0, 0, w, h)
  28.         For y = 0 To h - 1
  29.                 For x = 0 To w - 1
  30.                         pixel = ReadPixelFast(x, y, ImageBuffer(img))
  31.                         If pixel = mask
  32.                                 hTempRgn = CreateRectRgn(x, y, x + 1, y + 1)
  33.                                 CombineRgn(hRgn, hRgn, hTempRgn, 3)
  34.                                 DeleteObject(hTempRgn)
  35.                         EndIf
  36.                 Next
  37.         Next
  38.         UnlockBuffer ImageBuffer(img)
  39.        
  40.         SetWindowRgn(hWnd, hRgn, True)
  41.         DeleteObject(hRgn)
  42.  
  43. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal