Jump to content

about GDI+


Recommended Posts

Dear sir :)

below is a sample code from autoit help file .

she will draw a line at gui .

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $hGUI, $hWnd, $hGraphic, $hPen

; Create GUI
    $hGUI = GUICreate("GDI+", 400, 300)
    $hWnd = WinGetHandle("GDI+")
    GUISetState()

; Draw line
    _GDIPlus_Startup ()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd)
    $hPen = _GDIPlus_PenCreate ()
    _GDIPlus_GraphicsDrawLine ($hGraphic, 10, 150, 390, 150, $hPen)

; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

; Clean up resources
    _GDIPlus_PenDispose ($hPen)
    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_Shutdown ()

EndFunc  ;==>_Main

my question is :

when i drag the gui window and move it , the line show constant like other controls at gui .

while i minimize the gui and then reshow the gui window . the graphic disappear !!!

she would disappear too when some window cross like a [rubber] cross .

:)how to make the drawn graphic show constantly ?

Link to comment
Share on other sites

You have to draw the line in the WM_PAINT event:

CODE
#include <GuiConstantsEx.au3>

#include <GDIPlus.au3>

#include <WinAPI.au3>

#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Global $hGraphic, $hPen

_Main()

Func _Main()

Local $hGUI, $hWnd

; Startup GDI+

_GDIPlus_Startup ()

; Create GUI

$hGUI = GUICreate("GDI+", 400, 300)

$hWnd = WinGetHandle("GDI+")

; Create Resources for PAINTING

$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd)

$hPen = _GDIPlus_PenCreate ()

; Register WM_PAINT for Painting

GUIRegisterMsg(0xF,"MY_PAINT") ;WM_PAINT

GUISetState()

; Loop until user exits

Do

Until GUIGetMsg() = $GUI_EVENT_CLOSE

; Clean up resources

EndFunc ;==>_Main

; PAINT Func

Func MY_PAINT($hWnd, $Msg, $wParam, $lParam)

; draw Line

_GDIPlus_GraphicsDrawLine ($hGraphic, 10, 150, 390, 150, $hPen)

; Return RUNDEF, so that the internal PAINT is called, too

Return $GUI_RUNDEFMSG

EndFunc

; On Exit clean up

Func OnAitoITExit()

_GDIPlus_PenDispose ($hPen)

_GDIPlus_GraphicsDispose ($hGraphic)

_GDIPlus_Shutdown ()

EndFunc

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

You have to draw the line in the WM_PAINT event:

CODE
#include <GuiConstantsEx.au3>

#include <GDIPlus.au3>

#include <WinAPI.au3>

#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Global $hGraphic, $hPen

_Main()

Func _Main()

Local $hGUI, $hWnd

; Startup GDI+

_GDIPlus_Startup ()

; Create GUI

$hGUI = GUICreate("GDI+", 400, 300)

$hWnd = WinGetHandle("GDI+")

; Create Resources for PAINTING

$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd)

$hPen = _GDIPlus_PenCreate ()

; Register WM_PAINT for Painting

GUIRegisterMsg(0xF,"MY_PAINT") ;WM_PAINT

GUISetState()

; Loop until user exits

Do

Until GUIGetMsg() = $GUI_EVENT_CLOSE

; Clean up resources

EndFunc ;==>_Main

; PAINT Func

Func MY_PAINT($hWnd, $Msg, $wParam, $lParam)

; draw Line

_GDIPlus_GraphicsDrawLine ($hGraphic, 10, 150, 390, 150, $hPen)

; Return RUNDEF, so that the internal PAINT is called, too

Return $GUI_RUNDEFMSG

EndFunc

; On Exit clean up

Func OnAitoITExit()

_GDIPlus_PenDispose ($hPen)

_GDIPlus_GraphicsDispose ($hGraphic)

_GDIPlus_Shutdown ()

EndFunc

Dear sir

1) Thanks :)

2) how do i understanding the knowledge about "Windows Message Codes" and it"s meaning deeply ?

3) the 'GUIRegisterMsg(0x000F,"MY_PAINT")' seem could place any where ? so which $hWnd will be sent to MY_PAINT when the WM_PAINT be fired ? (suppose there are many GUI Windows ..)

4) is there any example would return some thing not "$GUI_RUNDEFMSG" ?

Link to comment
Share on other sites

The Message Codes are Messages which are sent to Windows. They inform the Window of changes in the Environment and allow the Window to react. Normally, we don't need to do anything, because AutoIT and the default WindowProc does evertything for us. But if we want to do something, like Painting we have to hok them and e.g. draw our Lines and graphics :)

The Messages are normally sent by the OS, but Applications are enabled to send them, too.

To get information about a message, you could search them in http://msdn.microsoft.com/en-us/library/bb...28VS.85%29.aspx

or on Google with the KeyWirds: MESSAGE_CODE msdn e.g.: WM_PAINT msdn

To 4): Normally you always return GUI_RUNDEFMSG, because the parent Messagehandler should be called, too.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

The Message Codes are Messages which are sent to Windows. They inform the Window of changes in the Environment and allow the Window to react. Normally, we don't need to do anything, because AutoIT and the default WindowProc does evertything for us. But if we want to do something, like Painting we have to hok them and e.g. draw our Lines and graphics :)

The Messages are normally sent by the OS, but Applications are enabled to send them, too.

To get information about a message, you could search them in http://msdn.microsoft.com/en-us/library/bb...28VS.85%29.aspx

or on Google with the KeyWirds: MESSAGE_CODE msdn e.g.: WM_PAINT msdn

To 4): Normally you always return GUI_RUNDEFMSG, because the parent Messagehandler should be called, too.

Thank You very much ! :)

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...