Jump to content
nacerbaaziz

a problem when create a array 3d

Recommended Posts

hello sirs, please help me

i tried to create a function that read a folder files to 3d array

e.g

$array[n][0][0] = ctName

$array[n][0][1] = ctFilePath

$array[n][0][2] = crtsections number

$array[n][m][0] = KeyName

$array[n][m][1] = KeyVal

$array[n][m][2] = keySectionName

 

that the array

when i put one file into the folder all things work fine

but when i put more than one file

the last file worked fine but the others only the first key is showing

please can you help me to correct this problem

here is the example with the folder

please accept my greetings

and thanks in advance

 

array3d.zip

Edited by nacerbaaziz
added the tags

Share this post


Link to post
Share on other sites

Thanks, just found a post from PSalty with an example which explained it, just never seen it previously, learnt something new.

Share this post


Link to post
Share on other sites

@czardas arrayworkshop is a great thread for learning more than you want,  the fruit cube is how i got comfortable manipulating stuff

 

 


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

my problem isn't in the array creation

 until now i can't know where is the problem exact

please if any one of you can download and try to tell me where is the problem

thx in advance 

Share this post


Link to post
Share on other sites

I've got the files but what I don't understand is what attributes or data you want to assign to each array dimension and what you want to store in each array cell.

AFAICT you only need a 2D array, so I must be overlooking something important to you.

A 3D array is perfect to represent, for instance, one attribute of points in cartesian coordinates: if (X, Y, Z) are point coordinates in air, the array may store, for instance, the température of air at that point.  Then the array once filled gives you T° = f(X, Y, Z).

How does this simple example apply to your data?


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
8 minutes ago, jchd said:

I've got the files but what I don't understand is what attributes or data you want to assign to each array dimension and what you want to store in each array cell.

AFAICT you only need a 2D array, so I must be overlooking something important to you.

A 3D array is perfect to represent, for instance, one attribute of points in cartesian coordinates: if (X, Y, Z) are point coordinates in air, the array may store, for instance, the température of air at that point.  Then the array once filled gives you T° = f(X, Y, Z).

How does this simple example apply to your data?

am making an links store

and that tool has a categorys

and evry category is in a file

that file as a ini file

and what i want is to store the data in a 3d array

that the 1d to change the categorys and the 2d is to change the ini sections, and the last is to store the links information as the name of link and the url

i hope that you understand what i want

Share this post


Link to post
Share on other sites

You only need a 2D array:

Category    LinkName    URL
test    faceBook    https://facebook.com/
test    twitter https://twitter.com/
test    honeygain   https://honeygain.com/
test2   google  https://google.com/
test2   gmail   https://gmail.com/
test2   youtube https://youtube.com/
test3   mx-blind    https://mx-blind.com/
test3   wordpress   https://wordpress.com/
test3   blind help  https://blindhelp.net/

This is TSV format so you can copy-paste and directly load into a 2D array. Leave the headers alone as it will simplify access.

BTW if you intent to have a large number of links, you might turn to SQLite.

Here's a SQL source file (containing SQLite-compatible statements) you can use to create the database corresponding to the table shown above:

Links.sql


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

i liked to use the 3d because i have a treeview and list box

for that to get the info from one to one i must use a array

but if you mean that no whey to do that, then i have to change all my function .

i hope any one can help me to correct that 

Share this post


Link to post
Share on other sites
4 minutes ago, nacerbaaziz said:

i liked to use the 3d because i have a treeview and list box

for that to get the info from one to one i must use a array

I provided an example of use of an array, didn't I?

I still fail to see how you would cram your data in 3 dimensions, still keeping ease of use, access, search and coding.  I'm not saying this is impossible, just that it's neither useful nor practical.

To make a parallel, think about a personal address book. A (very simple) address consists of: country, state, zipcode, city, street, number, floor, appartment number.  That's 8 entities for that simple case, many real-world addresses are much more complex.

There are two diametrally extreme ways to organize storage for addresses like that: a 2D-array where each entry (row) contains 8 columns to store the 8 components, or a 8D-array where each component represents a dimension.

A 2D-array fits well the personal use, but a 8D array is most suitable for administrative registers that lists all habitations/appartments in a large area.  Searching in a 2D array is much easier than selecting address components in a 8D-array.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Does this function contain any errors, please?

#include <iniex.au3>
#include <Array.au3>
#include <File.au3>
#include <fileOptions.au3>
Global $A_StoreDataRead[1][1][3]
Global $StoreDataDir = @ScriptDir & "\store_data"
Store_GetData()
Func Store_GetData($DataDir = $StoreDataDir)

    ReDim $A_StoreDataRead[1][1][3]

    Local $find = _FileListToArrayRec($DataDir, "*.CTG", $FLTAR_FILES, $FLTAR_NORECUR, $FLTAR_SORT, $FLTAR_FULLPATH)
    If $find[0] <= 0 Then Return SetError(1, 0, 1)


    Local $iAll = 0, $i = 1, $CrntPath = "", $sectionsRead, $SectionRead, $crntPathOpen, $CrntPathRead, $crntFileName
    For $iFiles = 1 To $find[0]

        $CrntPath = $find[$iFiles]
        $crntFileName = _GetFileName($CrntPath)
        $crntPathOpen = FileOpen($CrntPath)
        $CrntPathRead = FileRead($crntPathOpen)
        If @error Then
            FileClose($crntPathOpen)
            ContinueLoop
        EndIf
        FileClose($crntPathOpen)

        $sectionsRead = _IniReadSectionNamesFromString($CrntPathRead)
        If @error Then ContinueLoop
        $iAll += 1
        $i = 1
        For $scs = 1 To $sectionsRead[0]
            $i += 1
            ReDim $A_StoreDataRead[$iAll + 1][$i][3]
            If $sectionsRead[$scs] = "categoryInfo" Then
                $A_StoreDataRead[$iAll][0][0] = _IniReadFromString($CrntPathRead, "categoryInfo", "categoryName", "")
                $A_StoreDataRead[$iAll][0][1] = $crntFileName
                $i -= 1
            Else
                $A_StoreDataRead[$iAll][$i - 1][0] = _IniReadFromString($CrntPathRead, $sectionsRead[$scs], "linkName", "")
                $A_StoreDataRead[$iAll][$i - 1][1] = _IniReadFromString($CrntPathRead, $sectionsRead[$scs], "LinkValue", "")
                $A_StoreDataRead[$iAll][$i - 1][2] = $sectionsRead[$scs]
                $A_StoreDataRead[$iAll][0][2] = $i - 1
            EndIf
            MsgBox(64, "result", $A_StoreDataRead[$iAll][0][0] & @CRLF & $A_StoreDataRead[$iAll][0][1] & @CRLF & $A_StoreDataRead[$iAll][0][2] & @CRLF & $A_StoreDataRead[$iAll][$i - 1][0] & @CRLF & $A_StoreDataRead[$iAll][$i - 1][1] & @CRLF & $A_StoreDataRead[$iAll][$i - 1][2])
        Next
    Next
    $A_StoreDataRead[0][0][0] = $iAll

    MsgBox(64, "", $A_StoreDataRead[1][0][0] & @CRLF & $A_StoreDataRead[1][0][1] & @CRLF & $A_StoreDataRead[1][0][2])
    MsgBox(64, "", $A_StoreDataRead[1][1][0] & @CRLF & $A_StoreDataRead[1][1][1] & @CRLF & $A_StoreDataRead[1][1][2])
    MsgBox(64, "", $A_StoreDataRead[1][2][0] & @CRLF & $A_StoreDataRead[1][2][1] & @CRLF & $A_StoreDataRead[1][2][2])
    MsgBox(64, "", $A_StoreDataRead[1][3][0] & @CRLF & $A_StoreDataRead[1][3][1] & @CRLF & $A_StoreDataRead[1][3][2])

    MsgBox(64, "", $A_StoreDataRead[2][0][0] & @CRLF & $A_StoreDataRead[2][0][1] & @CRLF & $A_StoreDataRead[2][0][2])
    MsgBox(64, "", $A_StoreDataRead[2][1][0] & @CRLF & $A_StoreDataRead[2][1][1] & @CRLF & $A_StoreDataRead[2][1][2])
    MsgBox(64, "", $A_StoreDataRead[2][2][0] & @CRLF & $A_StoreDataRead[2][2][1] & @CRLF & $A_StoreDataRead[2][2][2])
    MsgBox(64, "", $A_StoreDataRead[2][3][0] & @CRLF & $A_StoreDataRead[2][3][1] & @CRLF & $A_StoreDataRead[2][3][2])

    MsgBox(64, "", $A_StoreDataRead[3][0][0] & @CRLF & $A_StoreDataRead[3][0][1] & @CRLF & $A_StoreDataRead[3][0][2])
    MsgBox(64, "", $A_StoreDataRead[3][1][0] & @CRLF & $A_StoreDataRead[3][1][1] & @CRLF & $A_StoreDataRead[3][1][2])
    MsgBox(64, "", $A_StoreDataRead[3][2][0] & @CRLF & $A_StoreDataRead[3][2][1] & @CRLF & $A_StoreDataRead[3][2][2])
    MsgBox(64, "", $A_StoreDataRead[3][3][0] & @CRLF & $A_StoreDataRead[3][3][1] & @CRLF & $A_StoreDataRead[3][3][2])


    Return 1
EndFunc   ;==>Store_GetData

 

Share this post


Link to post
Share on other sites

hello again

i found the problem, and i wanted to share it with you

here is the corrected function

thank you all to your help

with my greetings

func Store_GetData($DataDir = $StoreDataDir)

ReDim $A_StoreDataRead[1][1][3]

local $find = _FileListToArrayRec($DataDir, "*.CTG", $FLTAR_FILES, $FLTAR_NORECUR, $FLTAR_SORT, $FLTAR_FULLPATH)
    If not (isArray($find)) Then return SetError(1, 0, 1)
local $iAll = 0, $i = 1, $IcrntSec = 1, $CrntPath = "", $sectionsRead, $SectionRead, $crntPathOpen, $CrntPathRead, $crntFileName
for $iFiles = 1 to $find[0]

$crntPath = $find[$iFiles]
$crntFileName = _GetFileName($crntPath)
$crntPathOpen = FileOpen($crntPath)
$CrntPathRead = FileRead($crntPathOpen)
if @Error then
fileClose($crntPathOpen)
ContinueLoop
endIf
fileClose($crntPathOpen)

$SectionsRead = _IniReadSectionNamesFromString($CrntPathRead)
if @Error then ContinueLoop
$iAll += 1
$i = 1
for $scs = 1 to $SectionsRead[0]
$i += 1
if $IcrntSec < $i then
ReDim $A_StoreDataRead[$iAll+1][$i][3]
$IcrntSec = $i
else
ReDim $A_StoreDataRead[$iAll+1][$IcrntSec][3]


endIf
if $SectionsRead[$scs] = "categoryInfo" then
$A_StoreDataRead[$iAll][0][0] = _IniReadFromString($CrntPathRead, "categoryInfo", "categoryName", "")
$A_StoreDataRead[$iAll][0][1] = $crntFileName
$i -= 1
else
$A_StoreDataRead[$iAll][$i-1][0] = _IniReadFromString($CrntPathRead, $SectionsRead[$scs], "linkName", "")
$A_StoreDataRead[$iAll][$i-1][1] = _IniReadFromString($CrntPathRead, $SectionsRead[$scs], "LinkValue", "")
$A_StoreDataRead[$iAll][$i-1][2] = $SectionsRead[$scs]
$A_StoreDataRead[$iAll][0][2] = $i-1
endIf

next
next
$A_StoreDataRead[0][0][0] = $iAll

return 1
endFunc

 

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Colduction
      Hi dear friends!, i'm sorry for creating a new thread (a new problem), i have over than 9 lists that i want to combine them to be this (in this example, there are 3 test files):


      I've written a little code for splitting main information, but i really confused how to make results as "Output.txt", here is that code:
       
      $sRegex_1 = StringRegExp(FileRead("1.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3) $sRegex_2 = StringRegExp(FileRead("2.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3) $sRegex_3 = StringRegExp(FileRead("3.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3) For $i = 0 To UBound($sRegex_1) - 1 ConsoleWrite($sRegex_1[$i] & @CRLF) For $j = 0 To UBound($sRegex_2) - 1 ConsoleWrite($sRegex_2[$j] & @CRLF) For $k = 0 To UBound($sRegex_3) - 1 ConsoleWrite($sRegex_3[$k] & @CRLF) Next Next Next  
    • By nacerbaaziz
      hello evrybody
      here is an example about how to split your texts using a delimiter with the ability to select how much of delimiters shows in each colum  with $i_number
      e.g
      you have a long text and you want to split it in an array
      that evry colum have a number (n) of lines
      i made a function that do that for you
      just call it with a three params
      $s_text
      your text
      $i_number
      the number that you want to put in each col
      $s_siparator
      the siparator
      default is "|"
      here is the function with example
      i hope that it will be useful for you
       
      ****
       
      #include <Array.au3> $s_txt = "some text1some text2|some text3|some text4|some text5|some text6" $array = splitText($s_txt, 2) _ArrayDisplay($array) Func splitText($s_text, $i_number, $s_siparator = "|") Local $a_TXT = StringSplit($s_text, $s_siparator) Local $a_Return[$a_TXT[0] + 1] If ($a_TXT[0] <= $i_number) Or ($i_number <= 0) Then ReDim $a_Return[2] $a_Return[0] = 1 $a_Return[1] = $s_text Return $a_Return EndIf Local $i_Processed = 1, $i_arrayProcessed = 1 Do For $i = $i_Processed To ($i_Processed + $i_number) - 1 If ($a_TXT[0] < $i) Then ExitLoop If Not ($a_Return[$i_arrayProcessed]) Then $a_Return[$i_arrayProcessed] = $a_TXT[$i] Else $a_Return[$i_arrayProcessed] &= $s_siparator & $a_TXT[$i] EndIf $i_Processed += 1 Next $i_arrayProcessed += 1 Until ($a_TXT[0] < $i_Processed) ReDim $a_Return[$i_arrayProcessed] $a_Return[0] = $i_arrayProcessed - 1 Return $a_Return EndFunc ;==>splitText
      accept my greetings
      thanks to
      @Dan_555
      for his notes
       
    • By MesterPerfect
      good morning
      this is the first post here in the autoit forums
      i hope that you can help me in my problem
      i have a JSON encoded
      it a map of my forums
      where i want to make a treeview that have the same type of map
      e.g
      a system (as category)
      windows (as sub category)
      software (as an child item in the windows category)
      .....
      i don't know how to do that
      so, i know that i can do that using the json functions
      but i need your help about how we can do it as the type that i told you
      by the way i need to put the sub info for each item in an array that give me the ability to manage my items
      e.g
      can post thread
      can reply
      message cound ...
      you just give me a small example and i can continue.
      am sorry if this against the rules of the forum.
      but i realy searched a lot but i couldn't
      i hope some one give me the way.
      thank you very much in advance
       
      here is the link of json forum
      https://www.autoitscript.com/forum/topic/148114-a-non-strict-json-udf-jsmn/
      and here is my encoded json file
       
      { "tree_map": { "0": [ 1, 5, 6, 7 ], "1": [ 2 ], "2": [ 4 ], "5": [ 3 ], "6": [ 8 ], "8": [ 9, 10 ] }, "nodes": [ { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 1, "node_id": 1, "node_name": null, "node_type_id": "Category", "parent_node_id": 0, "title": "Main category", "type_data": {} }, { "breadcrumbs": [ { "node_id": 1, "title": "Main category", "node_type_id": "Category" } ], "description": "", "display_in_list": true, "display_order": 1, "node_id": 2, "node_name": null, "node_type_id": "Forum", "parent_node_id": 1, "title": "Main forum", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 1, "title": "Main category", "node_type_id": "Category" }, { "node_id": 2, "title": "Main forum", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 1, "node_id": 4, "node_name": null, "node_type_id": "Forum", "parent_node_id": 2, "title": "my forums1", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 2, "node_id": 5, "node_name": null, "node_type_id": "Category", "parent_node_id": 0, "title": "Perfect", "type_data": {} }, { "breadcrumbs": [ { "node_id": 5, "title": "Perfect", "node_type_id": "Category" } ], "description": "", "display_in_list": true, "display_order": 2, "node_id": 3, "node_name": null, "node_type_id": "Forum", "parent_node_id": 5, "title": "ahmed", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 3, "node_id": 6, "node_name": null, "node_type_id": "Forum", "parent_node_id": 0, "title": "autoit", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 6, "title": "autoit", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 3, "node_id": 8, "node_name": null, "node_type_id": "Forum", "parent_node_id": 6, "title": "examples", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 6, "title": "autoit", "node_type_id": "Forum" }, { "node_id": 8, "title": "examples", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 3, "node_id": 9, "node_name": null, "node_type_id": "Forum", "parent_node_id": 8, "title": "GUI", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 6, "title": "autoit", "node_type_id": "Forum" }, { "node_id": 8, "title": "examples", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 31, "node_id": 10, "node_name": null, "node_type_id": "Forum", "parent_node_id": 8, "title": "windowEX", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 4, "node_id": 7, "node_name": null, "node_type_id": "Category", "parent_node_id": 0, "title": "vbs", "type_data": {} } ] }  
    • By nooneclose
      I need to dynamically resize my 2d array while looping. 
      I know this code:
      ReDim $rArray[UBound($rArray) + 1] works for the rows, however, I also need to increase the columns. How would i go about increasing both rows and columns while looping? 
    • By nacerbaaziz
      question about _WinAPI_CreateWindowEx
      good morning
      welcome autoit team
      please i need your help
      i've searched a lot about how to use the _WinAPI_CreateWindowEx
      finally i found an example
      but i found some problem i hope you can help me
      firstly, i want to set the controls focussable with the keyboard input
      i already used the ws_tabStop but it did not work with me.
      secondly, i want to set some access keys linked with the window
      such as control+o enable the open button and control+f4 exit the app
      note: i need a local access keys and not a global hotkeys
      such as GUISetAccelerators
      finaly, before i will put the code here i must clarify a few things.
      1. you will ask me why you don't use the GUICreate function
      here i'll tell you that it as dialog and It is a little heavy in motion with screen readers.
      the screen readers for blind has some function that work with dialogs and others work with full windows style
      2. you will ask me why you didn't search the net for that?
      i will tell you that all examples that i found in the internet with pdfs and Picture books.
      i found some examples in microsoft but it with cpp.
      ok here is the code
      i hope you can help me to do what i want
      thank you in advance
       
      ; Small AutoIt Application that uses Windows API ; Written by Yuraj #NoTrayIcon #include <_RegisterClassEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <FontConstants.au3> AutoItSetOption("MustDeclareVars", 1) ; Window definitions Const $WinWidth = 370 Const $WinHeight = 350 Const $WinXPos = (@DesktopWidth / 2) - ($WinWidth / 2) Const $WinYPos = (@DesktopHeight / 2) - ($WinHeight / 2) Const $WinTitle = "Win32 Application - Text reader" Const $WinClass = "mainapp" Const $WinIcon = _WinAPI_LoadIcon(_WinAPI_GetModuleHandle("shell32.dll"), 13) ; Windows handles Global $hwnd, $edit1, $btn1, $btn2 ; Fonts Global $fnt1 ; Register class, Create the window Local $retVal = __WinAPI_RegisterClassEx($WinClass, "WindowCallback", $WinIcon, 0, _WinAPI_GetSysColor($COLOR_BTNFACE), BitOR($CS_DEFAULTSTYLE, $CS_DROPSHADOW)) ; If $retVal == 0 Then ; If registerclass fails MsgBox(16, "Error", "Error while registering window class!") Exit EndIf ; Create windows/controls $hwnd = _WinAPI_CreateWindowEx($WS_EX_STATICEDGE, $WinClass, $WinTitle, BitOR($WS_OVERLAPPED,$WS_SYSMENU, $WS_MINIMIZEBOX, $WS_GROUP, $WS_DLGFRAME), $WinXPos, $WinYPos, $WinWidth, $WinHeight, 0) $btn1 = _WinAPI_CreateWindowEx(0, "button", "Open file ...", BitOR($WS_VISIBLE, $WS_CHILD, $WS_TABSTOP, $WS_CLIPCHILDREN), 25, 270, 100, 30,$hwnd) $btn2 = _WinAPI_CreateWindowEx(0, "Button", "Exit", BitOR($WS_VISIBLE, $WS_CHILD, $WS_TABSTOP, $WS_CLIPCHILDREN), 235, 270, 100, 30, $hwnd) $edit1 = _WinAPI_CreateWindowEx(0, "edit", "text", BitOR($WS_VISIBLE, $WS_CHILD, $WS_VSCROLL, $ES_AUTOVSCROLL, $es_readOnly, $WS_TABSTOP), 5, 5, $WinWidth - 15, $WinHeight - 100, $hwnd) ; Set controls identifiers _WinAPI_SetWindowLong($btn1,$GWL_ID,150) _WinAPI_SetWindowLong($btn2,$GWL_ID,160) ; Set (controls) fonts $fnt1 = _CreateFont("MS Sans Serif", 15) _WinAPI_SetFont($btn1, $fnt1) _WinAPI_SetFont($btn2, $fnt1) _WinAPI_SetFont($edit1, $fnt1) ; Set focus to edit _WinAPI_SetFocus($edit1) ; Show window _WinAPI_ShowWindow($hwnd) _WinAPI_UpdateWindow($hwnd) ; Main loop that keep application opened While 1 Sleep(100) WEnd ;=================================================================; ; WINDOW CALLBACK ... ;=================================================================; Func WindowCallback($_hwnd, $iMsg, $wParam, $lParam) Local $iNC, $iID Switch $iMsg ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Case $WM_CLOSE ; Show message on closing If MsgBox(48 + 4, $WinTitle, "Do you want really exit?", 0, $hwnd) <> 6 Then Return 0 ; Call destructor and then exit main thread FinalizeApp() Exit ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Case $WM_COMMAND $iNC = _WinAPI_HiWord($wParam) $iID = _WinAPI_LoWord($lParam) Switch $iNC Case $BN_CLICKED ; When is control clicked Switch _WinAPI_GetDlgCtrlID($iID) Case _WinAPI_GetDlgCtrlID($btn1) BtnOpenFileClick() Case _WinAPI_GetDlgCtrlID($btn2) BtnExitClick() EndSwitch EndSwitch ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; EndSwitch Return _WinAPI_DefWindowProc($_hwnd, $iMsg, $wParam, $lParam) EndFunc ;==>WindowCallback Func FinalizeApp() _WinAPI_DeleteObject($fnt1) _WinAPI_DestroyWindow($hwnd) __WinAPI_UnregisterClass($WinClass) EndFunc ;==>FinalizeApp Func _CreateFont($fontName, $height = 16, $style = $FW_NORMAL, $italic = False, $underline = False, $strikeout = False) Local $hFont = _WinAPI_CreateFont($height, 0, 0, 0, $style, $italic, $underline, $strikeout, $DEFAULT_CHARSET, _ $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, $fontName) Return $hFont EndFunc ;==>_CreateFont ;=================================================================; ; WINDOW EVENTS ;=================================================================; Func BtnOpenFileClick() Local $ret = _WinAPI_GetOpenFileName("", "Text files (*.txt)|All files (*.*)", ".", "", "", 1, 0, 0, $hwnd) If ($ret[0] > 0) Then Local $path = $ret[1] & "\" & $ret[2] Local $file = _WinAPI_CreateFile($path, 2, 2) Local $buf = DllStructCreate("byte[" & _WinAPI_GetFileSizeEx($file) & "]") Local $i = 0 _WinAPI_ReadFile($file, DllStructGetPtr($buf), _WinAPI_GetFileSizeEx($file), $i) ; Close file handle _WinAPI_CloseHandle($file) _WinAPI_SetWindowText($edit1, BinaryToString(DllStructGetData($buf, 1))) EndIf EndFunc ;==>BtnOpenFileClick Func BtnExitClick() FinalizeApp() Exit EndFunc ;==>BtnExitClick  
      _RegisterClassEx.au3
×
×
  • Create New...