Jump to content

_WinAPI_Drawline 'Starting Point' position?


Burgs
 Share

Recommended Posts

Hello,

I am having some difficulty with the _WinAPI_Drawline command. When the line is drawn for some reason the starting position coordinates are incorrect...this can be seen in the attached working code example I have below. I have tried changing the "Opt("PixelCoordMode", 1)" to be "0" and "2", however no difference was effected. In the attached code I'm simply trying to get the red line to draw from the green rectangle to the given coordinates...however the 'starting point' positioning is all wrong and I am at a loss to explain why? Any help much appreciated. Thank you in advance.

#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>

Opt("PixelCoordMode", 2) ;1=absolute, 0=relative, 2=client

Global $Z = 1
Global $X_POSITION = 100
Global $Y_POSITION = 100
Global $Info1 = 80
Global $Info2 = 80
Global $MainGUI = GUICreate("TEST", 425, 540, 450, 250)
GUISetState(@SW_SHOW)

$font = "Arial"

;**'BOXES'
$a = GUICtrlCreateGraphic(5, 65, 415, 400)
GUICtrlSetColor($a, 0) ; to display a black border line
;GUICtrlSetBkColor($a, 0xc0c0ff)
GUICtrlSetState($a, $GUI_DISABLE) ; you have to disable the graphic or it overlaps all controls on it
$b = GUICtrlCreateGraphic(5, 5, 415, 55)
GUICtrlSetColor($b, 0) ; to display a black border line
GUICtrlSetState($b, $GUI_DISABLE) ; you have to disable the graphic or it overlaps all controls on it
$c = GUICtrlCreateGraphic(5, 470, 415, 65)
GUICtrlSetColor($c, 0) ; to display a black border line
GUICtrlSetState($c, $GUI_DISABLE) ; you have to disable the graphic or it overlaps all controls on it
;**

_Run_Path()

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
     Case $GUI_EVENT_CLOSE
         Exit
EndSwitch
WEnd

Func _Run_Path()

Local $pos = MouseGetPos()
Local $a[1000] ;1000 potential plots...
Local $hDC, $hPen, $obj_orig, $color = 0xFF

$a[$Z] = GUICtrlCreateGraphic($X_POSITION, $Y_POSITION, 20, 20, $SS_BLACKFRAME)
GUICtrlSetBKColor($a[$Z], 0x00ff00)

$hDC = _WinAPI_GetDC($MainGUI)
$hPen = _WinAPI_CreatePen($PS_SOLID, 2, $color)
$obj_orig = _WinAPI_SelectObject($hDC, $hPen)

_WinAPI_DrawLine($hDC, $X_POSITION, $Y_POSITION, $Info1, $Info2)

; clear resources
_WinAPI_ReleaseDC($MainGUI, $hDC)
_WinAPI_SelectObject($hDC, $obj_orig)
_WinAPI_DeleteObject($hPen)
_WinAPI_ReleaseDC(0, $hDC)

$Z += 1
EndFunc
Link to comment
Share on other sites

the Graphics control seem to displace the positions of the Lines drawn through GDI+ or WinAPI, hence try to create your rect with the same rather than a graphic control

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

this should help

#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>

Global $Z = 1
Global $X_POSITION = 100
Global $Y_POSITION = 100
Global $Info1 = 100+20
Global $Info2 = 100+20
Global $MainGUI = GUICreate("TEST", 425, 540, 450, 250)
GUISetState(@SW_SHOW)

$font = "Arial"

#cs
;**'BOXES'
$a = GUICtrlCreateGraphic(5, 65, 415, 400)
GUICtrlSetColor($a, 0) ; to display a black border line
;GUICtrlSetBkColor($a, 0xc0c0ff)
GUICtrlSetState($a, $GUI_DISABLE) ; you have to disable the graphic or it overlaps all controls on it
$b = GUICtrlCreateGraphic(5, 5, 415, 55)
GUICtrlSetColor($b, 0) ; to display a black border line
GUICtrlSetState($b, $GUI_DISABLE) ; you have to disable the graphic or it overlaps all controls on it
$c = GUICtrlCreateGraphic(5, 470, 415, 65)
GUICtrlSetColor($c, 0) ; to display a black border line
GUICtrlSetState($c, $GUI_DISABLE) ; you have to disable the graphic or it overlaps all controls on it
;**
#ce
_Run_Path()

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd

Func _Run_Path()

Local $hDC, $hPen, $obj_orig, $color = 0xFF
DrawBlackBox()
;$a[$Z] = GUICtrlCreateGraphic($X_POSITION, $Y_POSITION, 20, 20, $SS_BLACKFRAME)
;GUICtrlSetBkColor($a[$Z], 0x00ff00)

$hDC = _WinAPI_GetDC($MainGUI)
$hPen = _WinAPI_CreatePen($PS_SOLID, 2, $color)
$obj_orig = _WinAPI_SelectObject($hDC, $hPen)

_WinAPI_DrawLine($hDC, $X_POSITION, $Y_POSITION, $Info1, $Info2)

; clear resources
_WinAPI_ReleaseDC($MainGUI, $hDC)
_WinAPI_SelectObject($hDC, $obj_orig)
_WinAPI_DeleteObject($hPen)
_WinAPI_ReleaseDC(0, $hDC)

EndFunc ;==>_Run_Path

Func DrawBlackBox()
_GDIPlus_Startup()
$hGfx=_GDIPlus_GraphicsCreateFromHWND($MainGUI)
_GDIPlus_GraphicsDrawRect($hGfx,$X_POSITION,$Y_POSITION,20,20)
_GDIPlus_GraphicsDispose($hGfx)
_GDIPlus_Shutdown()
EndFunc

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Thanks again...that did help...was it the 'boxes' that I had in the code that messed up the placement of the line? Could you explain why you broke out the creation of the rectangle into a seperate function sing GDI+? Does the usage of 'GUICtrlCreateGraphic' somehow interfere with the '_WinAPI_Drawline'? Thanks again...

Link to comment
Share on other sites

there are many topics regarding the problem associated with graphic controls,

I would always prefer to use GDI+ rather a graphic control

Br

Phoenix XL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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...