ฟอรั่ม PSsix

Would you like to react to this message? Create an account in a few clicks or log in to continue.

ฟอรั่มของบล็อก http://pssix.blogspot.com


3 posters

    การเลือกไฟล์

    Arm
    Arm
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Master PSsix Program Coder
    จำนวนข้อความ : 268
    ความนิยม : 54
    เข้าร่วมเมื่อ : 31/03/2011
    อายุ : 26

    การเลือกไฟล์ Empty การเลือกไฟล์

    ตั้งหัวข้อ by Arm 13/05/11, 05:03 pm

    ใครก็ได้ช่วยหน่อยครับ..
    ผมอยากให้เวลาเราเลือกไฟล์ (FileOpenDialog) ผมอยากให้มันได้ค่าออกมาแค่เป็นชื่อไฟล์เท่านั้นน่ะครับแบบว่าสมมุติเราเลือก C:\Download\Pic.bmp ให้มันได้ค่าแค่ Pic.bmp น่ะครับ
    2.อยากให้ทำ GUI หาค่าสีที่ได้เป็นค่า (0x00[ค่าสี 6 ตัว]) ประมาณนี้หน่อยน่ะครับ

    ขอบคุณล่วงหน้าไปเลยคร้าบบบ em218 em229
    newsak2005
    newsak2005
    ระงับสมาชิก
    ระงับสมาชิก


    การเลือกไฟล์ Empty
    จำนวนข้อความ : 115
    ความนิยม : 0
    เข้าร่วมเมื่อ : 08/05/2011

    การเลือกไฟล์ Empty Re: การเลือกไฟล์

    ตั้งหัวข้อ by newsak2005 14/05/11, 12:57 am

    Arm พิมพ์ว่า:ใครก็ได้ช่วยหน่อยครับ..
    ผมอยากให้เวลาเราเลือกไฟล์ (FileOpenDialog) ผมอยากให้มันได้ค่าออกมาแค่เป็นชื่อไฟล์เท่านั้นน่ะครับแบบว่าสมมุติเราเลือก C:\Download\Pic.bmp ให้มันได้ค่าแค่ Pic.bmp น่ะครับ
    2.อยากให้ทำ GUI หาค่าสีที่ได้เป็นค่า (0x00[ค่าสี 6 ตัว]) ประมาณนี้หน่อยน่ะครับ

    ขอบคุณล่วงหน้าไปเลยคร้าบบบ em218 em229

    Array SplitPath
    Code:

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=
    $hWnd = GUICreate("Array SplitPath Sample", 442, 132, -1, -1)
    $Label1 = GUICtrlCreateLabel("Fullpath:", 160, 10, 44, 17)
    $Input1 = GUICtrlCreateInput("", 16, 32, 329, 21)
    $Label2 = GUICtrlCreateLabel("SplitPath", 160, 74, 46, 17)
    $Input2 = GUICtrlCreateInput("", 112, 96, 145, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
    $Button1 = GUICtrlCreateButton("Browse", 352, 32, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    While 1
       $nMsg = GUIGetMsg()
       Switch $nMsg
          Case $GUI_EVENT_CLOSE
             Exit
            Case $Button1
             Local $executable = FileOpenDialog("Choose", @DesktopDir & "|", "AllFiles (*.*)", 1 + 4, Default, $hWnd)
                If Not $executable Then ContinueLoop
             GUICtrlSetData($Input1, $executable)
             Local $pathsplit = StringSplit($executable, "\")
              Local $i
             For $i = 0 To UBound($pathsplit) -1
                    If StringInStr($pathsplit[$i], ".") Then ExitLoop
             Next
             MsgBox(0, "", $pathsplit[$i], 0, $hWnd)
             GUICtrlSetData($Input2, $pathsplit[$i])
       EndSwitch
    WEnd
    OR
    Code:

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=
    $hWnd = GUICreate("Array SplitPath Sample", 442, 132, -1, -1)
    $Label1 = GUICtrlCreateLabel("Fullpath:", 160, 10, 44, 17)
    $Input1 = GUICtrlCreateInput("", 16, 32, 329, 21)
    $Label2 = GUICtrlCreateLabel("SplitPath", 160, 74, 46, 17)
    $Input2 = GUICtrlCreateInput("", 112, 96, 145, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
    $Button1 = GUICtrlCreateButton("Browse", 352, 32, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    While 1
       $nMsg = GUIGetMsg()
       Switch $nMsg
          Case $GUI_EVENT_CLOSE
             Exit
            Case $Button1
             Local $executable = FileOpenDialog("Choose", @DesktopDir & "|", "AllFiles (*.*)", 1 + 4, Default, $hWnd)
                If Not $executable Then ContinueLoop
             GUICtrlSetData($Input1, $executable)
             Local $pathsplit = StringSplit($executable, "\")
             Local $array[5]
             $array = $pathsplit[0]
             $array = $pathsplit[1]
             $array = $pathsplit[2]
             $array = $pathsplit[3]
             $array = $pathsplit[4]
             If StringInStr($array, ".") Then
             MsgBox(0, "", $array, 0, $hWnd)
             GUICtrlSetData($Input2, $array)
             EndIf
       EndSwitch
    WEnd
    OR
    Code:

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=
    $hWnd = GUICreate("Array SplitPath Sample", 442, 132, -1, -1)
    $Label1 = GUICtrlCreateLabel("Fullpath:", 160, 10, 44, 17)
    $Input1 = GUICtrlCreateInput("", 16, 32, 329, 21)
    $Label2 = GUICtrlCreateLabel("SplitPath", 160, 74, 46, 17)
    $Input2 = GUICtrlCreateInput("", 112, 96, 145, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
    $Button1 = GUICtrlCreateButton("Browse", 352, 32, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    While 1
       $nMsg = GUIGetMsg()
       Switch $nMsg
          Case $GUI_EVENT_CLOSE
             Exit
            Case $Button1
             Local $executable = FileOpenDialog("Choose", @DesktopDir & "|", "AllFiles (*.*)", 1 + 4, Default, $hWnd)
                If Not $executable Then ContinueLoop
             GUICtrlSetData($Input1, $executable)
             Local $pathsplit = StringSplit($executable, "\")
                Global $filesplit
             Select
                Case StringInStr($pathsplit[1], ".")
                     $filesplit = $pathsplit[1]
                Case StringInStr($pathsplit[2], ".")
                     $filesplit = $pathsplit[2]
                Case StringInStr($pathsplit[3], ".")
                     $filesplit = $pathsplit[3]
                Case StringInStr($pathsplit[4], ".")
                     $filesplit = $pathsplit[4]
                Case StringInStr($pathsplit[5], ".")
                     $filesplit = $pathsplit[5]
             EndSelect
                 MsgBox(0, "", $filesplit, 0, $hWnd)
                 GUICtrlSetData($Input2, $filesplit)
       EndSwitch
    WEnd
    OR
    Code:

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #Include <Array.au3>
    #Region ### START Koda GUI section ### Form=
    $hWnd = GUICreate("Array SplitPath Sample", 442, 132, -1, -1)
    $Label1 = GUICtrlCreateLabel("Fullpath:", 160, 10, 44, 17)
    $Input1 = GUICtrlCreateInput("", 16, 32, 329, 21)
    $Label2 = GUICtrlCreateLabel("SplitPath", 160, 74, 46, 17)
    $Input2 = GUICtrlCreateInput("", 112, 96, 145, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
    $Button1 = GUICtrlCreateButton("Browse", 352, 32, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    While 1
       $nMsg = GUIGetMsg()
       Switch $nMsg
          Case $GUI_EVENT_CLOSE
             Exit
            Case $Button1
             Local $executable = FileOpenDialog("Choose", @DesktopDir & "|", "AllFiles (*.*)", 1 + 4, Default, $hWnd)
                If Not $executable Then ContinueLoop
             GUICtrlSetData($Input1, $executable)
             Local $pathsplit = StringSplit($executable, "\")
                Local $avArray[5][5] = [[$pathsplit[1], $pathsplit[2], $pathsplit[3], $pathsplit[4], $pathsplit[5]]]
                Local $i
             For $i = 0 To UBound($avArray) -1
                 If StringInStr($avArray[0][$i], '.') Then ExitLoop
             Next
             MsgBox(0, "", $avArray[0][$i])
              GUICtrlSetData($Input2, $avArray[0][$i])
       EndSwitch
    WEnd
    OR
    Code:

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #Include <Array.au3>
    #Region ### START Koda GUI section ### Form=
    $hWnd = GUICreate("Array SplitPath Sample", 442, 132, -1, -1)
    $Label1 = GUICtrlCreateLabel("Fullpath:", 160, 10, 44, 17)
    $Input1 = GUICtrlCreateInput("", 16, 32, 329, 21)
    $Label2 = GUICtrlCreateLabel("SplitPath", 160, 74, 46, 17)
    $Input2 = GUICtrlCreateInput("", 112, 96, 145, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
    $Button1 = GUICtrlCreateButton("Browse", 352, 32, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    While 1
       $nMsg = GUIGetMsg()
       Switch $nMsg
          Case $GUI_EVENT_CLOSE
             Exit
            Case $Button1
             Local $executable = FileOpenDialog("Choose", @DesktopDir & "|", "AllFiles (*.*)", 1 + 4, Default, $hWnd)
                If Not $executable Then ContinueLoop
             GUICtrlSetData($Input1, $executable)
             Local $pathsplit = StringSplit($executable, "\")
                Local $avArray[5][5]
             $avArray[0][0] = $pathsplit[1]
             $avArray[0][1] = $pathsplit[2]
             $avArray[0][2] = $pathsplit[3]
             $avArray[0][3] = $pathsplit[4]
             $avArray[0][4] = $pathsplit[5]
             Local $i
             For $i = 0 To UBound($avArray) -1
                 If StringInStr($avArray[0][$i], '.') Then ExitLoop
               Next
                MsgBox(0, "", $avArray[0][$i])
                GUICtrlSetData($Input2, $avArray[0][$i])
       EndSwitch
    WEnd
    Arm
    Arm
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Master PSsix Program Coder
    จำนวนข้อความ : 268
    ความนิยม : 54
    เข้าร่วมเมื่อ : 31/03/2011
    อายุ : 26

    การเลือกไฟล์ Empty Re: การเลือกไฟล์

    ตั้งหัวข้อ by Arm 14/05/11, 07:21 am

    โห!!! เยอะมากเลยครับ ขอบคุณครับ em238 em233
    ปล.เหลือแต่เรื่องทำ GUI หาค่าสี ใครก็ได้ช่วยทีคร้าบบบบบ em232
    newsak2005
    newsak2005
    ระงับสมาชิก
    ระงับสมาชิก


    การเลือกไฟล์ Empty
    จำนวนข้อความ : 115
    ความนิยม : 0
    เข้าร่วมเมื่อ : 08/05/2011

    การเลือกไฟล์ Empty Re: การเลือกไฟล์

    ตั้งหัวข้อ by newsak2005 14/05/11, 09:42 am

    Arm พิมพ์ว่า:โห!!! เยอะมากเลยครับ ขอบคุณครับ em238 em233
    ปล.เหลือแต่เรื่องทำ GUI หาค่าสี ใครก็ได้ช่วยทีคร้าบบบบบ em232

    Color Hex Code
    Code:

    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <ButtonConstants.au3>
    #Include <Misc.au3>

    #Region ### START Koda GUI section ### Form=
    Local $hForm = GUICreate("Color Decode", 240, 80, -1, -1)
    Local $Input1 = GUICtrlCreateInput("", 16, 32, 129, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
    GUICtrlCreateLabel("Hex Code", 60, 15, 59, 17)
    Local $Button1 = GUICtrlCreateButton("Choose", 150, 30, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    While 1
       $nMsg = GUIGetMsg()
       Switch $nMsg
          Case $GUI_EVENT_CLOSE
             Exit
            Case $Button1
             GUICtrlSetData($Input1, _ChooseColor(2, 0x808000, 1, $hForm))
             GUISetBkColor(GUICtrlRead($Input1), $hForm)
       EndSwitch
    WEnd
    OR
    Help Example
    Code:

    #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <Misc.au3>

    Opt('MustDeclareVars', 1)

    _Color_Example()

    Func _Color_Example()
       Local $GUI, $Btn_COLORREF, $Btn_BGR, $Btn_RGB, $iMemo

       $GUI = GUICreate("_ChooseColor() Example", 400, 300)
       $iMemo = GUICtrlCreateEdit("", 2, 55, 396, 200, BitOR($WS_VSCROLL, $WS_HSCROLL))
       GUICtrlSetFont($iMemo, 10, 400, 0, "Courier New")
       $Btn_COLORREF = GUICtrlCreateButton("COLORREF", 70, 10, 80, 40)
       $Btn_BGR = GUICtrlCreateButton("BGR", 160, 10, 80, 40)
       $Btn_RGB = GUICtrlCreateButton("RGB", 250, 10, 80, 40)
       GUISetState()

       While 1
          Switch GUIGetMsg()
             Case $GUI_EVENT_CLOSE
                ExitLoop
             Case $Btn_COLORREF
                _ShowChoice($GUI, $iMemo, 0, _ChooseColor(0, 255, 0, $GUI), "COLORREF color of your choice: ")
             Case $Btn_BGR
                _ShowChoice($GUI, $iMemo, 1, _ChooseColor(2, 0x808000, 1, $GUI), "BGR Hex color of your choice: ")
             Case $Btn_RGB
                _ShowChoice($GUI, $iMemo, 2, _ChooseColor(2, 0x0080C0, 2, $GUI), "RGB Hex color of your choice: ")
          EndSwitch
       WEnd
    EndFunc  ;==>_Color_Example

    Func _ShowChoice($GUI, $iMemo, $Type, $Choose, $sMessage)
       Local $cr
       If $Choose <> -1 Then
          
          If $Type = 0 Then ; convert COLORREF to RGB for this example
             $cr = Hex($Choose, 6)
             GUISetBkColor('0x' & StringMid($cr, 5, 2) & StringMid($cr, 3, 2) & StringMid($cr, 1, 2), $GUI)
          Else
             GUISetBkColor($Choose, $GUI)
          EndIf
          
          GUICtrlSetData($iMemo, $sMessage & $Choose & @CRLF, 1)

       Else
          GUICtrlSetData($iMemo, "User Canceled Selction" & @CRLF, 1)
       EndIf
    EndFunc  ;==>_ShowChoice
    Arm
    Arm
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Master PSsix Program Coder
    จำนวนข้อความ : 268
    ความนิยม : 54
    เข้าร่วมเมื่อ : 31/03/2011
    อายุ : 26

    การเลือกไฟล์ Empty Re: การเลือกไฟล์

    ตั้งหัวข้อ by Arm 14/05/11, 10:25 am

    ขอบคุณมากคร้าบบบ em218
    POS
    POS
    PSsix
    PSsix


    การเลือกไฟล์ Empty การเลือกไฟล์ Empty การเลือกไฟล์ Empty
    จำนวนข้อความ : 1152
    ความนิยม : 326
    เข้าร่วมเมื่อ : 19/07/2010

    การเลือกไฟล์ Empty Re: การเลือกไฟล์

    ตั้งหัวข้อ by POS 14/05/11, 12:57 pm

    ใน AutoIt มีคำสั่ง _PathSplit สำหรับช่วยแยกตำแหน่งและชื่อไฟล์อยู่ครับ

    Code:
    #include <File.au3>
    Dim $szDrive, $szDir, $szFName, $szExt

    $fpath = FileOpenDialog("Select an Image", @HomeDrive, "เลือกไฟล์ (*.*)")
    _PathSplit($fpath, $szDrive, $szDir, $szFName, $szExt)

    MsgBox(0, $fpath, "ชื่อ : " & $szFName & $szExt)

    หรือจะเขียนอีกแบบ ลองใช้คำสั่งด้านล่างนี้

    Code:
    $filename = FileOpenDialog("Select an Image", @HomeDrive, "เลือกไฟล์ (*.*)")
    $filename = StringTrimLeft($filename, StringInStr($filename, "\", 0, -1))
    If $filename = True Then MsgBox(0, "ชื่อ ", $filename)
    newsak2005
    newsak2005
    ระงับสมาชิก
    ระงับสมาชิก


    การเลือกไฟล์ Empty
    จำนวนข้อความ : 115
    ความนิยม : 0
    เข้าร่วมเมื่อ : 08/05/2011

    การเลือกไฟล์ Empty Re: การเลือกไฟล์

    ตั้งหัวข้อ by newsak2005 14/05/11, 01:34 pm

    New modify. MousePosPixelColor
    Code:

    #NoTrayIcon
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <ButtonConstants.au3>
    #Include <Misc.au3>

    #Region ### START Koda GUI section ### Form=
    Local $hForm = GUICreate("Color Decode", 240, 80, -1, -1)
    Local $Input1 = GUICtrlCreateInput("", 16, 32, 129, 21, BitOR($ES_CENTER,$ES_AUTOHSCROLL))
    GUICtrlCreateLabel("Hex Code", 60, 15, 59, 17)
    Local $Button1 = GUICtrlCreateButton("Choose", 150, 30, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    While 1
       Local $nMsg = GUIGetMsg()
       Switch $nMsg
          Case $GUI_EVENT_CLOSE
             Exit
            Case $Button1
             GUICtrlSetData($Input1, _ChooseColor(2, 0x808000, 1, $hForm))
             GUISetBkColor(GUICtrlRead($Input1), $hForm)
           Case 0
      Local $pos = MouseGetPos()
      Local $var = PixelGetColor($pos[0], $pos[1], $hForm)
      ToolTip("Mouse Position" _
      &@CRLF&"X="&$pos[0]&@CRLF&"Y="&$pos[1]&@CRLF& _
      "---------------------" _
      &@CRLF&"Color Position"&@CRLF&"Hex="&"0x"&Hex($var, 6))
    EndSwitch
    WEnd
    Utilities
    Code:

    #NoTrayIcon
    #include <Constants.au3>
    Opt("TrayOnEventMode",1)
    Opt("TrayMenuMode",1)
    TrayCreateItem("Exit")
    TrayItemSetOnEvent(-1,"Close")
    TraySetIcon(@SystemDir&"\conime.exe")

    While 1
      Local $pos = MouseGetPos()
      Local $var = PixelGetColor($pos[0], $pos[1])
      ToolTip("Mouse Position" _
      &@CRLF&"X="&$pos[0]&@CRLF&"Y="&$pos[1]&@CRLF& _
      "---------------------" _
      &@CRLF&"Color Position"&@CRLF&"Hex="&"0x"&Hex($var, 6))
      Sleep(100)
    WEnd
    Exit

    Func Close()
        Exit
    EndFunc
    newsak2005
    newsak2005
    ระงับสมาชิก
    ระงับสมาชิก


    การเลือกไฟล์ Empty
    จำนวนข้อความ : 115
    ความนิยม : 0
    เข้าร่วมเมื่อ : 08/05/2011

    การเลือกไฟล์ Empty Re: การเลือกไฟล์

    ตั้งหัวข้อ by newsak2005 16/05/11, 04:42 am

    Array _PathSplit() and move file browse dialog to screen center.
    Code:

    #include <File.au3>
    Dim $szDrive, $szDir, $szFName, $szExt
    $message = "Choose"
    $hWnd = @DesktopHeight/2
    Local $Filepath = FileOpenDialog($message, @DesktopDir & "\", "All File (*.*)", 1 + 4, "", $hWnd)
    If $Filepath Then
        Local $Path = _PathSplit($Filepath, $szDrive, $szDir, $szFName, $szExt)
        MsgBox(4096, "FNameExt", $Path[3] & $Path[4], 0, $hWnd)
    EndIf

      เวลาขณะนี้ 02/05/24, 12:21 pm