Jump to content

Working with Dynamic/Unknown GUI ctrls


Recommended Posts

Hey everyone I hope you will be doin fine...

I am trying to make a GUI which will be working as a forum interface but I'm stuck at working with some controls.

Here is my work:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <TabConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <String.au3>

#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 550, 437, 192, 124)
$Tab1 = GUICtrlCreateTab(0, 0, 550, 417)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)

$file = FileOpen("forum.htm", 0)
; Check if file opened for reading OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
; Read in lines of text until the EOF is reached
While 1
Local $line = FileReadLine($file)
If @error = -1 Then ExitLoop
If StringInStr($line, '<a href="forumdisplay.php?f=') Then ; means line contains needed data
$Array = _StringBetween($line, '<a href="forumdisplay.php?f=', '>')
$aArray = _StringBetween($line, '<a href="forumdisplay.php?f=' & $Array[0] & '>', '</a>')
If StringInStr($aArray[0], "Section ", 1) Then ;this line contains section info
$TabSheet = GUICtrlCreateTabItem(Validate($aArray[0], 1))
$treeview = GUICtrlCreateTreeView(8, 40, 193, 369, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$Label = GUICtrlCreateLabel("Description:", 248, 48, 200, 21)
GUICtrlSetFont(-1, 9, 400, 0, "Segoe UI")
$Input = GUICtrlCreateEdit("", 248, 80, 281, 117, BitOR($ES_CENTER,$ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_HSCROLL,$WS_VSCROLL))
GUICtrlSetFont(-1, 8, 400, 0, "Segoe UI")
ElseIf StringInStr($aArray[0], "<strong>", 1) Then ;contains section forums
$line = Validate($line, 2)
$value = _StringBetween($aArray[0], '>', '</')
$item = GUICtrlCreateTreeViewItem(Validate($aArray[0], 1), $treeview)
GUICtrlSetColor(-1, 0x0000C0)
Else ;contains sub forums
GUICtrlCreateTreeViewItem(Validate($aArray[0], 1), $item)
EndIf
EndIf
If StringInStr($line, '<div class="smallfont">') Then ;its description of the forums
$aArray = _StringBetween($line, '<div class="smallfont">', '<')
$value = Validate($aArray[0], 1)
GUICtrlSetData($Input, $value)
EndIf
WEnd

FileClose($file)

$StatusBar1 = _GUICtrlStatusBar_Create($Form1)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $item
;IDK How to display description infromation of the clicked item???

EndSwitch
WEnd

Func Validate($text, $func)
If $func = 1 Then
$text = StringRegExpReplace($text, '<([^%]*?)>', '')
$text = StringReplace($text, "&amp;", "&")
Return $text
ElseIf $func = 2 Then
$text = StringReplace($text, @CRLF, "")
Return $text
EndIf
EndFunc ;==>Validate

I want that when we click on an item then it should display its description text in EditBox but don't know how to do it, any help would be appericiated...

forum.htm

Edited by NicePerson
Link to comment
Share on other sites

Try with the classname='smallfont'

after getting the link try to find for the next <Div> which has the class as 'smallfont'

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

@PhoenixXL Thanks, but thats already done in the code...

Here is a simple example code of my problem:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 178, 450, 192, 124)

$buttonsToCreate = 8
$buttons = 0
$Button0 = GUICtrlCreateButton("Button 0", 16, 16, 145, 41, $WS_GROUP)
$buttonTop = 64
While $buttons <> $buttonsToCreate
$buttons += 1
GUICtrlCreateButton("Button " & $buttons, 16, $buttonTop, 145, 41, $WS_GROUP)
$buttonTop = $buttonTop + 48
WEnd
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button0
MsgBox(0,"","Button 0 clicked")


EndSwitch
WEnd

I want to know how to do something when other buttons are clicked ??

I hope now its easy to understand what I'm trying to say.

Edited by NicePerson
Link to comment
Share on other sites

Is this is what you want

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 178, 450, 192, 124)

$buttonsToCreate = 8
$buttons = 0
$Button0 = GUICtrlCreateButton("Button 0", 16, 16, 145, 41, $WS_GROUP)
$buttonTop = 64
While $buttons <> $buttonsToCreate-1
$buttons += 1
GUICtrlCreateButton("Button " & $buttons, 16, $buttonTop, 145, 41, $WS_GROUP)
$buttonTop = $buttonTop + 48
WEnd
$buttonLast=GUICtrlCreateButton("Button " & $buttonsToCreate, 16, $buttonTop, 145, 41, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button0 To $buttonLast
MsgBox(0,"Information",GUICtrlRead($nMsg)&" clicked")


EndSwitch
WEnd
Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Well

BTW if you are dealing with huge no. of buttons this Func should help

GenerateButtons(5,2)
GenerateButtons(20,10)
GenerateButtons(3,1)
GenerateButtons(6,2)
GenerateButtons(90,2)


Func GenerateButtons($sNumber,$sLine=1,$Width=70,$Height=50,$sButtonSpacing=10,$hBorderSpacing=20)
If $sLine>=$sNumber Then $sLine=$sNumber
Local $sMaxButton=Ceiling($sNumber/$sLine)
Local $Form2 = GUICreate("Phoenix XL _Testing.au3", _
($sMaxButton*$Width)+(2*$hBorderSpacing)+(($sMaxButton-1)*$sButtonSpacing), _
($sLine*$Height)+(2*$hBorderSpacing)+(($sLine-1)*$sButtonSpacing))
Global $Buttons[$sNumber+1]
Local $h = $hBorderSpacing
Local $w = $hBorderSpacing
For $i=1 To $sNumber
$Buttons[$i]=GUICtrlCreateButton(0,$w,$h,$Width,$Height)
GUICtrlSetTip(-1,'Button Number: '&$i,'Information',1,3)
If IsMultiple($i,$sMaxButton) Then
$h+=$Height+$sButtonSpacing
$w = $hBorderSpacing
Else
$w+=$Width+$sButtonSpacing
EndIf
Next
GUISetState()
Local $nMsg
While 1
$nMsg=GUIGetMsg()
Switch $nMsg
Case -3
Return GUIDelete($Form2)
Case $Buttons[1] To $Buttons[$sNumber]
GUICtrlSetData($nMsg,Number(GUICtrlRead($nMsg))+1)
EndSwitch
WEnd
EndFunc

Func IsMultiple($nNumber,$sFactor)
If IsInt($nNumber/$sFactor) Then Return 1
Return 0
EndFunc

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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