AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

I need a program

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
bradglaser



Joined: 14 Jan 2006
Posts: 3
Location: Tooele, UT

PostPosted: Sat Jan 14, 2006 9:02 pm    Post subject: I need a program Reply with quote

Can someone write me a program so i can draw anywhere on screen like on a powerpoint presentation. I wont need any color besides red. Please make it so i have a pen and a eraser and a erase all functins. Thank you Thank you Thank you. If someone could help me, they'd have my gratitude
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
shimanov



Joined: 25 Sep 2005
Posts: 612

PostPosted: Sat Jan 14, 2006 11:28 pm    Post subject: Reply with quote

Enjoy!

mouse movement = draw/erase

F1 = toggle draw/erase
F2 = erase all
F12 = exit

Code:

CoordMode, Mouse, Screen


Process, Exist
pid_this := ErrorLevel

hdc_screen := DllCall( "GetDC", "uint", 0 )

hdc_buffer := DllCall( "CreateCompatibleDC", "uint", hdc_screen )
hbm_buffer := DllCall( "CreateCompatibleBitmap", "uint", hdc_screen, "int", A_ScreenWidth, "int", A_ScreenHeight )
DllCall( "SelectObject", "uint", hdc_buffer, "uint", hbm_buffer )

DllCall( "BitBlt", "uint", hdc_buffer, "int", 0, "int", 0, "int", A_ScreenWidth, "int", A_ScreenHeight, "uint", hdc_screen, "int", 0, "int", 0, "uint", 0x00CC0020 )

Gui, +AlwaysOnTop -Caption
Gui, Show, x0 y0 w%A_ScreenWidth% h%A_ScreenHeight%

WinGet, hw_canvas, ID, ahk_class AutoHotkeyGUI ahk_pid %pid_this%

hdc_canvas := DllCall( "GetDC", "uint", hw_canvas )

DllCall( "BitBlt", "uint", hdc_canvas, "int", 0, "int", 0, "int", A_ScreenWidth, "int", A_ScreenHeight, "uint", hdc_buffer, "int", 0, "int", 0, "uint", 0x00CC0020 )

mode_draw := true

WM_MOUSEMOVE = 0x0200
OnMessage( WM_MOUSEMOVE, "HandleMessage" )
return

HandleMessage( p_w, p_l )
{
   global   mode_draw, hdc_canvas, hdc_buffer

   x := p_l & 0xFFFF
   y := p_l >> 16

   if ( mode_draw )
      color = 0xFF

   else
      color := DllCall( "GetPixel", "uint", hdc_buffer, "int", x, "int", y )
   
   DllCall( "SetPixel", "uint", hdc_canvas, "int", x, "int", y, "uint", color )
}

F1::
   mode_draw := !mode_draw
return

F2::
   DllCall( "BitBlt", "uint", hdc_canvas, "int", 0, "int", 0, "int", A_ScreenWidth, "int", A_ScreenHeight, "uint", hdc_buffer, "int", 0, "int", 0, "uint", 0x00CC0020 )
return

F12::ExitApp
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Sun Jan 15, 2006 3:35 am    Post subject: Reply with quote

Nice drawing demonstration. Just a few strokes of the mouse cursor to vandalize your desktop. Then put it back to normal simply by pressing F2!
Back to top
View user's profile Send private message Send e-mail
shimanov



Joined: 25 Sep 2005
Posts: 612

PostPosted: Sun Jan 15, 2006 3:49 am    Post subject: Reply with quote

Chris wrote:
vandalize your desktop


Well, a copy anyway. I don't condone malicious behavior.

Fun, isn't it?!
Back to top
View user's profile Send private message
BoBo
Guest





PostPosted: Sun Jan 15, 2006 11:49 am    Post subject: Reply with quote

Very nice & usefull - what should I say more. Very Happy
Thx for sharing it + please push a copy of this marvelous piece of code to the Script Section of the Forum (if not done already).

Cool
Back to top
JSLover



Joined: 20 Dec 2004
Posts: 542
Location: LooseChange911.com... the WTC attacks were done by the US Gov't... the official story is a lie...

PostPosted: Sun Jan 15, 2006 4:19 pm    Post subject: Reply with quote

Chris wrote:
Nice drawing demonstration.

...I figured it'd be cool, then ran it...WHOA!...small drawing, 1 pixel at a time...I can barely see it...nice code, but too small of drawing...my edits...

Find...

Code:
CoordMode, Mouse, Screen

Before, Add...

Code:
DrawSize=19

Find...

Code:
HandleMessage( p_w, p_l )
{
; entire function
}

Replace With...

Code:
HandleMessage( p_w, p_l )
{
   global   mode_draw, hdc_canvas, hdc_buffer, DrawSize

   x := p_l & 0xFFFF
   y := p_l >> 16

   x-=(DrawSize/2)
   y-=(DrawSize/2)

   x_orig:=x
   y_orig:=y

   SetBatchLines, -1
   Loop, %DrawSize%
   {
      Loop, %DrawSize%
      {
         if ( mode_draw )
            color = 0xFF

         else
            color := DllCall( "GetPixel", "uint", hdc_buffer, "int", x, "int", y )

         DllCall( "SetPixel", "uint", hdc_canvas, "int", x, "int", y, "uint", color )
         y++
      }
      x++
      y:=y_orig
   }
}

...I'm sure it'd be faster to use FillRect & CopyRect, but I didn't wanna delve into that yet (structures!...I'm sure a rect structure is simple & there's even code in the help file, but I'm already beating myself in the head over a different {not simple} structure problem).

Code:
   x := p_l & 0xFFFF
   y := p_l >> 16

...how on God's Earth, did you figure out THAT would get the x & y...I'm sure if I go to the MSDN on WM_MOUSEMOVE it won't tell me I need to do that to get the params outta it, it'd probably tell me it's a POINT structure (structure! ugh!)...then I'd go down the entire structure route & you get what you need with some weird math...can you please help me understand what that does, why it works?!? I've never understood the << >> (left shift / right shift) stuff.
_________________

Home • Click image! • Blog
Back to top
View user's profile Send private message Visit poster's website
bradglaser



Joined: 14 Jan 2006
Posts: 3
Location: Tooele, UT

PostPosted: Sun Jan 15, 2006 10:14 pm    Post subject: Reply with quote

Thx ya'll it's fun
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
shimanov



Joined: 25 Sep 2005
Posts: 612

PostPosted: Sun Jan 15, 2006 11:36 pm    Post subject: Reply with quote

to BoBo:

Thanks. It is only a demonstration in answer to bradglaser's request. Even less ready for prime time, than some of my other contributions. If you enjoy graphics, then you could use it as a springboard to develop something truly useful for the general populace.

to JSLover:


Quote:
x := p_l & 0xFFFF
y := p_l >> 16

help me understand what that does


p_l is a packed variable of size four bytes (or 32 bits). Packed in the sense that the bottom (least significant) two bytes contain the x coordinate, and the top (most significant) two bytes contain the y coordinate. In pseudo-hex notation, it would be
    0xYYYYXXXX


where each X (or Y) is 4 bits (a nibble) and XX (or YY) is 8 bits (a byte). The bit operators, >> (shift right) and & (and), enable operations on bits. In our case:
    0xYYYYXXXX & 0xFFFF = 0xXXXX


thereby isolating the bottom two bytes, or the x coordinate; and,

    0xYYYYXXXX >> 16 = 0xYYYY


thereby isolating the top two bytes, or the y coordinate in our case.

For more information check the bitwise operation page at Wikipedia.
Back to top
View user's profile Send private message
dosenfleisch
Guest





PostPosted: Mon Jan 16, 2006 11:44 am    Post subject: Reply with quote

very nice program!!

on windows me it locks the desktop.
Back to top
shimanov



Joined: 25 Sep 2005
Posts: 612

PostPosted: Mon Jan 16, 2006 8:50 pm    Post subject: Reply with quote

dosenfleisch wrote:
on windows me it locks the desktop


I am not sure what you mean by "lock", but it does create an "AlwaysOnTop" window with the dimensions of the screen. An image of the screen's contents are copied into that window, so you are not interacting with the desktop or task bar, but a static facsimile. Press F12 to exit the script and close the corresponding window, which will reveal the actual desktop.
Back to top
View user's profile Send private message
JSLover



Joined: 20 Dec 2004
Posts: 542
Location: LooseChange911.com... the WTC attacks were done by the US Gov't... the official story is a lie...

PostPosted: Tue Jan 17, 2006 10:19 am    Post subject: Reply with quote

shimanov wrote:
    0xYYYYXXXX & 0xFFFF = 0xXXXX
    0xYYYYXXXX >> 16 = 0xYYYY

...thanks that helped...I did some testing in JavaScript...
    '0x'+(0x12345678 & 0xffff).toString(16)=0x5678
    '0x'+(0x12345678 & 0x0000ffff).toString(16)=0x5678

    '0x'+(0x12345678 & 0xffff0000).toString(16)=0x12340000
    '0x'+(0x12345678 >> 16).toString(16)=0x1234

    '0x'+(0x12345678 << 16).toString(16)=0x56780000
    '0x'+(0x12345678 << 16 >> 16).toString(16)=0x5678

    '0x'+(0x12345678 >> 16 << 16).toString(16)=0x12340000
...(you have to paste the part before = inside an alert())...
    0x12345678 & 0xffff
...&...
    0x12345678 << 16 >> 16
...both get 0x5678 which I thought was interesting. I still don't know why &'ing with 0xffff works & 0x0000 or 0x1111 don't...0xffff is magic?
_________________

Home • Click image! • Blog
Back to top
View user's profile Send private message Visit poster's website
shimanov



Joined: 25 Sep 2005
Posts: 612

PostPosted: Tue Jan 17, 2006 6:01 pm    Post subject: Reply with quote

JSLover wrote:
I still don't know why &'ing with 0xffff works & 0x0000 or 0x1111 don't...0xffff is magic?


& truth table:

0&0 = 0
0&1 = 0
1&0 = 0
1&1 = 1

to isolate first 4 bits (least significant):

0xF = 1111b (binary)

value & 0xF

example:

0xFA = 250 (decimal) = 11111010b (binary)

0xA = 10 = 1010b

0xFA & 0xF = 11111010b & 00001111b = [1&0][1&0][1&0][1&0][1&1][0&1][1&1][0&1]b = 1010b = 0xA
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group