Jump to content

I thought i am clever


au3scr
 Share

Recommended Posts

Hi all

I want it To operate with window title as notepad 2 does it http://www.flos-freeware.ch/notepad2.html

Something goes wrong here, I want my script change window title when I open file and when I modify text in $edit1. When I Open File window then window title will be changed to drive:\full\File\path.ext but my problem is that my scripts add * at the beginning of name so it looks like this:*drive:\full\File\path.ext, But I need that window title stay with out * until I change text in $Edit1 (You can test it if you type text in $edit1 when you run script).

How to modify my script thatway it add * at the beginning of windowtitle only when I modify my Edit control. (Do not display * at the beginning of windowtitle, when file opened, and wait with adding * untill I change data in$edit1)

Hope u understood what I wanted to tell u,Here Is My code,run and see how it works.

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <Timers.au3>

#Region ### START Koda GUI section ### Form=
Global $current_file = ""
Global $current_title = "Untitled"
Global $modified = 0
$start=_Timer_Init()
$test = ""
$Form1_1 = GUICreate($current_title, 612, 402, 194, 126)
$Edit1 = GUICtrlCreateEdit("", 0, 0, 611, 383,BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_HSCROLL,$WS_VSCROLL,$WS_CLIPSIBLINGS))
$filemenu = GUICtrlCreateMenu("&File")
$MenuItem13 = GUICtrlCreateMenuItem("&Open", $filemenu)
GUISetState (@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case _timer_diff($start) = 2
        If $test <> guictrlread($edit1) then
              do_Func ()
              $modified = 1           
              $test = guictrlread($Edit1)
              $start=_Timer_Init()
        Else
              $test = guictrlread($Edit1)
              $start=_Timer_Init()
        Endif
        Case $GUI_EVENT_CLOSE
            Exit
        Case $MenuItem13
;here Starts file open finction 
;Here I set $modified 1 so do_Func should not take action
            $modified = 1
$OpenLocal = FileOpenDialog("Open file",@MyDocumentsDir,"Text file  (*.*)")
If Not @error Then
$current_file = $OpenLocal
$readfile = FileRead($OpenLocal)
GUICtrlSetData($Edit1 , $readfile)
;Here I set window tole to file path
WinSetTitle($current_title,"",$current_file)
$current_title = $current_file
;Here I set $modified 0 to allow do_Func again
;And here I have problem... * added at the beginning of window title without I change text
$modified = 0
Else
MsgBox(64,"Sorry Guys","We got big error here :(")
EndIf
;here Ends file open finction   
            
    EndSwitch
WEnd

;This function should be skipped after file is opene, and it must done again when $edit1 has changed.
Func do_Func ()
If $modified = 0 Then
WinSetTitle($current_title,"","*"&$current_title)
$current_title = "*"&$current_title
EndIf
EndFunc
Edited by au3scr
Link to comment
Share on other sites

Opt("WinTitleMatchMode",2)
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <Timers.au3>

#Region ### START Koda GUI section ### Form=
Global $current_file = ""
Global $current_title = "Untitled"
Global $modified = 0
$start=_Timer_Init()
$test = ""
$Form1_1 = GUICreate($current_title, 612, 402, 194, 126)
$Edit1 = GUICtrlCreateEdit("", 0, 0, 611, 383,BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_HSCROLL,$WS_VSCROLL,$WS_CLIPSIBLINGS))
$filemenu = GUICtrlCreateMenu("&File")
$MenuItem13 = GUICtrlCreateMenuItem("&Open", $filemenu)
GUISetState (@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case _timer_diff($start) = 2
        If $test <> guictrlread($edit1) then
              do_Func ()
              $modified = 1 
              $test = guictrlread($Edit1)
              $start=_Timer_Init()
        Else
              $test = guictrlread($Edit1)
              $start=_Timer_Init()
        Endif
        Case $GUI_EVENT_CLOSE
            Exit
        Case $MenuItem13
;here Starts file open finction 
;Here I set $modified 1 so do_Func should not take action
            $modified = 1
$OpenLocal = FileOpenDialog("Open file",@MyDocumentsDir,"Text file  (*.*)",1)
If Not @error Then
$current_file = $OpenLocal
$readfile = FileRead($OpenLocal)
GUICtrlSetData($Edit1 , $readfile)
;Here I set window tole to file path
WinSetTitle($current_title,"",$OpenLocal)
$current_title = $current_file
;Here I set $modified 0 to allow do_Func again
;And here I have problem... * added at the beginning of window title without I change text
$modified = 0
Else
MsgBox(64,"Sorry Guys","We got big error here sad.gif")
EndIf
;here Ends file open finction   
           
    EndSwitch
WEnd

;This function should be skipped after file is opene, and it must done again when $edit1 has changed.
Func do_Func ()
If $modified = 0 Then
WinSetTitle($current_title,"",$current_title)
$current_title = "*"&$current_title
EndIf
EndFunc

When the words fail... music speaks.

Link to comment
Share on other sites

Oh Andreik's Modification totally disabled adding * at the beginning of file name but I want add * when I modify $Edit 1.(Only when I modify data in $edit1)

So adding * to window title must be disabled only when opening new file.

I want it To operate with window title as notepad 2 does it http://www.flos-freeware.ch/notepad2.html

Edited by au3scr
Link to comment
Share on other sites

I thought That I am clever and I can help my self adding another if sentence ,but it didnt work.

As this modification shows you that 2-nd if sentence dont change value for $modified

Func do_Func ()
    MsgBox(64,"stuff",$modified)
If $modified = 0 Then
WinSetTitle($current_title,"","*"&$current_title)
$current_title = "*"&$current_title
EndIf
If $modified = 1 Then
    $modified = 0
MsgBox(64,"stuff",$modified)
EndIf
EndFunc
Link to comment
Share on other sites

Like this?

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <Timers.au3>

#Region ### START Koda GUI section ### Form=
Global $current_file = ""
Global $current_title = "Untitled"
Global $modified = 0
$start=_Timer_Init()
$test = ""
$Form1_1 = GUICreate($current_title, 612, 402, 194, 126)
$Edit1 = GUICtrlCreateEdit("", 0, 0, 611, 383,BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_HSCROLL,$WS_VSCROLL,$WS_CLIPSIBLINGS))
$filemenu = GUICtrlCreateMenu("&File")
$MenuItem13 = GUICtrlCreateMenuItem("&Open", $filemenu)
GUISetState (@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case _timer_diff($start) = 2
        If $test <> guictrlread($edit1) then
              do_Func ()
              $modified = 1 
              $test = guictrlread($Edit1)
              $start=_Timer_Init()
        Else
              $test = guictrlread($Edit1)
              $start=_Timer_Init()
        Endif
        Case $GUI_EVENT_CLOSE
            Exit
        Case $MenuItem13
;here Starts file open finction 
;Here I set $modified 1 so do_Func should not take action
            $modified = 1
$OpenLocal = FileOpenDialog("Open file",@MyDocumentsDir,"Text file  (*.*)")
If Not @error Then
$current_file = $OpenLocal
$readfile = FileRead($OpenLocal)
GUICtrlSetData($Edit1 , $readfile)
;Here I set window tole to file path
WinSetTitle($Form1_1,"",$current_file)
;$current_title = $current_file

;Here I set $modified 0 to allow do_Func again
;And here I have problem... * added at the beginning of window title without I change text
$modified = 0
Else
MsgBox(64,"Sorry Guys","We got big error here sad.gif")
EndIf
;here Ends file open finction   
           
    EndSwitch
WEnd

;This function should be skipped after file is opene, and it must done again when $edit1 has changed.
Func do_Func ()
    If $modified = 0 AND WinGetTitle($Form1_1) <> $current_title then 
        WinSetTitle($Form1_1,"",$current_title)
    Else
        If WinGetTitle($Form1_1) <> "*"&$current_title then 
            WinSetTitle($Form1_1,"","*"&$current_title)
        EndIf
    EndIf
EndFunc
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...