hDC, Brush etc.

Windows specific forum
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

hDC, Brush etc.

Post by freedimension »

Is there a way of getting the current hDC, Brush, Color etc. inside of StartDrawing ... StopDrawing.

As for the hDC, I know that StartDrawing returns this one, but I want to be independent of this function.
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

From the LibrarySDK:
_PB_2DDrawing_CurrentDC ; OS Current DC (HDC)
_PB_2DDrawing_CurrentColor ; Current RGB 24 color
_PB_2DDrawing_CurrentMode ; Current drawing mode (Set by DrawingMode())
_PB_2DDrawing_Brush ; Current brush (for flood fill), set by FrontColor() (HBRUSH)
_PB_2DDrawing_Pen ; Current pen (for outline color), set by FrontColor() (HPEN)
You should easily be able to access these with !extrn

Timo
quidquid Latine dictum sit altum videtur
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post by freedimension »

Yes, found this one too, but I don't have the asm-skills, needed to do so.
Any chance of getting a lection on asm from a real FREAK ;-) :?:
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post by freedimension »

After all it wasn't that hard:

Code: Select all

Procedure GetHDC()
  !EXTRN _PB_2DDrawing_CurrentDC
  !MOV EAX, dword [_PB_2DDrawing_CurrentDC]
  ProcedureReturn
EndProcedure
Thanx a lot
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Code: Select all

CurrentDC.l
!extrn  _PB_2DDrawing_CurrentDC
!mov eax, [_PB_2DDrawing_CurrentDC]
!mov [v_CurrentDC], eax
The current dc is now in CurrentDC.l
Note: this only works outside of a procedure or with global variables.

This one also works inside: needs InlineASM to be on:

Code: Select all

CurrentDC.l
!extrn  _PB_2DDrawing_CurrentDC
MOV eax, [_PB_2DDrawing_CurrentDC]
MOV CurrentDC, eax
In both cases, the variable needs to be declared before being used from asm.

I like this solution best: a little procedure:

Code: Select all

Procedure GetCurrentDC()
  !extrn _PB_2DDrawing_CurrentDC
  !mov eax, [_PB_2DDrawing_CurrentDC]
  ProcedureReturn
EndProcedure
This works the same with all those valued.

Timo


[edit]too slow... :wink: [/edit]
quidquid Latine dictum sit altum videtur
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post by freedimension »

freak wrote: [edit]too slow... :wink: [/edit]
No, you helped me a lot, really.
Especially because of this:

Code: Select all

This one also works inside: needs InlineASM to be on:
CurrentDC.l
!extrn  _PB_2DDrawing_CurrentDC
MOV eax, [_PB_2DDrawing_CurrentDC]
MOV CurrentDC, eax
I tried to figure this one out but came to no conclusion.
Post Reply