News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

toolbar.asm

Started by jj2007, May 14, 2015, 10:05:06 PM

Previous topic - Next topic

jj2007

I am studying \Masm32\examples\exampl01\qikpad\toolbar.asm (it's present in various other places, too) trying to understand the SetBmpColor code (shortened with rv):

  mov mDC, rv(CreateCompatibleDC, 0)       ; ------------ SetBmpColor start ------------
  mov hOldBmp, rv(SelectObject, mDC, hTbBmp)
  mov hBrush, rv(CreateSolidBrush, rv(GetSysColor, COLOR_BTNFACE))
  mov hOldBrush, rv(SelectObject, mDC, hBrush)
  invoke ExtFloodFill, mDC, 1, 1, rv(GetPixel,mDC, 1, 1), FLOODFILLSURFACE
  invoke SelectObject, mDC, hOldBrush
  invoke DeleteObject, hBrush
  ; invoke SelectObject, mDC, hTbBmp       ; does that make sense?
  invoke SelectObject, mDC, hOldBmp        ; NEW - necessary?
  invoke DeleteDC, mDC                     ; ------------ SetBmpColor end ------------


It seems the SelectObject hTbBmp can go. Immediately after, the DC gets deleted. The toolbar works fine without it.

dedndave

you select 2 objects into the DC, and save the original values
when done, you should only have to select the 2 original objects before deleting the DC
it is simpler (and probably faster) to use SaveDC and RestoreDC   :biggrin:

https://msdn.microsoft.com/en-us/library/dd162945%28v=vs.85%29.aspx
https://msdn.microsoft.com/en-us/library/dd162929%28v=vs.85%29.aspx

i'm not sure i understand why a brush is selected - it shouldn't be needed for ExtFloodFill
ExtFloodFill uses the color you pass to it, not the currently selected brush

https://msdn.microsoft.com/en-us/library/dd162709%28v=vs.85%29.aspx

and, if you did need a system brush handle, use GetSysColorBrush - the handle need not be deleted
(if you were going to use the handle in WNDCLASSEX, then GetSysColor/CreateSolidBrush would be correct
this is only needed for system colors with index above 18
for 0-18, you can use the color index+1)

https://msdn.microsoft.com/en-us/library/dd144927%28v=vs.85%29.aspx

i often use PatBlt for such operations, which does require a brush   :P
i suspect it's faster than flood fill   :t

https://msdn.microsoft.com/en-us/library/dd162778%28v=vs.85%29.aspx

jj2007

Thanks, Dave. In the meantime, I found a solution that works perfectly and is one third shorter:

push rv(SelectObject, mDC, rv(GetClassLong, hWin, GCL_HBRBACKGROUND))
invoke ExtFloodFill, mDC, 0, 0, rv(GetPixel, mDC, 0, 0), FLOODFILLSURFACE ; get rgb of point 1, 1 in DC and extend it on the whole bitmap
push mDC
call SelectObject ; invoke SelectObject, mDC, hOldBrush