Jump to content

GUI ctrl menu bar offset for GDIPlus drawings


AlmarM
 Share

Recommended Posts

Hi!

I'm currently working on some GDIPlus drawing and I noticed a little offset in the Y when having a menu bar.

To clarify my issue, here is some example code.

#include <GDIPlus.au3>

_GDIPlus_Startup()

Global $hPenBlack = _GDIPlus_PenCreate(0xFF000000), $hPenGray = _GDIPlus_PenCreate(0xFFCCCCCC)

$hGUI = GUICreate("(Untitled)", 200, 200)
$hFile = GUICtrlCreateMenu("File")
$hNew = GUICtrlCreateMenuItem("New", $hFile)
GUICtrlCreateMenuItem("", $hFile)
$hOpen = GUICtrlCreateMenuItem("Open", $hFile)
$hSave = GUICtrlCreateMenuItem("Save", $hFile)
$hSaveAs = GUICtrlCreateMenuItem("Save as..", $hFile)
GUICtrlCreateMenuItem("", $hFile)
$hExit = GUICtrlCreateMenuItem("Exit", $hFile)
GUISetState()

$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics(200, 200, $hGraphic)
$hBackBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)

While 1
    Switch GUIGetMsg()
        Case -3
            Exit

    EndSwitch

    _GDIPlus_GraphicsClear($hBackBuffer, 0xFFFFFFFF)

    DrawGrid()

    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, 200, 200)
WEnd

Func DrawGrid()
    For $i = 0 To 200 Step 10
        _GDIPlus_GraphicsDrawLine($hBackBuffer, $i, 0, $i, 200, $hPenGray)
        _GDIPlus_GraphicsDrawLine($hBackBuffer, 0, $i, 200, $i, $hPenGray)
    Next

    Local $iHalfWidth = (200 / 2)
    Local $iHalfHeight = (200 / 2)

    _GDIPlus_GraphicsDrawLine($hBackBuffer, $iHalfWidth, 0, $iHalfWidth, 200, $hPenBlack)
    _GDIPlus_GraphicsDrawLine($hBackBuffer, 0, $iHalfHeight, 200, $iHalfHeight, $hPenBlack) ; HERE
EndFunc

 

As you can see, the the second black line being drawn has a slight offset downwards, this can be fixed by removing the menu bar.

Any ideas how to fix this without removing the menu bar?

Thanks in advance. :)

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

The drawing is corrected by the gfx handle is moved approx. 20 px. down.

Just use 

$hGUI = GUICreate("(Untitled)", 200, 220)

and you will see it properly.

Br

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

The drawing is corrected by the gfx handle is moved approx. 20 px. down.

Just use 

$hGUI = GUICreate("(Untitled)", 200, 220)

and you will see it properly.

Br

UEZ

I just noticed this myself, so weird. :o

Thanks for the heads-up!

Will it always be +/- 20px? Does this depend on the OS?

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

You can check the GUI size with WinGetClientSize() and adjust the GUI appropriately.

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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