Jump to content

When I locked button, can't exit...


Luigi
 Share

Recommended Posts

Hi all!

I write a little program, it store some datas like 'name', 'address', 'age' and 'file picture's location'. Have some functions: Add, Update, Remove, Next and Previous. Everything is store in a 'ini' file.

I can't two problems.

a] when you stay in the first it block the 'previous' button and you stay in the last registry the 'next' button is locked too... But the script cannot exit with a simple ESC if exist a locked button, and the windows beep is played... I have used two commands:

GUICtrlSetState($Previous,$GUI_ENABLE)

ControlEnable("","",$Previous)

They return the same result, cannot exit and played sound...

Script lines: 101 to 117;

b] I have dificult to delete a image displayed, I need create a new picture in the same color's background and put there when have no image... It's simulate a no picture, but have a picture there... How do remove a pic?

Script lines: 129 to 140 (Func _ShowImage)

Thanks for any help.

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <image_get_info.au3>
; English version
_GDIPlus_Startup()
Local $Ini = "config.ini"
Local $Window
Local $Add, $Alter, $Del
Local $Amount, $AmountOld, $Reg = IniRead($Ini,"Config","Registro",""), $RegOld
 
$Amount = IniReadSectionNames($Ini)
$Amount = $Amount[0]-1
;ConsoleWrite(StringFormat("%08s",$Amount) & @LF)
GUICreate(".",800,600)
GUISetState()
GUICtrlCreateGroup("",10,30,780,500)
GUICtrlCreateGroup("Picture",450,72,300,300)
GUICtrlCreateLabel("Registry:",97,50)
$Quantos = GuiCtrlCreateLabel($Amount,160,50,80,20)
$Add = GUICtrlCreateButton("Add",600,550,80,23)
$Salvar = GUICtrlCreateButton("Save",500,550,80,23)
$Apagar = GUICtrlCreateButton("Delete",400,550,80,23)
$Next = GUICtrlCreateButton(">",710,550,80,23)
$Previous = GUICtrlCreateButton("<",10,550,80,23)
GUICtrlCreateLabel("Name:",110,80)
$Name = GUICtrlCreateInput("",160,80,200,20)
GUICtrlCreateLabel("Age:",122,110,120,20)
$AgeDeAtalho = GUICtrlCreateInput("",160,110,200,20)
GUICtrlCreateLabel("Address:",96,140)
$AddressDeFerramentas = GUICtrlCreateInput("",160,140,200,20)
GUICtrlCreateLabel("Picture:",105,170)
$Picture = GUICtrlCreateInput("",160,170,200,20)
$SelectPicture = GUICtrlCreateButton("...",370,170,30,20)
$pic = GUICtrlCreatePic("", 460, 95)
While 1
_Amount()
$msg = GuiGetMSG()
Select
  Case $msg = $GUI_EVENT_CLOSE
   _GDIPlus_ShutDown()
   IniWrite($Ini,"Config","Registro",$Reg)
   Exit
  Case $msg = $Add
   $Amount +=1
   IniWrite($Ini,$Amount,"Name",GuiCtrlRead($Name))
   IniWrite($Ini,$Amount,"Age",GuiCtrlRead($AgeDeAtalho))
   IniWrite($Ini,$Amount,"Address",GuiCtrlRead($AddressDeFerramentas))
   IniWrite($Ini,$Amount,"Picture",_StringDiference($FilePicture,@ScriptDir))
  Case $msg = $Apagar
   IniDelete($Ini,$Reg)
   For $x = $Reg + 1 To $Amount
    IniWrite($Ini,$x-1,"Name",IniRead($Ini,$x,"Name",""))
    IniWrite($Ini,$x-1,"Age",IniRead($Ini,$x,"Age",""))
    IniWrite($Ini,$x-1,"Picture",IniRead($Ini,$x,"Picture",""))
    IniWrite($Ini,$x-1,"Address",IniRead($Ini,$x,"Address",""))
   Next
   IniDelete($Ini,$Amount)
   $Reg = $Reg -1
   $Amount = IniReadSectionNames($Ini)
   $Amount = $Amount[0]-1
  Case $msg = $Salvar
   IniWrite($Ini,$Reg,"Name",GuiCtrlRead($Name))
   IniWrite($Ini,$Reg,"Age",GuiCtrlRead($AgeDeAtalho))
   IniWrite($Ini,$Reg,"Address",GuiCtrlRead($AddressDeFerramentas))
   IniWrite($Ini,$Reg,"Picture",GuiCtrlRead($Picture))
   _ShowImage(GuiCtrlRead($Picture))
  Case $msg = $SelectPicture
   $FilePicture = FileOpenDialog("Select picture",@ScriptDir & "\","Pictures (*.bmp)",1+4)
   If @error Then
   Else
    GuiCtrlSetData($Picture,_StringDiference($FilePicture,@ScriptDir))
    $info = _ImageGetInfo($FilePicture)
    $info = StringSplit($info,@lf)
    $PicWidth = StringReplace($info[1],"Width=","")
    ConsoleWrite($PicWidth & @LF)
    $PicHeight = StringReplace($info[2],"Height=","")
    ConsoleWrite($PicHeight & @LF)
    _ShowImage($FilePicture)
   EndIf
  Case $msg = $Next
   $Reg +=1
  Case $msg = $Previous
   $Reg -=1
EndSelect
_Registro()
WEnd
;===
Func _Registro()
If $Reg <> $RegOld Then
  If $Reg <= 1 Then
   $Reg = 1
   ;GUICtrlSetState($Previous,$GUI_DISABLE)
   ControlDisable("","",$Previous)
  Else
   ;GUICtrlSetState($Previous,$GUI_ENABLE)
   ControlEnable("","",$Previous)
  EndIf
  If $Reg >= $Amount Then
   $Reg = $Amount
   ;GUICtrlSetState($Next,$GUI_DISABLE)
   ControlDisable("","",$Next)
  Else
   ;GUICtrlSetState($Next,$GUI_ENABLE)
   ControlEnable("","",$Next)
  EndIf
  GUICtrlSetData($Quantos,$Reg & "/" & $Amount)
  GuiCtrlSetData($Name,IniRead($Ini,$Reg,"Name",""))
  GuiCtrlSetData($AddressDeFerramentas,IniRead($Ini,$Reg,"Address",""))
  GuiCtrlSetData($AgeDeAtalho,IniRead($Ini,$Reg,"Age",""))
  $i = IniRead($Ini,$Reg,"Picture","")
  GuiCtrlSetData($Picture,$i)
  _ShowImage($i)
  $RegOld = $Reg
EndIf
EndFunc
;===
Func _ShowImage($entrada)
If FileExists($entrada) = 0 Then
  $pic = GUICtrlCreatePic("nada.jpg", 460, 95, 24,24)
  GUICtrlSetImage(-1,"nada.jpg")
Else
  $info = _ImageGetInfo($entrada)
  $info = StringSplit($info,@lf)
  $PicWidth = StringReplace($info[1],"Width=","")
  $PicHeight = StringReplace($info[2],"Height=","")
  $pic = GUICtrlCreatePic($entrada, 460, 95, $PicWidth,$PicHeight)
  GUICtrlSetImage($pic,$entrada)
EndIf
EndFunc
;===
Func _Amount()
If $Amount <> $AmountOld Then
  GUICtrlSetData($Quantos,$Reg & "/" & $Amount)
  $AmountOld = $Amount
EndIf
EndFunc
;===
Func _StringDiference($aa,$bb)
Local $a = StringLen($aa), $b = StringLen($bb)
Local $big, $small, $y
If $a > $b Then
  $big = $aa
  $small = $bb
  $y = $a
ElseIf $b > $a Then
  $big = $bb
  $small = $aa
  $y = $b
ElseIf $a = $b Then
  Return $aa
EndIf
$x = 0
While $x < $y
  If Not (StringMid($big,$x+1,1) == StringMid($small,$x+1,1)) Then ExitLoop
  $x +=1
WEnd
Return StringMid($big,$x+2,$y)
EndFunc

[config]
registro=3
[1]
Name=Trevor Blaster
Age=20
Picture=0000.bmp
Address=
[3]
Name=4
Age=4
Picture=
Address=
[2]
Name=3
Age=3
Picture=0001.bmp
Address=

nada.bmp

0000.bmp

0001.bmp

Visit my repository

Link to comment
Share on other sites

Hi,

Were is: #include <image_get_info.au3>

You must place the image control after call GuiCreate:

GUICreate(".", 800, 600)
$pic = GUICtrlCreatePic("", 460, 95)

João Carlos

Edited by jscript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

I can solve the problem, update a funcion.

Func _ShowImage($entrada)
If Not ($ver == $verOld) Then
  GUICtrlDelete($pic)
  $ver = $verOld
EndIf
If FileExists($entrada) = 0 Then
  $ver = ""
Else
  $info = _ImageGetInfo($entrada)
  $info = StringSplit($info,@lf)
  $PicWidth = StringReplace($info[1],"Width=","")
  $PicHeight = StringReplace($info[2],"Height=","")
  $pic = GUICtrlCreatePic($entrada, 460, 95, $PicWidth,$PicHeight)
  GUICtrlSetImage($pic,$entrada)
  $ver = $entrada
EndIf
EndFunc

Visit my repository

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