Author Topic: toolbar.asm  (Read 3462 times)


  • Member
  • *****
  • Posts: 11526
  • Assembler is fun ;-)
    • MasmBasic
« on: May 14, 2015, 10:05:06 PM »
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.


  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: toolbar.asm
« Reply #1 on: May 15, 2015, 02:43:27 AM »
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:

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

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)

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


  • Member
  • *****
  • Posts: 11526
  • Assembler is fun ;-)
    • MasmBasic
Re: toolbar.asm
« Reply #2 on: May 15, 2015, 03:13:45 AM »
Thanks, Dave. In the meantime, I found a solution that works perfectly and is one third shorter:

Code: [Select]
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