Draw on Desktop

Just starting out? Need help? Post your questions and find answers here.
Vater
User
User
Posts: 18
Joined: Fri Dec 17, 2004 8:52 am

Draw on Desktop

Post by Vater »

Hello NG,

I try to draw a rectangle directly on the Desktop with the following Function

Code: Select all

Procedure DrawRectOnScreen()
  CallDebugger
  ;Draw on Screen
  lngDC.l = 0
  lngPen.l = 0
  lngRetValue.l = 0
  ;Get The Desktop DC 
  lngDC = GetDesktopWindow_()
  Debug lngDC
  ;Create a new solid Pen, Width 5, Color Blue
  lngPen = createPen_(#PS_SOLID, 5, RGB(192,214,20))
  Debug lngPen
  
  If lngDC <> 0 And lngPen <> 0

    structRect.RECT
    structRect\right = 500
    structRect\left = 500
    structRect\bottom = 500
    structRect\top = 500
    
    ;Draw the Rectangle on Desktop
    lngRetValue = rectangle_(lngDC, structRect\right, structRect\left, structRect\bottom, structRect\top)
    Debug lngRetValue

  EndIf
  
  ;Free Memory
  deleteObject_(lngPen)

EndProcedure
This is not working and I got no idea why.

Thanks in advance for your help
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Post by DarkDragon »

Well, I modified a short code from the codearchiv:

Code: Select all

; www.purearea.net (Sourcecode collection by cnesm)
; Author:
; Date: 22. November 2003

; A bit modified by DarkDragon ;) 

#wMem=0 
Global Mem.l 
Mem = AllocateMemory(1024) 

Procedure.l DesktopOutput() 
  PokeL(Mem, 1) 
  ProcedureReturn Mem 
EndProcedure 

Maus.Point 

Repeat
  StartDrawing(DesktopOutput()) 
    Box(200, 200, 300, 300, RGB(255, 0, 0))
  StopDrawing() 
  
  Delay(5) 
  If GetAsyncKeyState_(#VK_ESCAPE) 
    Quit = 1 
  EndIf 
  
Until Quit 
InvalidateRect_(0, 0, 0) 
End 

; ExecutableFormat=Windows
; EOF
bye,
Daniel
Vater
User
User
Posts: 18
Joined: Fri Dec 17, 2004 8:52 am

Thanks

Post by Vater »

Thanks for the quick answer, what I do not understand is the DesktopOutput Procedure, is this the DC for the Desktop???

Stefan
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Post by DarkDragon »

No, that's the output ID for the Startdrawing command. And StartDrawing returns the DC.

In your code:
lngDC = GetDesktopWindow_()
GetDesktopWindow_() returns the handle to the Desktop, not the DC so you must use GetDC or CreateCompatibleDC and a ReleaseDC for that Desktop handle
bye,
Daniel
Post Reply