daddydave Posted May 15, 2008 Share Posted May 15, 2008 (edited) I'm sure this is probably more of a WinAPI question than an AutoIt3 question, but I'm hoping it's something simple . I am trying to draw a rectangle using _GDIPlus_GraphicsDrawRect, but I only see the right and bottom sides of the rectangle. What am I doing wrong? All the examples with _GDIPlus_GraphicsDrawRect that I have seen involve creating a new image. Is that what I must do? expandcollapse popup#include <GuiConstantsEx.au3> #include <GDIPlus.au3> #include <WinAPI.au3> Opt('MustDeclareVars', 1) _Main() Func _Main() Local $hGUI, $hWnd, $hGraphic, $hDC, $hPen, $iHeight, $iWidth, ; Create GUI $hGUI = GUICreate("GDI+", 400, 300) $hWnd = WinGetHandle("GDI+") ;; Get dimensions $iWidth = _WinAPI_GetClientWidth($hWnd) $iHeight = _WinAPI_GetClientHeight($hWnd) MsgBox("", "", String($iWidth)) MsgBox("", "", String($iHeight)) $hDC = _WinAPI_GetWindowDC($hWnd) GUISetState() _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC) ;; Outline window in red $hPen = _GDIPlus_PenCreate(0xC4FF0000, 2) $hBrush = _GDIPlus_BrushCreateSolid(0xffFF0000) _GDIPlus_GraphicsDrawRect($hGraphic, 0, 0, $iWidth, $iHeight, $hPen) ; Clean up resources _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphic) _WinAPI_ReleaseDC($hWnd, $hDC) _GDIPlus_Shutdown() EndFunc ;==>_Main Edited May 15, 2008 by daddydave Link to comment Share on other sites More sharing options...
smashly Posted May 15, 2008 Share Posted May 15, 2008 Hi,expandcollapse popup#include <GuiConstantsEx.au3> #include <GDIPlus.au3> Opt('MustDeclareVars', 1) _Main() Func _Main() Local $hWnd, $hGraphic, $hPen, $iWidth, $iHeight $hWnd = GUICreate("GDI+", 400, 300) $iWidth = _WinAPI_GetClientWidth($hWnd) $iHeight = _WinAPI_GetClientHeight($hWnd) MsgBox("", "", "Client Width: " & $iWidth & @LF & "Client Height: " & $iHeight) GUISetState() _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd) $hPen = _GDIPlus_PenCreate(0xC4FF0000, 2) _GDIPlus_GraphicsDrawRect($hGraphic, 0, 0, $iWidth, $iHeight, $hPen) Do Until GUIGetMsg() = -3 _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() EndFunc ;==>_Main Cheers Link to comment Share on other sites More sharing options...
rasim Posted May 15, 2008 Share Posted May 15, 2008 smashlyHi! Thanks for example. One question, if i will minimize window and then restore his (any repaint behavior), that drawed line is disappear. How avoid from this behaviour? Link to comment Share on other sites More sharing options...
daddydave Posted May 15, 2008 Author Share Posted May 15, 2008 Thank you so much, smashly! Link to comment Share on other sites More sharing options...
smashly Posted May 15, 2008 Share Posted May 15, 2008 (edited) Hi rasim, You can do it multiple ways depending on your needs, but if your just after to update the graphic on th WM_Paint msg then..expandcollapse popup#include <GuiConstantsEx.au3> #include <GDIPlus.au3> Opt('MustDeclareVars', 1) Global $hWnd, $hGraphic, $hPen, $iWidth, $iHeight _Main() Func _Main() $hWnd = GUICreate("GDI+", 400, 300) $iWidth = _WinAPI_GetClientWidth($hWnd) $iHeight = _WinAPI_GetClientHeight($hWnd) MsgBox("", "", "Client Width: " & $iWidth & @LF & "Client Height: " & $iHeight) GUISetState() GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT") _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd) $hPen = _GDIPlus_PenCreate(0xC4FF0000, 2) _GDIPlus_GraphicsDrawRect($hGraphic, 0, 0, $iWidth, $iHeight, $hPen) Do Until GUIGetMsg() = -3 _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() EndFunc ;==>_Main Func MY_WM_PAINT($hWnd, $Msg) _WinAPI_RedrawWindow($hWnd, 0, 0, $RDW_UPDATENOW) _GDIPlus_GraphicsDrawRect($hGraphic, 0, 0, $iWidth, $iHeight, $hPen) _WinAPI_RedrawWindow($hWnd, 0, 0, $RDW_VALIDATE) Return $GUI_RUNDEFMSG EndFunc Cheers Edit: your welcome daddydave, I seemed to have posted while you were posting Edited May 15, 2008 by smashly Link to comment Share on other sites More sharing options...
rasim Posted May 15, 2008 Share Posted May 15, 2008 smashlyThanks! I think this part of code don`t need, because window is redrawed automatically:_WinAPI_RedrawWindow($hWnd, 0, 0, $RDW_UPDATENOW) _WinAPI_RedrawWindow($hWnd, 0, 0, $RDW_VALIDATE) 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