Draw to the desktop =D

Share your advanced PureBasic knowledge/code with the community.
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Draw to the desktop =D

Post by josku_x »

Hello people!

I have now finished my "draw-to-desktop" code.

And here it is (This is updated code, so it should work):

Code: Select all

Global Memory 
Memory = AllocateMemory(1024) 

Procedure DesktopOutput() 
  PokeL(Memory, 1) 
  ProcedureReturn Memory 
EndProcedure 

StartDrawing(DesktopOutput()) 
 Locate(130,100)
 DrawText("See, you can draw to the desktop very easily.. to exit this program, press Escape on your keyboard.")
 Ellipse(150,200,70,70,RGB(0,50,100))
 Ellipse(350,200,70,70,RGB(0,50,100))
 Ellipse(550,200,70,70,RGB(0,50,100))
 Ellipse(750,200,70,70,RGB(0,50,100))
StopDrawing() 

Repeat 
Delay(5) ; Delay for CPU's health =D 

If GetAsyncKeyState_(#VK_ESCAPE) 
  Quit = 1 ; If ESCAPE button is pushed, then quit. 
EndIf 
  
Until Quit 
InvalidateRect_(0, 0, 0) ; Redraw the desktop. 
End
I made this for roachofdeath, but I see that it belongs here.

And here is an example to draw a plot in the mouse position (made by request):

Code: Select all

Global Memory 
Memory = AllocateMemory(1024) 

If InitMouse() = 0 
  MessageRequester("Error", "Can't use mouse.", #MB_ICONERROR) 
  End 
EndIf 

Procedure DesktopOutput()
  PokeL(Memory, 1) 
  ProcedureReturn Memory 
EndProcedure

Repeat 
ExamineMouse() ; Needed to update the MouseX() and MouseY() values. 

StartDrawing(DesktopOutput()) 
  Plot(DesktopMouseX(),DesktopMouseY(),RGB(0,50,100)) 
StopDrawing()  ; As you see the drawing operations are inside the Repeat loop. 

Delay(5) ; Delay for CPU's health =D 

If GetAsyncKeyState_(#VK_ESCAPE) 
  Quit = 1 ; If ESCAPE button is pushed, then quit. 
EndIf 
  
Until Quit 
InvalidateRect_(0, 0, 0) ; Redraw the desktop. 
End
Have fun.
Last edited by josku_x on Tue Nov 29, 2005 5:22 pm, edited 8 times in total.
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

I get an error: Line 4 - Specified address is null

Code: Select all

 PokeL(Memory, 1) 
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

GeoTrail wrote:I get an error: Line 4 - Specified address is null

Code: Select all

 PokeL(Memory, 1) 
I believe you have to make the variable global.
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

Maybe this works? (I updated the first post, so now it has the right code.)

Code: Select all

Global Memory
Memory = AllocateMemory(1024) 

;Procedure DesktopOutput() - Just incase you need this. 
;  PokeL(Memory, 1) 
;  ProcedureReturn Memory 
;EndProcedure 

StartDrawing(DesktopOutput()) 
; Drawing code goes here. 
StopDrawing() 

Repeat 
Delay(5) ; Delay for CPU's health =D 

If GetAsyncKeyState_(#VK_ESCAPE) 
  Quit = 1 ; If ESCAPE button is pushed, then quit. 
EndIf 
  
Until Quit 
InvalidateRect_(0, 0, 0) ; Redraw the desktop. 
End
It's as rsts said, I forgot to make the variable Global. thanks for reminding!
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

Works fine now ;)
Pretty funny, can use the draw mouse thing to scare people, you can say it's a virus or something :lol: And they must pay to get help removing it :twisted:
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

:? :? :? What's the deal with this? Get codearchiv:

Code: Select all

; www.purearea.net (Sourcecode collection by cnesm)
; Author:  (updated for PB3.93 by ts-soft)
; Date: 22. November 2003

Global mem.l 
; hier werden 1024 byte speicher reserviert 
mem = AllocateMemory(1024) 

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

Maus.POINT 

Repeat 
  ; hier werden die maus koordinaten ausgelesen 
  GetCursorPos_(Maus) 
  ; 
  ; hier beginnt die verwirrung 
  StartDrawing(DesktopOutput()) 
    Plot(Maus\x, Maus\y, $0000FF) 
  StopDrawing() 
  ; 
  ; delay für cpu entlastung 
  Delay(5) 
  ; hier wird die escape taste geprüft 
  If GetAsyncKeyState_(#VK_ESCAPE) 
    Quit = 1 
  EndIf 
  
Until Quit 
InvalidateRect_(0, 0, 0) 
End  
; jaPBe Version=2.5.4.22
; Build=0
; FirstLine=0
; CursorPosition=18
; ExecutableFormat=Windows
; DontSaveDeclare
; EOF
Rip off?
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

GeoTrail wrote:Works fine now ;)
Pretty funny, can use the draw mouse thing to scare people, you can say it's a virus or something :lol: And they must pay to get help removing it :twisted:
That's funny! I laughed for that about 10 minutes :lol: :D ...

dagcrack wrote: :? :? :? What's the deal with this? Get codearchiv:
well, dagcrack, maybe there is similar code to do that in the codearchiv, but that doesn't count! This counts here, because I needed a half-hour to do this, it was hard first to do the DesktopOutput procedure, and after it was completed I tried very much to do things right, because I was afraid something could happen to my PC. After I saw it kills my CPU, I wanted to stop working on it, but when it was just to use Delay(5), then the show began :) ... Also, while I was experimenting the Win32 API, I found the InvalidateRect_() procedure which refreshes the determined area.. So what I mean is, that I made much work to do this.

Code: Select all

PS: Updated code! Check the first code snippet in my first post. lol.
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

josku_x wrote:PS: Updated code! Check the first code snippet in my first post. lol.
If you add a message to be written on the desktop that says something like "Microsoft Windows XP Beta 1. Will expire in 2 days" you could also get a cheap laugh hehehe ;)
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

GeoTrail wrote:
josku_x wrote:PS: Updated code! Check the first code snippet in my first post. lol.
If you add a message to be written on the desktop that says something like "Microsoft Windows XP Beta 1. Will expire in 2 days" you could also get a cheap laugh hehehe ;)
Guess what ill send you for xmas :twisted:
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

thefool wrote:Guess what ill send you for xmas :twisted:
Xbox 360? :lol:
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

hah in your dreams :P
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

Ok ok, how about a PSP instead then? :P
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

give me your adress and ill send a real nice letterbomb!
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

OK, but it's just gonna get stamped with Return to sender :lol:
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post by thefool »

:lol:
Post Reply