Jump to content

If you minimize and maximize the window, the text disappears (_GDIPlus)


Go to solution Solved by Nine,

Recommended Posts

Posted

Hi all!

Please tell me how to make sure that the text does not disappear after minimizing/maximizing the window?

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
        Local $hGUI = GUICreate("GDI+ test", 800, 400)
        GUISetState(@SW_SHOW)

        _GDIPlus_Startup()
        Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
        _GDIPlus_GraphicsDrawString($hGraphics, "AutoIt rulez!", 0, 0, "Tahoma", 66)
        _GDIPlus_GraphicsSetTextRenderingHint($hGraphics, $GDIP_TEXTRENDERINGHINTANTIALIASGRIDFIT)
        _GDIPlus_GraphicsSetSmoothingMode($hGraphics,4)
        _GDIPlus_GraphicsDrawString($hGraphics, "AutoIt rulez!", 0, 200, "Tahoma", 66)

        While 1
                Switch GUIGetMsg()
                        Case $GUI_EVENT_CLOSE
                                ExitLoop
                EndSwitch
        WEnd

        ;cleanup resources
        _GDIPlus_GraphicsDispose($hGraphics)
        _GDIPlus_Shutdown()
        GUIDelete($hGUI)
EndFunc   ;==>Example

 

Posted

 

Example()

Func Example()
    Local $hGUI = GUICreate("GDI+ test", 800, 400)
    GUISetState(@SW_SHOW)

    _GDIPlus_Startup()
    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    DrawText($hGraphics)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $GUI_EVENT_RESTORE
                DrawText($hGraphics)

        EndSwitch
    WEnd

    ;cleanup resources
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
EndFunc   ;==>Example

Func DrawText($hGraphics)
    _GDIPlus_GraphicsDrawString($hGraphics, "AutoIt rulez!", 0, 0, "Tahoma", 66)
    _GDIPlus_GraphicsSetTextRenderingHint($hGraphics, $GDIP_TEXTRENDERINGHINTANTIALIASGRIDFIT)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 4)
    _GDIPlus_GraphicsDrawString($hGraphics, "AutoIt rulez!", 0, 200, "Tahoma", 66)
EndFunc   ;==>DrawText

 

I know that I know nothing

Posted

One simple way is to use a back buffer :

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
  Local $hGUI = GUICreate("GDI+ test", 800, 400)
  GUISetState(@SW_SHOW)

  _GDIPlus_Startup()
  Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
  Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics(800, 400, $hGraphic)
  Local $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)

  _GDIPlus_GraphicsDrawString($hBuffer, "AutoIt rulez!", 0, 0, "Tahoma", 66)
  _GDIPlus_GraphicsSetTextRenderingHint($hBuffer, $GDIP_TEXTRENDERINGHINTANTIALIASGRIDFIT)
  _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 4)
  _GDIPlus_GraphicsDrawString($hBuffer, "AutoIt rulez!", 0, 200, "Tahoma", 66)

  _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, 800, 400)

  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop
      Case $GUI_EVENT_RESTORE
        _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, 800, 400)
    EndSwitch
  WEnd

  ;cleanup resources
  _GDIPlus_GraphicsDispose($hBuffer)
  _GDIPlus_BitmapDispose($hBitmap)
  _GDIPlus_GraphicsDispose($hGraphic)
  _GDIPlus_Shutdown()
  GUIDelete($hGUI)
EndFunc   ;==>Example

 

Posted

Thank you very much for your quick reply! But to be honest - I need the caption to be static, if I move the window off the screen and back - the caption is erased.

How can I make it so that it is static? Never disappears, like GUICtrlCreateLabel?

Please sorry my English!

Posted
12 minutes ago, SEKOMD said:

How can I make it so that it is static?

Use a static control.  But with GDI+ the way you are using it, you need to patch things up, like this :

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>

Global $hGraphic, $hBitmap

Example()

Func Example()
  Local $hGUI = GUICreate("GDI+ test", 800, 400)
  GUISetState(@SW_SHOW)

  _GDIPlus_Startup()
  $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
  $hBitmap = _GDIPlus_BitmapCreateFromGraphics(800, 400, $hGraphic)
  Local $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)

  _GDIPlus_GraphicsDrawString($hBuffer, "AutoIt rulez!", 0, 0, "Tahoma", 66)
  _GDIPlus_GraphicsSetTextRenderingHint($hBuffer, $GDIP_TEXTRENDERINGHINTANTIALIASGRIDFIT)
  _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 4)
  _GDIPlus_GraphicsDrawString($hBuffer, "AutoIt rulez!", 0, 200, "Tahoma", 66)

  GUIRegisterMsg($WM_MOVE, WM_MOVE)
  _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, 800, 400)

  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop
      Case $GUI_EVENT_RESTORE
        _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, 800, 400)
    EndSwitch
  WEnd

  ;cleanup resources
  _GDIPlus_GraphicsDispose($hBuffer)
  _GDIPlus_BitmapDispose($hBitmap)
  _GDIPlus_GraphicsDispose($hGraphic)
  _GDIPlus_Shutdown()
  GUIDelete($hGUI)
EndFunc   ;==>Example

Func WM_MOVE($hWnd, $iMsg, $wParam, $lParam)
  _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, 800, 400)
  Return $GUI_RUNDEFMSG
EndFunc

 

  • SEKOMD changed the title to If you minimize and maximize the window, the text disappears (_GDIPlus)
Posted
On 1/13/2025 at 3:34 PM, Nine said:

Use a static control.  But with GDI+ the way you are using it, you need to patch things up, like this :

Thanks for the example! Everything works, but please tell me how to make it so that the anti-aliasing does not disappear after dragging the window? Anti-aliasing does not work when dragging a window...

  • Solution
Posted

Did not notice that.  Here one way :

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>

Global $hGraphic, $hBitmap, $hBuffer

Example()

Func Example()
  Local $hGUI = GUICreate("GDI+ test", 800, 400)
  GUISetState(@SW_SHOW)

  _GDIPlus_Startup()
  $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
  $hBitmap = _GDIPlus_BitmapCreateFromGraphics(800, 400, $hGraphic)
  $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)

  _GDIPlus_GraphicsSetTextRenderingHint($hBuffer, $GDIP_TEXTRENDERINGHINTANTIALIASGRIDFIT)
  _GDIPlus_GraphicsSetSmoothingMode($hBuffer, $GDIP_SMOOTHINGMODE_HIGHQUALITY)

  _GDIPlus_GraphicsDrawString($hBuffer, "AutoIt rulez!", 0, 0, "Tahoma", 66)
  _GDIPlus_GraphicsDrawString($hBuffer, "AutoIt rulez!", 0, 200, "Tahoma", 66)

  GUIRegisterMsg($WM_PAINT, WM_PAINT)
  _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, 800, 400)

  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop
      Case $GUI_EVENT_RESTORE
        _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, 800, 400)
    EndSwitch
  WEnd

  _GDIPlus_GraphicsDispose($hBuffer)
  _GDIPlus_BitmapDispose($hBitmap)
  _GDIPlus_GraphicsDispose($hGraphic)
  _GDIPlus_Shutdown()
  GUIDelete($hGUI)
EndFunc   ;==>Example

Func WM_PAINT($hWnd, $iMsg, $wParam, $lParam)
  _GDIPlus_GraphicsClear($hBuffer, 0xFFF0F0F0)

  _GDIPlus_GraphicsDrawString($hBuffer, "AutoIt rulez!", 0, 0, "Tahoma", 66)
  _GDIPlus_GraphicsDrawString($hBuffer, "AutoIt rulez!", 0, 200, "Tahoma", 66)

  _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, 800, 400)
  Return $GUI_RUNDEFMSG
EndFunc

 

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
  • Recently Browsing   0 members

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