AutoHotkey Community

It is currently May 26th, 2012, 12:58 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 59 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
PostPosted: December 6th, 2008, 9:06 pm 
Offline

Joined: August 24th, 2005, 5:29 pm
Posts: 549
Location: Berlin / Germany
Anonymous wrote:
nick wrote:
Coloured Buttons with GDI+

Or if you would like colored buttons (and most other controls like edit,text, checkbox, and radio) with much simpler (and smaller) code see this post by DerRaphael:Colored Controls (no bitmaps needed)


Where are the Buttons?

_________________
nick :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 6th, 2008, 9:30 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Raph, very nicely done. It looks very professional.

Nick, I think it would be easier to use Gdip_TextToGraphics? Lemme know what you think


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 6th, 2008, 9:44 pm 
Offline

Joined: August 24th, 2005, 5:29 pm
Posts: 549
Location: Berlin / Germany
Moin tic,

the problem was: How to VCENTER text in a button.

Gdip_TextToGraphics calls Gdip_MeasureString, but it draws the text without checking the result.

_________________
nick :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 23rd, 2008, 10:05 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
nick wrote:
Moin tic,

the problem was: How to VCENTER text in a button.

Gdip_TextToGraphics calls Gdip_MeasureString, but it draws the text without checking the result.


I took your suggestion seriously nick and have added vcentre to the library. Thank you for your input


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 28th, 2008, 10:05 pm 
Offline

Joined: July 26th, 2006, 8:50 pm
Posts: 68
Location: Wuppertal
COLOURlovers screensaver

Image

My first take on GDI+:
It downloads and displays the top-rated palettes from colourlovers.com. After each drawn palette, it increments the palette offset and repeats.

- Press F1 to switch off the circles
- Press F2 to switch off the text
- Press F3 to show some debug tooltips
- Press CTRL+S to save the current image to the Desktop (CL.png) and exit
- Press SPACE to set the current image as wallpaper and exit

The Code:
Code:
; ++++++++++++++++++++++++++++++++++++++++ Setup

#Persistent
#SingleInstance, Force
#NoEnv
SetBatchLines, -1
SetWorkingDir, %A_ScriptDir%

; ++++++++++++++++++++++++++++++++++++++++

OnExit, Exit
Delimiter := ","
Offset = 0
Circles := Text := 1
Tips = 0
WinWidth := A_ScreenWidth
WinHeight := A_ScreenHeight

; ++++++++++++++++++++++++++++++++++++++++ Start

If Tips
   ToolTip, Start!

If pToken := Gdip_Startup()
{
   GDIP_RegisterClass(),
   hwnd1 := GDIP_CreateWindow()
}
Else
   ExitApp
   
; Prepare the Canvas
hBitmap := CreateDIBSection(WinWidth, WinHeight)
hDC := CreateCompatibleDC()
obm := SelectObject(hDC, hBitmap)
G := Gdip_GraphicsFromhDC(hDC)

If Tips
   ToolTip, Setting timer!
GoSub, Draw
SetTimer, Draw, 4000
Return

; ++++++++++++++++++++++++++++++++++++++++ Draw

Draw:
   If Tips
      ToolTip, Draw!
   
   If Tips
      ToolTip, Getting palette!
   Palette := GetCL_Palette("TOP", Offset)
   
   Alpha := Dec2Hex("255")
   StringSplit, Colour_, Palette, %Delimiter%, %Delimiter%
   RectWidth := Ceil(WinWidth / (Colour_0 - 1))
   
   Gdip_SetSmoothingMode(G, 0)
   Loop % Colour_0-1 ;%
   {
      i := A_Index + 1
      pBrush := Gdip_BrushCreateSolid(Alpha Colour_%i%)
      Gdip_FillRectangle(G, pBrush, xPos, 0, RectWidth, WinHeight)
      xPos += RectWidth
   }
   
   If Tips
      ToolTip, Drawn BG!
   Gdip_DeleteBrush(pBrush)
   xPos = 0
   Offset++
   
   If Circles
   {
      Gdip_SetSmoothingMode(G, 2)
      Loop 500
      {
         Random, RandColor, 2, %Colour_0%
         Random, RandSize, 2, % WinHeight / 8 ;%
         Random, RandXPos, 0, %WinWidth%
         Random, RandYPos, 0, %WinHeight%
         Random, RandAlpha, 255, 255
         
         pBrush := Gdip_BrushCreateSolid(Dec2Hex(RandAlpha) Colour_%RandColor%)
         Gdip_FillEllipse(G, pBrush, RandXPos, RandYPos, RandSize, RandSize)
      }
      If Tips
         ToolTip, Drawn circles!
   }
   
   Options := "x20 y" (WinHeight - 55) "c" SubStr(Dec2Hex("200"), 3) "ffffff" " r4 s30"
   
   If Text
   {
      Gdip_SetSmoothingMode(G, 4)
      pBrush2 := Gdip_BrushCreateSolid(0xffff0000)
      pBrush3 := Gdip_BrushCreateSolid(Dec2Hex("200") "000000")
      RectF := Gdip_TextToGraphics(G, Colour_1 "`n" Chr(160), Options, "Arial", WinWidth, WinHeight, 1)
      If Tips
         ToolTip, %RectF%
      StringSplit, RectF_, RectF, |, |
      
      Gdip_FillRoundedRectangle(G, pBrush3, RectF_1, RectF_2, RectF_3, RectF_4/2, 4)
      Gdip_TextToGraphics(G, Colour_1 "`n" Chr(160), Options, "Arial", WinWidth, WinHeight)
   }

   
   UpdateLayeredWindow(hwnd1, hDC, 0, 0, WinWidth, WinHeight)
Return

; ++++++++++++++++++++++++++++++++++++++++ Functions

DrawCL_Palette(Palette, Delimiter = ",", Alpha = "255")
{
   Alpha := Dec2Hex(Alpha)
   StringSplit, Colour_, Palette, %Delimiter%, %Delimiter%
   RectWidth := Ceil(WinWidth / Colour_0)
   
   Loop %Colour_0%
   {
      pBrush := Gdip_BrushCreateSolid(Alpha Colour_%A_Index%)
      Gdip_FillRectangle(G, pBrush, xPos, 0, RectWidth, WinHeight)
      xPos += RectWidth
   }
   Gdip_DeleteBrush(pBrush)
}

; ++++++++++++++++++++++++++++++++++++++++

GetCL_Palette(Type = "TOP", Offset = "0")
{
   global Delimiter
   If (Type = "Top")
      URL = http://www.colourlovers.com/api/palettes/top&numResults=1&resultOffset=%Offset%
   If (Type = "RAND")
      URL = http://www.colourlovers.com/api/palettes/random
   
   ; URL = http://www.colourlovers.com/api/palettes/top&keywordExact=0&keywords=dark&numResults=1&resultOffset=%Offset%
   
   httpQuery(html, URL, POSTdata)
   VarSetCapacity(html, -1)

   RegExMatch(html, "iS)\Q<title><![CDATA[\E(.+?)\Q]]></title>\E", titleNode)
   RegExMatch(html, "iS)\Q<userName><![CDATA[\E(.+?)\Q]]></userName>\E", userNameNode)
   
   Loop, Parse, html, `n, `n
   {
      RegExMatch(A_LoopField, "iS)<hex>(.+?)</hex>", hexNode)
      If hexNode
         Output .= hexNode1 Delimiter
      If InStr(A_LoopField, "</palette>")
         Output .= "`n"
   }   
   Return titleNode1 " by " userNameNode1 Delimiter SubStr(Output, 1, -2)
}

; ++++++++++++++++++++++++++++++++++++++++

Dec2Hex(Dec)
{
   SetFormat, integer, hex
   Dec += 0
   SetFormat, integer, d
   Return Dec
}
; ++++++++++++++++++++++++++++++++++++++++ Labels

^S::
   pBitmap := Gdip_CreateBitmapFromHBITMAP(hBitmap)
   Gdip_SaveBitmapToFile(pBitmap, A_Desktop "\CL.png")
   Gdip_DisposeImage(pBitmap)
   GoSub, Exit
Return

Space::
   pBitmap := Gdip_CreateBitmapFromHBITMAP(hBitmap)
   Gdip_SaveBitmapToFile(pBitmap, A_Desktop "\CL.bmp")
   Gdip_DisposeImage(pBitmap)
   DllCall("SystemParametersInfo", "UInt", 0x14, "UInt", 0, "Str", A_Desktop "\CL.bmp", "UInt", 2)
   FileDelete, %A_Desktop%\CL.bmp
   GoSub, Exit
Return

F1::
   Circles := !Circles
Return

F2::
   Text := !Text
Return

F3::
   Tips := !Tips
   ToolTip
Return

Esc::
Exit:
   SelectObject(hDC, obm)
   DeleteObject(hBitmap)
   DeleteDC(hDC)
   Gdip_DeleteGraphics(G)
   Gdip_Shutdown(pToken)
ExitApp


Important! You'll need to replace Gdip_TextToGraphics() with my version below.
(I just added a parameter which, when enabled, tells the function to return just the information from Gdip_MeasureString() and not draw the Text)

Edit: Also, this needs httpQuery and it uses some additional Gdip functions, which are now pasted below (thanks tic!)

@tic: It would be cool if a means to get the resulting text dimensions directly would be included in the library :)

Code:
Gdip_TextToGraphics(pGraphics, Text, Options, Font="Arial", Width="", Height="", MeasureOnly="")
{
   IWidth := Width, IHeight:= Height
   
   RegExMatch(Options, "i)X([\-0-9]+)(p*)", xpos)
   RegExMatch(Options, "i)Y([\-0-9]+)(p*)", ypos)
   RegExMatch(Options, "i)W([0-9]+)(p*)", Width)
   RegExMatch(Options, "i)H([0-9]+)(p*)", Height)
   RegExMatch(Options, "i)C(?!(entre|enter))([a-f0-9]{8})", Colour)
   RegExMatch(Options, "i)Top|Up|Bottom|Down|vCentre|vCenter", vPos)
   RegExMatch(Options, "i)R([0-9])", Rendering)
   RegExMatch(Options, "i)S([0-9]+)(p*)", Size)

   If !(IWidth && IHeight) && (xpos2 || ypos2 || Width2 || Height2 || Size2)
   Return, -1

   Style := 0, Styles := "Regular|Bold|Italic|BoldItalic|Underline|Strikeout"
   Loop, Parse, Styles, |
   {
      If RegExMatch(Options, "\b" A_loopField)
      Style |= (A_LoopField != "StrikeOut") ? (A_Index-1) : 8
   }
 
   Align := 0, Alignments := "Near|Left|Centre|Center|Far|Right"
   Loop, Parse, Alignments, |
   {
      If RegExMatch(Options, "\b" A_loopField)
      Align |= A_Index//2.1      ; 0|0|1|1|2|2
   }

   xpos := (xpos1 != "") ? xpos2 ? IWidth*(xpos1/100) : xpos1 : 0
   ypos := (ypos1 != "") ? ypos2 ? IHeight*(ypos1/100) : ypos1 : 0
   Width := Width1 ? Width2 ? IWidth*(Width1/100) : Width1 : IWidth
   Height := Height1 ? Height2 ? IHeight*(Height1/100) : Height1 : IHeight
   Colour := "0x" (Colour2 ? Colour2 : "ff000000")
   Rendering := ((Rendering1 >= 0) && (Rendering1 <= 4)) ? Rendering1 : 4
   Size := (Size1 > 0) ? Size2 ? IHeight*(Size1/100) : Size1 : 12

   hFamily := Gdip_FontFamilyCreate(Font)
   hFont := Gdip_FontCreate(hFamily, Size, Style)
   hFormat := Gdip_StringFormatCreate(0x4000)
   pBrush := Gdip_BrushCreateSolid(Colour)
   If !(hFamily && hFont && hFormat && pBrush && pGraphics)
   Return, !pGraphics ? -2 : !hFamily ? -3 : !hFont ? -4 : !hFormat ? -5 : !pBrush ? -6 : 0
   
   CreateRectF(RC, xpos, ypos, Width, Height)
   Gdip_SetStringFormatAlign(hFormat, Align)
   Gdip_SetTextRenderingHint(pGraphics, Rendering)
   ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)
   
   If MeasureOnly
   {
      Gdip_DeleteBrush(pBrush)
      Gdip_DeleteStringFormat(hFormat)   
      Gdip_DeleteFont(hFont)
      Gdip_DeleteFontFamily(hFamily)
      Return ReturnRC
   }

   If vPos
   {
      StringSplit, ReturnRC, ReturnRC, |
      
      If (vPos = "vCentre") || (vPos = "vCenter")
         ypos := (Height-ReturnRC4)//2
      Else If (vPos = "Top") || (vPos = "Up")
         ypos := 0
      Else If (vPos = "Bottom") || (vPos = "Down")
         ypos := Height-ReturnRC4
      
      CreateRectF(RC, xpos, ypos, Width, ReturnRC4)
   }

   E := Gdip_DrawString(pGraphics, Text, hFont, hFormat, pBrush, RC)

   Gdip_DeleteBrush(pBrush)
   Gdip_DeleteStringFormat(hFormat)   
   Gdip_DeleteFont(hFont)
   Gdip_DeleteFontFamily(hFamily)
   Return, E ? E : ReturnRC
}

; ++++++++++++++++++++++++++++++++++++++++

; additional GDIP functions, to register a new GDIP Canvas class
; and work on a GUI which is NOT created by Gui* Commands
; initially written by derRaphael for tic's gdip library on nov 30, 2008
; licensed under the terms of gdip.ahk's license

; Inspiration to this came from this thread:
;    majkinetor's [tutorial] Creating windows without GUI commands
;    http://www.autohotkey.com/forum/viewtopic.php?t=22904

GDIP_CreateWindow(lpWindowName="dR's GDIP Canvas") {
   return DllCall("CreateWindowEx" ; This function actually creates the window and returns its hWnd
      , "uInt",dwExStyle:=0x80088, "Str", lpClassName:="GDIP_Canvas"
     , "Str", lpWindowName, "uInt", dwStyle:=0x940A0000
      , "Int", x, "Int", y, "Int", nWidth, "Int", nHeight, "uInt", hWndParent
      , "uInt",hMenu, "uInt", hInstance, "uInt", lpParam)
}

GDIP_RegisterClass(){ ; needs to be called only once, so it can register the class
   cName := "GDIP_Canvas", WndProc := RegisterCallback("GDIP_WndProc", "F")
   VarSetCapacity(WndClass, 40, 0)
   NumPut(WndProc, WndClass, 4) ; style / lpfnWndProc
   ; If below is NOT specified, the app must take care of assigning proper IDC_* Cursors
   ; the provoded method assigns standard cursor for the window
   NumPut((hCursor := DllCall( "LoadCursor", "Uint",0, "Int", IDC_ARROW:=32512 )), WndClass , 24)
   NumPut(&cName, WndClass, 36) ; lpszClassName
   return DllCall("RegisterClass", "uint", &WndClass )
}

/*
; Additional WndClass - http://msdn.microsoft.com/en-us/library/ms633576(VS.85).aspx
   NumPut(0, WndClass, 0)   ; style see http://msdn.microsoft.com/en-us/library/ms633574(VS.85).aspx
   NumPut(0, WndClass, 8)   ; cbClsExtra
   NumPut(0, WndClass, 12)  ; cbWndExtra
   NumPut(0, WndClass, 16)  ; hInstance
   NumPut(0, WndClass, 20)  ; hIcon
   NumPut(0, WndClass, 28)  ; hbrBackground (brush background)
   NumPut(0, WndClass, 32)  ; lpszMenuName
*/

; The callback for our new registered class
GDIP_WndProc(hwnd, uMsg, wParam, lParam) { ; This one can handle additional WndMsgs
   if (uMsg=0x111) {
      DllCall("DestroyWindow", "uint", hwnd)
   }
   return, DllCall("DefWindowProc", "uint", hwnd, "uint", umsg, "uint", wParam, "uint", lParam)
}


Last edited by philou on December 29th, 2008, 1:08 am, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 29th, 2008, 12:27 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
its funny you added that to Gdip_TextToGraphics philou :) I had already done pretty much exactly the same thing, but was still a bit unsure about how I would handle gradiented brushes within the function so hadnt released another update straight away. A snippet from 1.27:

Code:
Gdip_TextToGraphics(pGraphics, Text, Options, Font="Arial", Width="", Height="", Measure="", pBrush="")
{
   IWidth := Width, IHeight:= Height
   
   RegExMatch(Options, "i)X([\-0-9]+)(p*)", xpos)
   RegExMatch(Options, "i)Y([\-0-9]+)(p*)", ypos)
   RegExMatch(Options, "i)W([0-9]+)(p*)", Width)
   RegExMatch(Options, "i)H([0-9]+)(p*)", Height)
   RegExMatch(Options, "i)C(?!(entre|enter))([a-f0-9]{8})", Colour)
   RegExMatch(Options, "i)Top|Up|Bottom|Down|vCentre|vCenter", vPos)
   RegExMatch(Options, "i)R([0-9])", Rendering)
   RegExMatch(Options, "i)S([0-9]+)(p*)", Size)

   If !(IWidth && IHeight) && (xpos2 || ypos2 || Width2 || Height2 || Size2)
   Return, -1

   Style := 0, Styles := "Regular|Bold|Italic|BoldItalic|Underline|Strikeout"
   Loop, Parse, Styles, |
   {
      If RegExMatch(Options, "\b" A_loopField)
      Style |= (A_LoopField != "StrikeOut") ? (A_Index-1) : 8
   }
 
   Align := 0, Alignments := "Near|Left|Centre|Center|Far|Right"
   Loop, Parse, Alignments, |
   {
      If RegExMatch(Options, "\b" A_loopField)
      Align |= A_Index//2.1      ; 0|0|1|1|2|2
   }

   xpos := (xpos1 != "") ? xpos2 ? IWidth*(xpos1/100) : xpos1 : 0
   ypos := (ypos1 != "") ? ypos2 ? IHeight*(ypos1/100) : ypos1 : 0
   Width := Width1 ? Width2 ? IWidth*(Width1/100) : Width1 : IWidth-xpos
   Height := Height1 ? Height2 ? IHeight*(Height1/100) : Height1 : IHeight-ypos
   Colour := "0x" (Colour2 ? Colour2 : "ff000000")
   Rendering := ((Rendering1 >= 0) && (Rendering1 <= 4)) ? Rendering1 : 4
   Size := (Size1 > 0) ? Size2 ? IHeight*(Size1/100) : Size1 : IHeight//10

   hFamily := Gdip_FontFamilyCreate(Font)
   hFont := Gdip_FontCreate(hFamily, Size, Style)
   hFormat := Gdip_StringFormatCreate(0x4000)
   pBrush := pBrush ? pBrush : Gdip_BrushCreateSolid(Colour)
   If !(hFamily && hFont && hFormat && pBrush && pGraphics)
   Return, !pGraphics ? -2 : !hFamily ? -3 : !hFont ? -4 : !hFormat ? -5 : !pBrush ? -6 : 0
   
   CreateRectF(RC, xpos, ypos, Width, Height)
   Gdip_SetStringFormatAlign(hFormat, Align)
   Gdip_SetTextRenderingHint(pGraphics, Rendering)
   ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)

   If !Measure
   {
      If vPos
      {
         StringSplit, ReturnRC, ReturnRC, |
         
         If (vPos = "vCentre") || (vPos = "vCenter")
         ypos := (Height-ReturnRC4)//2
         Else If (vPos = "Top") || (vPos = "Up")
         ypos := 0
         Else If (vPos = "Bottom") || (vPos = "Down")
         ypos := Height-ReturnRC4
         
         CreateRectF(RC, xpos, ypos, Width, ReturnRC4)
      }
      E := Gdip_DrawString(pGraphics, Text, hFont, hFormat, pBrush, RC)
   }

   Gdip_DeleteBrush(pBrush)
   Gdip_DeleteStringFormat(hFormat)
   Gdip_DeleteFont(hFont)
   Gdip_DeleteFontFamily(hFamily)
   Return, E ? E : ReturnRC
}


People may not have httpQuery() when trying your example. Also...Im still not sure about GDIP_RegisterClass() and GDIP_CreateWindow() as it is currently limiting with styles and things you would want to set on the window. what do you think?

The screensaver does look really cool. I just got a new monitor and it looks nice on it :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 30th, 2008, 12:40 am 
Offline

Joined: July 26th, 2006, 8:50 pm
Posts: 68
Location: Wuppertal
Heh, that's cool!
Thanks for reminding me about httpQuery() and the GDIP_RegisterClass() stuff, I edited my other post.

I just used GDIP_RegisterClass() because... I originally just wanted to try it, I think. I like the more "clean" approach to creating the window, but that's completely subjective.

Very, very nice work on the library!

A couple of brainfarts:
- Update Gdip_BitmapFromScreen() to (optionally) be able to capture layered windows as well [Seans solution]
- Is there a Clear() or something similar to use with Animation? (when animating on a transparent background)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 30th, 2008, 1:26 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Hi philou

as of 1.26 you can specify to capture layered windows with Gdip_BitmapFromScreen(), sorry i should have made it more clear how to do it. ill update that in 1.27 to make it easier to see...

Code:
pBitmap := Gdip_BitmapFromScreen(0, 0x00CC0020|0x40000000)


You can clear an area, a good example to see that is in the TTG example. Specifically look at Gdip_SetCompositingMode()

Gdip_SetCompositingMode(G, 1) will make it so that when you draw anything it will erase anything behind it, and Gdip_SetCompositingMode(G, 0) will put it back to normal. You would probably also like to use Gdip_SetClipRect(pGraphics, x, y, w, h, CombineMode=0) which can either limit drawing to a specific rectangle, or make it so that you cannot draw within that rectangle

TTG shows all this, but not very clearly. I will make this my next example


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 30th, 2008, 2:01 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
tic, two suggestions:
  • If a font fails to load, use a fallback font. "Garamond" is not a default Windows font.
  • Implement GdipGraphicsClear.
    Code:
    GpStatus WINGDIPAPI GdipGraphicsClear(GpGraphics *graphics, ARGB color);


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 30th, 2008, 1:14 pm 
Offline

Joined: November 23rd, 2007, 10:23 am
Posts: 841
Location: ~/.
toc updated. thx all!

_________________
Image
    All scripts, unless otherwise noted, are hereby released under CC-BY


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2009, 7:46 am 
Hi All!!

HotKeyIt from Germany has referred me to this great thread of GDI paradise. I have this painting tool in progress, and stumped by one or two things to get me going much further & invest time to expand this to a custom drawing tool.

The topmost thing is - the process of taking the drawing being created on the GUI with the script below, and save it to a file.... I think I am decent enough with GDI commands, where if someone can figure out a way to 'capture in buffer' the drawing being made, ... and at least get it to a pBitmap or hBitmap stage, then I can then convert and save it out to whatever file formats I need :D

At a second level of interest, I need to figure out how to draw a solid line. As you can see it is only a dotted type line being rendered. Perhaps someone can illustrate a 25pixel thick round-circle shape, in Red color... how to draw such freehand line where it is solid, smooth and nice.

Can someone please help me with either/both of these? It would be very gracious and kind of you if you can. Thank you for your time, insight and have a very great day!!!

Code:

SetBatchLines, -1
Process, Exist
Process, priority, %ErrorLevel%, High
OnExit, Exit
Gui, Show, h300 w300, Test
Gui, Add, Button, x10 y10 w270 h25 , Save To pBitmap/hBitmap
hWnd := WinExist("Test")
hDC := DllCall("GetDC", UInt, hWnd)
color := 0xFF0000FF
OnMessage(0x201, "Draw")
Return

LButton::
Loop
   If GetKeyState("Lbutton", "P")
      Click
   Else
      break
Return

Draw(wParam, lParam)
{
   Global hDC, color
   DllCall("SetPixel", UInt, hDC, Int, lParam & 0xFFFF, Int, lParam >> 16, UInt, color)
}

GuiClose:
GuiEscape:
Exit:
If hDC
   DllCall("ReleaseDC", UInt, hDC)
ExitApp




Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2009, 11:10 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
DG.....I suggest you look at the GDI+ library and examples


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2009, 6:17 pm 
Can someone please help me? I am not an expert, and only just beginning to understand simple stuff. It would be greatly appreciated to push me forwards... thanks allot :) ! :D


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 16th, 2009, 1:20 am 
I know this is tough *gulp*, but I am just pulling my hair out trying to figure this out. Could someone please assist, and check out the code I posted in the previous message? I just need a _basic_ start, to saving the drawing data. It would be really great to have it working, and I assume it is not a big deal, but is just way above my head at this time. thank you for your understanding, ..Greetings!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 1st, 2009, 5:07 am 
Offline

Joined: February 19th, 2009, 6:44 pm
Posts: 125
thanks for the clock script
i modify it a bit and create a sidebar clock for my mini9 desktop

Image

Code:
#singleinstance force
#NoTrayIcon
xpos:=A_screenwidth-200
Gui, color, black
Gui, -Caption +LastFound +ToolWindow +disabled
WinSet, Transparent, 80
Gdip_Startup()
onexit, exit
ClockDiameter := 130
Width := Height := 500
CenterX := 100
CenterY := 100
Gui, 2: -Caption +E0x80000 +LastFound +ToolWindow +OwnDialogs +disabled
Gui, 2: Show,,clock
WinSet, Bottom,, clock
Gui, show, w200 h%A_screenheight% x%xpos%, bar
WinSet, Bottom,, bar
hwnd1 := WinExist()
hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm), G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetSmoothingMode(G, 4)
Diameter := 300
pBrush := Gdip_BrushCreateSolid(0x60000000)
Gdip_FillEllipse(G, pBrush, CenterX-(Diameter//2), CenterY-(Diameter//2),Diameter, Diameter)
Gdip_DeleteBrush(pBrush)
Diameter := 150
pBrush := Gdip_BrushCreateSolid(0x80000000)
Gdip_FillEllipse(G, pBrush, CenterX-(Diameter//2), CenterY-(Diameter//2),Diameter, Diameter)
Gdip_DeleteBrush(pBrush)
R1 := 70
R2 := 58
Items := 12
pPen := Gdip_CreatePen(0xffffffff, 2)
GoSub, DrawClockMarks
Gdip_DeletePen(pPen)
UpdateLayeredWindow(hwnd1, hdc, xpos,0, Width, Height)
SetTimer, sec, 1000
Diameter := 110
sec:
Gdip_SetCompositingMode(G, 1)
pBrush := Gdip_BrushCreateSolid(0x00000000)
Gdip_FillEllipse(G, pBrush, CenterX-(Diameter//2), CenterY-(Diameter//2),Diameter, Diameter)
t := A_Sec*360//60+90
R1 := ClockDiameter//2-ceil((ClockDiameter//2)*0.2)
pPen := Gdip_CreatePen(0x6fffffff, floor((ClockDiameter/100)*1.2))
Gdip_DrawLine(G, pPen, CenterX, CenterY
, ceil(CenterX - (R1 * Cos(t * Atan(1) * 4 / 180)))
, ceil(CenterY - (R1 * Sin(t * Atan(1) * 4 / 180))))
t := A_Min*360//60+90
R1 := ClockDiameter//2-ceil((ClockDiameter//2)*0.25)
pPen := Gdip_CreatePen(0xdfffffff, floor((ClockDiameter/100)*2.7))
Gdip_DrawLine(G, pPen, CenterX, CenterY
, ceil(CenterX - (R1 * Cos(t * Atan(1) * 4 / 180)))
, ceil(CenterY - (R1 * Sin(t * Atan(1) * 4 / 180))))
t := A_Hour*360//12 + (A_Min*360//60)//12 +90
R1 := 35
pPen := Gdip_CreatePen(0xdfffffff, 3)
Gdip_DrawLine(G, pPen, CenterX, CenterY
, ceil(CenterX - (R1 * Cos(t * Atan(1) * 4 / 180)))
, ceil(CenterY - (R1 * Sin(t * Atan(1) * 4 / 180))))
Gdip_DeletePen(pPen)
UpdateLayeredWindow(hwnd1, hdc)
return
DrawClockMarks:
Loop, % Items
Gdip_DrawLine(G, pPen
, CenterX - ceil(R1 * Cos(((a_index-1)*360//Items) * Atan(1) * 4 / 180))
, CenterY - ceil(R1 * Sin(((a_index-1)*360//Items) * Atan(1) * 4 / 180))
, CenterX - ceil(R2 * Cos(((a_index-1)*360//Items) * Atan(1) * 4 / 180))
, CenterY - ceil(R2 * Sin(((a_index-1)*360//Items) * Atan(1) * 4 / 180)) )
return
Exit:
SelectObject(hdc, obm)
DeleteObject(hbm)
DeleteDC(hdc)
Gdip_DeleteGraphics(G)
Gdip_Shutdown(pToken)
ExitApp
Return
 


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 59 posts ]  Go to page Previous  1, 2, 3, 4  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: DataLife and 13 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