Sign in to follow this  
Followers 0
moczymorda

Count char and reset GUI

2 posts in this topic

#1 ·  Posted (edited)

This is sample of my script:

#include <GUIConstants.au3>
#include <array.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Char count", 703, 500, 193, 115)

GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Load file", 8, 15, 250, 81)
$Path = GUICtrlCreateInput("", 16, 47, 145, 21)
$Browse = GUICtrlCreateButton("Browse", 168, 47, 81, 22, 0)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $msg = GUIGetMsg()

        Switch $msg
        Case $GUI_EVENT_CLOSE
        Exit
    EndSwitch
    
    If $msg = $Browse Then

        $file = FileOpenDialog("open","C:\","(*.txt)",3,"",$Form1)
        If @error Then ContinueLoop
        GUICtrlSetData($Path, $file)
        
        $PathSv = GUICtrlRead($Path)
        
    Local $aAlph = StringSplit('abcdefghijklmnopqrstuvwxyz', '')
    Local $aArray[UBound($aAlph)], $sString = FileRead($PathSv)
    For $iCC = 1 To UBound($aAlph) - 1
        StringReplace($sString, $aAlph[$iCC], '')
        $aArray[$iCC] = @extended
        
GUICtrlCreateGraphic(23, 91+$iCC*15, $aArray[$iCC], 10)
GUICtrlSetBkColor(-1, 0xffffff)
GUICtrlSetColor(-1, 0)
GUICtrlCreateLabel($aAlph[$iCC], 10, 89+$iCC*15, 10, 11)
GUICtrlCreateLabel($aArray[$iCC], 23+$aArray[$iCC]+5, 89+$iCC*15, 36, 11)           
            
            
    Next

    EndIf   
    
WEnd

This script count A B C char from *.txt file and show as graph. I have questions:

2. How reset graph when i need load another file.

Thx for any help.

Edited by moczymorda

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Using WM_PAINT and GDI drawing:

#include <GUIConstants.au3>#include <array.au3>


#include <WinAPI.au3>

Global Const $TRANSPARENT = 1

Global $aAlph = StringSplit(&apos;abcdefghijklmnopqrstuvwxyz&apos;, &apos;&apos;)
Global $aArray[UBound($aAlph)]
$gdi_dll = DllOpen("gdi32.dll")

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Char count", 703, 500, 193, 115)
$pic = GUICtrlCreatePic("",53,91,700,500)
;~ GuiCtrlSetState($pic,$GUI_DISABLE)
$pic_hWnd = ControlGetHandle($Form1,"",$pic)
$hdc = _WinAPI_GetDC($pic_hWnd)

GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Load file", 8, 15, 250, 81)
$Path = GUICtrlCreateInput("", 16, 47, 145, 21)
$Browse = GUICtrlCreateButton("Browse", 168, 47, 81, 22, 0)

GUISetState(@SW_SHOW)
#EndRegion ### START Koda GUI section ### Form=

GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")

While 1
 $msg = GUIGetMsg()

 Switch $msg
    Case $GUI_EVENT_CLOSE
       Exit
 EndSwitch

 If $msg = $Browse Then

    $file = FileOpenDialog("open", "C:\", "(*.txt)", 3, "", $Form1)
    If @error Then ContinueLoop
    GUICtrlSetData($Path, $file)

    $PathSv = GUICtrlRead($Path)

    $sString = FileRead($PathSv)
    For $iCC = 1 To UBound($aAlph) - 1
       StringReplace($sString, $aAlph[$iCC], &apos;&apos;)
       $aArray[$iCC] = @extended

;~    GUICtrlCreateGraphic(23, 91 + $iCC * 15, $aArray[$iCC], 10)
;~    GUICtrlSetBkColor(-1, 0xffffff)
;~    GUICtrlSetColor(-1, 0)
;~    GUICtrlCreateLabel($aAlph[$iCC], 10, 89 + $iCC * 15, 10, 11)
;~    GUICtrlCreateLabel($aArray[$iCC], 23 + $aArray[$iCC] + 5, 89 + $iCC * 15, 36, 11)
    Next
    _WinAPI_InvalidateRect($Form1, 0, 1) ; Erase=true
 EndIf
WEnd

_WinAPI_ReleaseDC($pic_hWnd, $hDC)
Exit

Func DrawGraph() 
 ; clear background
 $tRect = _WinAPI_GetClientRect($pic_hWnd)
 _WinAPI_FillRect($hdc, DllStructGetPtr($tRect), _WinAPI_GetSysColorBrush($COLOR_BTNFACE))
 
 $size = 5
 $color = 0x0000FF
 _WinAPI_SetBkMode($hDC, $TRANSPARENT)
 $pen = DLLCall($gdi_dll,"int","CreatePen","int",0,"int",$size,"int",$color)
 $obj_orig = DLLCall($gdi_dll,"int","SelectObject","int",$hdc,"int",$pen[0])
 For $iCC = 1 To UBound($aAlph) - 1
    DLLCall($gdi_dll,"int","MoveToEx","int",$hdc,"int",23,"int",$iCC * 15 + 10,"int",0)
    DLLCall($gdi_dll,"int","LineTo","int",$hdc,"int",23 + $aArray[$iCC],"int",$iCC * 15 + 10) ;one horizontal line
    DllStructSetData($tRect, "Left",0)
    DllStructSetData($tRect, "Right",23 + $aArray[$iCC] + 5 + 25)
    DllStructSetData($tRect, "Top",$iCC * 15)
    DllStructSetData($tRect, "Bottom",$iCC * 15 + 20)
    _WinAPI_DrawText($hdc, $aAlph[$iCC], $tRect, BitOR($DT_SINGLELINE, $DT_LEFT, $DT_VCENTER))
    _WinAPI_DrawText($hdc, $aArray[$iCC], $tRect, BitOR($DT_SINGLELINE, $DT_RIGHT, $DT_VCENTER))
 Next
 DLLCall($gdi_dll,"int","SelectObject","int",$hdc,"int",$obj_orig[0])
 DLLCall($gdi_dll,"int","DeleteObject","int",$pen[0])
EndFunc

Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
 _WinAPI_RedrawWindow($pic_hWnd, 0, 0, $RDW_UPDATENOW) ; force redraw of pic (Rect=0 Region=0)
 DrawGraph() ; then draw my stuff on top
 _WinAPI_RedrawWindow($pic_hWnd, 0, 0, $RDW_VALIDATE) ; then force no-redraw of pic
 Return $GUI_RUNDEFMSG
EndFunc

Func _WinAPI_SetBkMode($hDC, $iBkMode)
 Local $aResult = DllCall( "gdi32.dll", "int", "SetBkMode", "ptr", $hDC, "int", $iBkMode)
 If @error Then Return SetError(@error, 0, 0)
 Return $aResult[0]
EndFunc ;==>_WinAPI_SetBkMode

post-6483-1230559092_thumb.png

Edited by Zedna

Share this post


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
Sign in to follow this  
Followers 0