Jump to content

Table wit GDI+Border - Lines don't redraw


Recommended Posts

Hi,

I played a little bit around with the table UDF. But I want to have it clickable and for the border (line) setting I thought GDI plus woud be better.

Works so far, but the lines escape, if the GUI have to be repainted (after minimize, background, ..). Somewhere I saw a solution, but don't get it to work.

Attached an extract of the test script. The table UDF isn't needed for that.

Thanks in advance, Reinhard

#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
;#include "Table.au3"
#include <Array.au3>

$GUI = GUICreate("Table Test", 450, 450)
;----- Make sure GUI exists BEFORE creating Tables -----
GUISetState()

;----- Lock GUI until tables drawn -----
GUISetState(@SW_LOCK)
 
DIM $xRows = 20, $xCols = 7
DIM $xLeft = 25, $xTop = 130, $xWidth = 55, $xHeight = 13
DIM $table2[$xrows+1][$xCols+1]
DIM $xCurrBoxLeft = 0, $xCurrBoxTop = 0, $xGridWidth = 1

CreateTable($table2)
func CreateTable(ByRef $xtable,$xLeft = 25, $xTop = 130, $xWidth = 55, $xHeight = 13,$xRows = 5, $xCols = 5,$xGridWidth = 1)
 local $xCurrBoxLeft = 0, $xCurrBoxTop = 0
 $xRows = ubound($xtable,1)-1
 $xCols = ubound($xtable,2)-1
 ;msgbox(0,"",$xRows&" / "&$xCols)
 For $i = 1 To $xRows ;$iRows
  For $j = 1 To $xCols ;$iColumns
   $xtable[$i][$j] = GUICtrlCreateLabel("", $xleft + $xCurrBoxLeft, $xTop + $xCurrBoxTop, $xWidth, $xHeight)
   if $i = 1 then ;header
    GUICtrlSetBkColor(-1,0xEEEEEE )
    GuiCtrlSetData(-1,"Col "&$j)
   elseif $j = 1 then ;leftBorder
    GUICtrlSetBkColor(-1,0xEEEEEE )
    GuiCtrlSetData(-1,"Row "&$i)
   else
    GUICtrlSetBkColor(-1, 0xFFFFFF)
   endif
   if $i = 1 and $j = 1 then GuiCtrlSetData(-1,"Table")
   $xCurrBoxLeft += $xWidth + $xGridWidth
  Next
  $xCurrBoxLeft = 0
  $xCurrBoxTop += $xHeight + $xGridWidth
 Next
endfunc
$table2HdlFirst = $table2[1][1]
$table2HdlEnd = $table2[$xRows][$xCols]
GUISetState(@SW_UNLOCK)

dim $Test[3]
$test[1] = GUICtrlCreateLabel("Test",10,420,60,20)
 
GUISetState()

; Draw lines
;_GDIPlus_GraphicsDrawLine($hGraphics, $iX1, $iY1, $iX2, $iY2[, $hPen = 0])
_GDIPlus_Startup ()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($GUI)
$hPen = _GDIPlus_PenCreate ()
 
DrawBorder()
func DrawBorder()
 ;;outline all
   ;;top-line
 _GDIPlus_GraphicsDrawLine ($hGraphic, $xleft-1, $xtop-1, $xleft-1 +(($xWidth+$xGridWidth)*$xCols), $xtop-1, $hPen)
   ;;leftline
 _GDIPlus_GraphicsDrawLine ($hGraphic, $xleft-1, $xtop-1, $xleft-1 , $xtop-1 +(($xHeight+$xGridWidth)*$xRows), $hPen)
   ;; bottom line
 _GDIPlus_GraphicsDrawLine ($hGraphic, $xleft-1, $xtop-1 +(($xHeight+$xGridWidth)*$xRows), $xleft-1 +(($xWidth+$xGridWidth)*$xCols), $xtop-1 +(($xHeight+$xGridWidth)*$xRows), $hPen)
   ;; right line
 _GDIPlus_GraphicsDrawLine ($hGraphic, $xleft-1 + (($xWidth+$xGridWidth)*$xCols), $xtop-1, $xleft-1 + (($xWidth+$xGridWidth)*$xCols) , $xtop-1 +(($xHeight+$xGridWidth)*$xRows), $hPen)
 ;; outline header (underline first row)
 _GDIPlus_GraphicsDrawLine ($hGraphic, $xleft-1, $xtop-1 +(($xHeight+$xGridWidth) * 1), $xleft-1 +(($xWidth+$xGridWidth)*$xCols), $xtop-1 +(($xHeight+$xGridWidth)* 1), $hPen)
 ;; outline left Border ()
 _GDIPlus_GraphicsDrawLine ($hGraphic, $xleft-1 +(($xWidth+$xGridWidth)*1), $xtop-1, $xleft-1 +(($xWidth+$xGridWidth)*1), $xtop-1 +(($xHeight+$xGridWidth)*$xRows), $hPen)
 endfunc
 
GuiSetState()

GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
 
;----- Loop -----
While 1
 $Msg = GUIGetMsg()
 if $msg > $table2HdlFirst-1 and $msg < $table2HdlEnd +1 then
   $RowId = INT((+$msg-$table2HdlFirst)/$xCOLS)+1
   $colId = +$msg-$table2HdlFirst-(($rowId-1)*$xCOLS)+1
   ;msgbox(0,"","Address: R"&$RowId &"C"&$colId)
   tableOnClick($rowId,$colId)
 endif
 Switch $Msg
  Case $GUI_EVENT_CLOSE
   ; Clean up resources
   _GDIPlus_PenDispose ($hPen)
   _GDIPlus_GraphicsDispose ($hGraphic)
   _GDIPlus_Shutdown ()
   Exit
  case $test[1]
   msgbox(0,"",$msg)
 EndSwitch
 Sleep(50)
WEnd

Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
 _WinAPI_RedrawWindow($GUI, 0, 0, $RDW_UPDATENOW + $RDW_VALIDATE)
    Return $GUI_RUNDEFMSG
EndFunc

func tableOnClick($rowId,$colId)
 ;; reset format, better save formats and reset single
 For $i = 1 To $xRows ;$iRows
  For $j = 1 To $xCols ;$iColumns
   if $i = 1 then ;header
    GUICtrlSetBkColor($table2[$i][$j],0xEEEEEE )
   elseif $j = 1 then ;leftBorder
    GUICtrlSetBkColor($table2[$i][$j],0xEEEEEE )
   else
    GUICtrlSetBkColor($table2[$i][$j], 0xFFFFFF)
   endif
   ;$xCurrBoxLeft += $xWidth + $xGapWidth
  Next
 Next
 ;; set format (via table UDF)
 ; if $colId = 1 then  _GUICtrlTable_Set_CellColor_Row($Table2, $rowId, 0xFFFF80)
 ; if $rowId = 1 then  _GUICtrlTable_Set_CellColor_Column($Table2, $colid, 0xFFFF80)
 ; _GUICtrlTable_Set_CellColor_Cell($table2,$rowId,$colId,0xFFFF80)
endfunc
Edited by ReFran
Link to post
Share on other sites

Try this:

#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
;#include "Table.au3"
#include <Array.au3>

$iWidth = 450
$iHeight = 450
$GUI = GUICreate("Table Test", $iWidth, $iHeight)
;----- Make sure GUI exists BEFORE creating Tables -----
GUISetState()

;----- Lock GUI until tables drawn -----
GUISetState(@SW_LOCK)

DIM $xRows = 20, $xCols = 7
DIM $xLeft = 25, $xTop = 130, $xWidth = 55, $xHeight = 13
DIM $table2[$xrows+1][$xCols+1]
DIM $xCurrBoxLeft = 0, $xCurrBoxTop = 0, $xGridWidth = 1

CreateTable($table2)
func CreateTable(ByRef $xtable,$xLeft = 25, $xTop = 130, $xWidth = 55, $xHeight = 13,$xRows = 5, $xCols = 5,$xGridWidth = 1)
 local $xCurrBoxLeft = 0, $xCurrBoxTop = 0
 $xRows = ubound($xtable,1)-1
 $xCols = ubound($xtable,2)-1
 ;msgbox(0,"",$xRows&" / "&$xCols)
 For $i = 1 To $xRows ;$iRows
  For $j = 1 To $xCols ;$iColumns
   $xtable[$i][$j] = GUICtrlCreateLabel("", $xleft + $xCurrBoxLeft, $xTop + $xCurrBoxTop, $xWidth, $xHeight)
   if $i = 1 then ;header
    GUICtrlSetBkColor(-1,0xEEEEEE )
    GuiCtrlSetData(-1,"Col "&$j)
   elseif $j = 1 then ;leftBorder
    GUICtrlSetBkColor(-1,0xEEEEEE )
    GuiCtrlSetData(-1,"Row "&$i)
   else
    GUICtrlSetBkColor(-1, 0xFFFFFF)
   endif
   if $i = 1 and $j = 1 then GuiCtrlSetData(-1,"Table")
   $xCurrBoxLeft += $xWidth + $xGridWidth
  Next
  $xCurrBoxLeft = 0
  $xCurrBoxTop += $xHeight + $xGridWidth
 Next
endfunc
$table2HdlFirst = $table2[1][1]
$table2HdlEnd = $table2[$xRows][$xCols]
GUISetState(@SW_UNLOCK)

dim $Test[3]
$test[1] = GUICtrlCreateLabel("Test",10,420,60,20)

GUISetState()

; Draw lines
;_GDIPlus_GraphicsDrawLine($hGraphics, $iX1, $iY1, $iX2, $iY2[, $hPen = 0])
_GDIPlus_Startup ()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($GUI)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic)
$hGfxContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
$hPen = _GDIPlus_PenCreate ()

DrawBorder()


func DrawBorder()
 ;;outline all
   ;;top-line
 _GDIPlus_GraphicsDrawLine ($hGfxContext, $xleft-1, $xtop-1, $xleft-1 +(($xWidth+$xGridWidth)*$xCols), $xtop-1, $hPen)
   ;;leftline
 _GDIPlus_GraphicsDrawLine ($hGfxContext, $xleft-1, $xtop-1, $xleft-1 , $xtop-1 +(($xHeight+$xGridWidth)*$xRows), $hPen)
   ;; bottom line
 _GDIPlus_GraphicsDrawLine ($hGfxContext, $xleft-1, $xtop-1 +(($xHeight+$xGridWidth)*$xRows), $xleft-1 +(($xWidth+$xGridWidth)*$xCols), $xtop-1 +(($xHeight+$xGridWidth)*$xRows), $hPen)
   ;; right line
 _GDIPlus_GraphicsDrawLine ($hGfxContext, $xleft-1 + (($xWidth+$xGridWidth)*$xCols), $xtop-1, $xleft-1 + (($xWidth+$xGridWidth)*$xCols) , $xtop-1 +(($xHeight+$xGridWidth)*$xRows), $hPen)
 ;; outline header (underline first row)
 _GDIPlus_GraphicsDrawLine ($hGfxContext, $xleft-1, $xtop-1 +(($xHeight+$xGridWidth) * 1), $xleft-1 +(($xWidth+$xGridWidth)*$xCols), $xtop-1 +(($xHeight+$xGridWidth)* 1), $hPen)
 ;; outline left Border ()
 _GDIPlus_GraphicsDrawLine ($hGfxContext, $xleft-1 +(($xWidth+$xGridWidth)*1), $xtop-1, $xleft-1 +(($xWidth+$xGridWidth)*1), $xtop-1 +(($xHeight+$xGridWidth)*$xRows), $hPen)
 endfunc
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iWidth, $iHeight)
GuiSetState()

GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")

;----- Loop -----
While 1
 $Msg = GUIGetMsg()
 if $msg > $table2HdlFirst-1 and $msg < $table2HdlEnd +1 then
   $RowId = INT((+$msg-$table2HdlFirst)/$xCOLS)+1
   $colId = +$msg-$table2HdlFirst-(($rowId-1)*$xCOLS)+1
   ;msgbox(0,"","Address: R"&$RowId &"C"&$colId)
   tableOnClick($rowId,$colId)
 endif
 Switch $Msg
  Case $GUI_EVENT_CLOSE
   ; Clean up resources
   _GDIPlus_PenDispose ($hPen)
   _GDIPlus_BitmapDispose($hBitmap)
   _GDIPlus_GraphicsDispose ($hGfxContext)
   _GDIPlus_GraphicsDispose ($hGraphic)
   _GDIPlus_Shutdown ()
   Exit
  case $test[1]
   msgbox(0,"",$msg)
 EndSwitch
;~  Sleep(50)
WEnd

Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    If @OSBuild > 5999 Then _WinAPI_RedrawWindow($GUI, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW))
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iWidth, $iHeight)
    Return $GUI_RUNDEFMSG
EndFunc


func tableOnClick($rowId,$colId)
 ;; reset format, better save formats and reset single
 For $i = 1 To $xRows ;$iRows
  For $j = 1 To $xCols ;$iColumns
   if $i = 1 then ;header
    GUICtrlSetBkColor($table2[$i][$j],0xEEEEEE )
   elseif $j = 1 then ;leftBorder
    GUICtrlSetBkColor($table2[$i][$j],0xEEEEEE )
   else
    GUICtrlSetBkColor($table2[$i][$j], 0xFFFFFF)
   endif
   ;$xCurrBoxLeft += $xWidth + $xGapWidth
  Next
 Next
 ;; set format (via table UDF)
 ; if $colId = 1 then  _GUICtrlTable_Set_CellColor_Row($Table2, $rowId, 0xFFFF80)
 ; if $rowId = 1 then  _GUICtrlTable_Set_CellColor_Column($Table2, $colid, 0xFFFF80)
 ; _GUICtrlTable_Set_CellColor_Cell($table2,$rowId,$colId,0xFFFF80)
endfunc

Gruß,

UEZ

Edited by 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 post
Share on other sites

I hate the difference between WinXP and Vista+ OS.

Code from post#2 updated.

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 post
Share on other sites

"I hate the difference between WinXP and Vista+ OS."

Maybe good that I saved the first one - company just testing Win7 upgrade.

Under XP the change forground <-> background now works very well.

Using Min/Max the lines escape furtheron.

Maybe someone with XP can test/solve.

Thanks, Reinhard

Link to post
Share on other sites

Hi,

got it with this wm_paint function:

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

_WinAPI_RedrawWindow($GUI, 0, 0, $RDW_UPDATENOW)

_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iWidth, $iHeight)

_WinAPI_RedrawWindow($GUI, 0, 0, $RDW_VALIDATE)

Return $GUI_RUNDEFMSG

EndFunc

Thanks for your support, Reinhard

Edited by ReFran
Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...