AutoHotkey Community

It is currently May 27th, 2012, 10:43 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: February 10th, 2008, 11:26 pm 
Offline

Joined: June 26th, 2006, 6:14 pm
Posts: 1379
Location: USA
This is another proof of concept script. Color Dialog found on forum.
Have fun.

Code:
SetBatchLines -1
SetWinDelay -1
#NoEnv

Gui, +LastFound ; +AlwaysOnTop +ToolWindow
Gui, Add, GroupBox, x6 y40 w320 h310 , My Picture
Gui, Add, ComboBox, x46 y10 w90 h20 vPen_Size gPenSize r5, 1|2|3|4||5|6|7|8|9|10
Gui, Add, Text, x16 y10 w30 h20 , Size:
Gui, Add, Button, x146 y10 w60 h20 gPickColor, Pick Color
;Gui, Add, Button, x216 y10 w60 h20 , Save File
Gui, Add, Text, x16 y60 w300 h280 +Border hwndhCanvas +0x2000000 +0x6 +0x1000 ;+0x12
Gui, Show, , AHK Paint
Size := 200
WinSet, Trans, 255
hGui := WinExist()
hDc := DllCall("GetDC", "uint", hCanvas)
Selected_Color := 0x0
CoordMode, Mouse, Relative
SysGet, SM_CXBORDER, 5
SysGet, SM_CYBORDER, 6
SysGet, SM_CYCAPTION, 4
WindowProcNew := RegisterCallback("WindowProc", ""  ; "" to avoid fast-mode for subclassing.
    , 4, hGui)  ; Must specify exact ParamCount when EventInfo parameter is present.
WindowProcOld := DllCall("SetWindowLong", UInt, hGui, Int, -4  ; -4 is GWL_WNDPROC
    , Int, WindowProcNew, UInt)  ; Return value must be set to UInt vs. Int.

ControlGetPos, Canvas_x, Canvas_y, , , ,ahk_id %hCanvas%

;Return

PenSize:
Gui, Submit, NoHide
return


#z::
PickColor:
Selected_Color:=ColorPicker(hGui)
return
WindowProc(hwnd, uMsg, wParam, lParam)
   {
    Global
   Critical
   If LButton {
      MouseGetPos, x1, y1, , hControl, 2
      If !(hControl = hCanvas) or ( (Oldx1 = x1) and (Oldy1 = y1) )
         return DllCall("CallWindowProcA", UInt, WindowProcOld, UInt, hwnd, UInt, uMsg, UInt, wParam, UInt, lParam)
      Count++
      hPen := DllCall("CreatePen", "UInt", 0, "UInt", Pen_Size, "UInt", Selected_Color)
      hOldObject := DllCall("SelectObject", "UInt", hDc, "UInt", hPen)
      DllCall("Ellipse", "uint", hDc, "int", x1-Canvas_x-1, "int", y1-Canvas_y+1, "int", x1-Canvas_x, "int", y1-Canvas_y)
      ;Select the old oject back into the DC.
      DllCall("SelectObject", "UInt", hDc, "UInt", hOldObject)
      ;Delete the pen that is no longer needed
      DllCall("DeleteObject", "UInt", hPen)
      Oldx1 := x1
      Oldy1 := y1
      }
    return DllCall("CallWindowProcA", UInt, WindowProcOld, UInt, hwnd, UInt, uMsg, UInt, wParam, UInt, lParam)
   }

BGRtoRGB(oldValue)
{
  Value := (oldValue & 0x00ff00)
  Value += ((oldValue & 0xff0000) >> 16)
  Value += ((oldValue & 0x0000ff) << 16)
  return Value
}

ColorPicker(OwnerGui,CurrentHexColor="")
{

SizeOfStructForChooseColor = 0x24
VarSetCapacity(StructForChooseColor, SizeOfStructForChooseColor, 0)
VarSetCapacity(StructArrayForChooseColor, 64, 0)
NumPut(SizeOfStructForChooseColor, StructForChooseColor, 0)  ; DWORD lStructSize
NumPut(OwnerGui, StructForChooseColor, 4)  ; HWND hwndOwner (makes dialog "modal").
NumPut(0x0 ,    StructForChooseColor, 8)  ; HINSTANCE hInstance
NumPut(0x0 ,    StructForChooseColor, 12)  ; clr.rgbResult =  0;
NumPut(&StructArrayForChooseColor , StructForChooseColor, 16)  ; COLORREF *lpCustColors
NumPut(0x00000100 , StructForChooseColor, 20)  ; Flag: Anycolor
NumPut(0x0 ,    StructForChooseColor, 24)  ; LPARAM lCustData
NumPut(0x0 ,    StructForChooseColor, 28)  ; LPCCHOOKPROC lpfnHook
NumPut(0x0,    StructForChooseColor, 32)  ; LPCTSTR lpTemplateName

nRC := DllCall("comdlg32\ChooseColorA", str, StructForChooseColor)  ; Display the dialog.
if (errorlevel <> 0)
{
   MsgBox error while calling ChooseColor Errorlevel: %errorlevel% - RC: %nRC%
   return
}
If (nRC = 0)
 return -1
; Otherwise, the user pressed OK in the dialog, so determine what was selected.
;GuiControl,, Color, % BGRtoRGB(ExtractInteger(StructForChooseColor, 12))
SetFormat, integer, hex  ; Show RGB color extracted below in hex format.
return NumGet(StructForChooseColor, 12)
}

   
   
~Lbutton::
MouseGetPos, , , , hButtonDownControl, 2
If (hButtonDownControl = hCanvas) {
   LButton++
   Break=
   }
Return
~Lbutton Up::LButton:="", Break := 1

esc::exitapp


_________________
Image
ʞɔпɟ əɥʇ ʇɐɥʍ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 11th, 2008, 12:11 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
This is not new - others before you have created similar paint like scripts. It's good to see new methods such as your WindowProc being used though. I know you cleverly labelled this as a PoC but I noticed a bug: the mouse capturing frequency is too low.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 23rd, 2008, 8:48 am 
Offline

Joined: July 12th, 2007, 10:24 pm
Posts: 103
Location: Hawaii, USA
Hey, I think this is pretty nifty! AHKLearner, is there any sort of way to extend this, so I can save the drawing to a PNG or something? :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 25th, 2008, 7:05 am 
Offline

Joined: November 10th, 2006, 5:10 am
Posts: 110
very neat ! Certainly shows AHK is "almost" limitless.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 18 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group