byronsmith Posted January 23, 2010 Share Posted January 23, 2010 Hi All, Consider the following code below, when I minimize the app and maximize it again the screen is cleared. Is there a way I can keep what has already been draw when maximized, I would also like the pen to keep drawing even when minimized. It may actually still be drawing whilst minimized but I cannot see because of said problem. I was doing a little reading and perhaps I can make it a bitmap, then draw directly to the bitmap? Of course I could be talking utter rubbish. Also, if there a way with WinAPI to smooth the line drawn? i.e some sort of anti-alias? Your help will be greatly appreciated. Regards Byron #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> Local $hDC, $hPen, $hObj, $hImage $hWnd = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0) GUISetState() $hDC = _WinAPI_GetWindowDC($hWnd) $hPen = _WinAPI_CreatePen($PS_SOLID, 1, 0xAFAFAF) $hObj = _WinAPI_SelectObject($hDC, $hPen) _WinAPI_MoveTo($hDC, _WinAPI_GetMousePosX(), _WinAPI_GetMousePosY()) While 1 sleep(15) $mouse_x = _WinAPI_GetMousePosX() $mouse_y = _WinAPI_GetMousePosY() _WinAPI_LineTo($hDC, $mouse_x, $mouse_y) $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd _WinAPI_SelectObject($hDC, $hObj) _WinAPI_DeleteObject($hPen) _WinAPI_ReleaseDC(0, $hDC) Link to comment Share on other sites More sharing options...
martin Posted January 23, 2010 Share Posted January 23, 2010 (edited) Hi All, Consider the following code below, when I minimize the app and maximize it again the screen is cleared. Is there a way I can keep what has already been draw when maximized, I would also like the pen to keep drawing even when minimized. It may actually still be drawing whilst minimized but I cannot see because of said problem. I was doing a little reading and perhaps I can make it a bitmap, then draw directly to the bitmap? Of course I could be talking utter rubbish. Also, if there a way with WinAPI to smooth the line drawn? i.e some sort of anti-alias? Your help will be greatly appreciated. Regards Byron #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> Local $hDC, $hPen, $hObj, $hImage $hWnd = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0) GUISetState() $hDC = _WinAPI_GetWindowDC($hWnd) $hPen = _WinAPI_CreatePen($PS_SOLID, 1, 0xAFAFAF) $hObj = _WinAPI_SelectObject($hDC, $hPen) _WinAPI_MoveTo($hDC, _WinAPI_GetMousePosX(), _WinAPI_GetMousePosY()) While 1 sleep(15) $mouse_x = _WinAPI_GetMousePosX() $mouse_y = _WinAPI_GetMousePosY() _WinAPI_LineTo($hDC, $mouse_x, $mouse_y) $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd _WinAPI_SelectObject($hDC, $hObj) _WinAPI_DeleteObject($hPen) _WinAPI_ReleaseDC(0, $hDC) Maybe it's easier to use a graphic control. #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> opt("mouseCoordMode",2) Local $hDC, $hPen, $hObj, $hImage $hWnd = GUICreate("", @DesktopWidth, @DesktopHeight, 0,0, -1,$WS_EX_COMPOSITED) $graphic = GUICtrlCreateGraphic(0,0);,@DesktopWidth, @DesktopHeight) GUISetState() Global $lastx,$lasty $mouse = mousegetpos() GUICtrlSetGraphic ($graphic,$GUI_GR_MOVE,$mouse[0], $mouse[1]) GUICtrlSetGraphic ($graphic,$GUI_GR_COLOR,0);$GUI_GR_NOBKCOLOR) While 1 $mouse = mousegetpos() If $lastx <> $mouse[0] Or $lasty <> $mouse[1] Then GUICtrlSetGraphic ($graphic,$GUI_GR_LINE,$mouse[0], $mouse[1]) GUICtrlSetGraphic ($graphic,$GUI_GR_REFRESH) $lasty = $mouse[1] $lastx = $mouse[0] EndIf $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd EDIT: Oh, welcome to the AutoIt forums byronsmith Edited January 23, 2010 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
byronsmith Posted January 24, 2010 Author Share Posted January 24, 2010 Hi Martin, Very kind of you to provide an alternative to what I was trying to achieve. Although I did have a little play around with the GUI functions I found that the $GUI_GR_REFRESH was a little slow i.e would present a flicker when drawing and so in turn opted for the WinAPI UDF. I will do some more reading on the GUI method and see if there is a way around this issue. Thank you for welcoming me to the forum and again many thanks for your help! Regards Byron Link to comment Share on other sites More sharing options...
martin Posted January 24, 2010 Share Posted January 24, 2010 Hi Martin,Very kind of you to provide an alternative to what I was trying to achieve. Although I did have a little play around with the GUI functions I found that the $GUI_GR_REFRESH was a little slow i.e would present a flicker when drawing and so in turn opted for the WinAPI UDF.I will do some more reading on the GUI method and see if there is a way around this issue.Thank you for welcoming me to the forum and again many thanks for your help!RegardsByronWell my example should not have any flicker, did you try it? I used the $WS_EX_COMPOSITED style and the lines seem to be drawn pretty fast.Maybe using GDI would be better. You just need a bitmap in the background to draw on and when the window is repainted copy it to the window DC. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
byronsmith Posted January 24, 2010 Author Share Posted January 24, 2010 Hi Martin, I did indeed try your script and it worked a treat except for the flicker. I have been doing a little research and found out that $WS_EX_COMPOSITED does not work in Win7 So I did a little bit more reading on the GDI+ UDF and came up with this! expandcollapse popup#include <GDIPlus.au3> #include <WinAPI.au3> #include <GuiConstants.au3> #include <WindowsConstants.au3> Global $GuiSizeX = @DesktopWidth, $GuiSizeY = @DesktopHeight Local $lasty, $lastx $hGui = GUICreate("Draw", $GuiSizeX, $GuiSizeY) GUISetState() _GDIPlus_Startup() $hGraphicGUI = _GDIPlus_GraphicsCreateFromHWND($hGui) $hBMPBuff = _GDIPlus_BitmapCreateFromGraphics($GuiSizeX, $GuiSizeY, $hGraphicGUI) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBMPBuff) $hPen = _GDIPlus_PenCreate (0x20000000,1,2) $startpos = MouseGetPos() While 1 $mouse = MouseGetPos() If IsInt($lastx) = 0 And IsInt($lasty) = 0 Then $startmousex = $startpos[0] $startmousey = $startpos[1] Else $startmousex = $lastx $startmousey = $lasty EndIf _GDIPlus_GraphicsDrawLine($hGraphic, $startmousex, $startmousey, $mouse[0], $mouse[1],$hPen) ;_GDIPlus_GraphicsDrawLine($hGraphicGUI, $startmousex, $startmousey, $mouse[0], $mouse[1],$hPen) _GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0) $lasty = $mouse[1] $lastx = $mouse[0] $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd The problem I have with this is Alpha blending, you will see one line commented out, on this line I am specfiying $hGraphicsGUI instead of $hGraphics. With $hGraphicsGUI the alpha blending works a treat but when minimized it clears and I'm back to square one, however with $hGraphics the image does not clear when minimized but the alpha blending is no more Can you offer some light on this? Regards Byron Link to comment Share on other sites More sharing options...
picea892 Posted January 24, 2010 Share Posted January 24, 2010 You need to register a repaint. See Malkey's first response for a good working template. Link to comment Share on other sites More sharing options...
byronsmith Posted January 24, 2010 Author Share Posted January 24, 2010 You need to register a repaint. See Malkey's first response for a good working template.Howzit picea, thanks for the reply, however are you responding to the last reply or to the original post?RegardsByron Link to comment Share on other sites More sharing options...
byronsmith Posted January 24, 2010 Author Share Posted January 24, 2010 Howzit picea, thanks for the reply, however are you responding to the last reply or to the original post?RegardsByronNevermind. Thanks for the working template. Link to comment Share on other sites More sharing options...
picea892 Posted January 24, 2010 Share Posted January 24, 2010 I read "when I minimize the app and maximize it again the screen is cleared" and usually the answer is the link I provided. Perhaps I should have explained more sorry. First off, let me say that I think Martin's example is your best, easiest solution. The problem as I see it is you have not saved what you draw. If you saved what you draw as a bitmap or graphic, then you could redraw it on a max event using the technique in the link I provided. Martin save his to a graphic control using GUICtrlSetGraphic, that's why it is there when you maximize. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now