Jump to content

How can I add a function without it being part of GUICreate?


Recommended Posts

  • Moderators

TalesFromTheScript,

Your question has already been answered in the thread that was locked when you refused to believe the responses you received there. I will make one final attempt to get through to you.

$WS_EX_TOPMOST is a "style" not a "function" - so I suggest you start by reading the Setting Styles tutorial in the Wiki so that you actually understand what you are dealing with.

Next, in your attempts to use GUICreate in the other thread you were not correctly setting the parameters:

GUICreate("My GUI", 600, 400, -1, -1, Default, $nIniXPos, $nIniYPos)

Let us look at the Help file page for GUICreate:

GUICreate ( "title" [, width [, height [, left = -1 [, top = -1 [, style = -1 [, exStyle = -1 [, parent = 0]]]]]]] )

Starting from the left we get:

Parameter   Correct         Your version    Comment

The basics:

Title       string          string          Good
Width       value           value           Good
Height      value           value           Good
x pos       value           default (-1)    Good
y pos       value           default (-1)    Good

Now we come to the tricky bits:

style       various style   default         Good
            values
exstyle     various exstyle Xpos value?     Why?
            values
parent      handle of       Ypos value?     Why?
            parent GUI

So as you can (I hope) see you were placing coordinate values retrieved from your Ini file into the parameter spaces reserved for extended style and parent GUI handle values. Little wonder that it did not work!

What you need to do to add the $WS_EX_TOPMOST style to your GUI is to add the style to the default values - something like this:

GUICreate("My GUI", 600, 400, -1, -1, Default, BitOR($WS_EX_WINDOWEDGE, $WS_EX_TOPMOST))

Now you will have the $WS_EX_TOPMOST style applied to your GUI. The tutorial I linked to earlier explains why you need to use BitOR - you did read it?

Does that make the whole thing any clearer?

M23

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Cheers Melba23 that does answer it.

I am still stuck on how to add $nIniXPos and $nIniYPos (detailed in the other thread) without those having to be part of GUICreate.

I have exactly the same functionality I had before - I still don't know how to add a function globally to the GUI without it being part of GUICreate.

A drawback I did find with those ini functions to save window position was, if another instance of the GUI is opened, it saves the X and Y coordinates as 32000 on each and you can't get the GUI on screen unless you delete the ini file, so even if I can add $nIniXPos and $nIniYPos in separately somewhere, I'm going to have that to contend with. I thought about some way to make it read only but that's not going to be possible when opening another instance of the GUI is just going to toggle the read only attribute on/off or whatever, it's still just going to write to it (or else no instance could) so it can't be done, well at least I can't do it.

I'm just not cut out for this, it would be easier learning Chinese.

Since the always on top functionality can be made to work (your way or the way I was originally doing it) I think I'll just try to find some other software altogether that can save the window position, I am past caring at this point.

Cheers.

Edited by TalesFromTheScript
Link to comment
Share on other sites

  • Moderators

TalesFromTheScript,

Glad I could help.

Now to the new question: It looks as if those coordinates are stored in an ini file - is that so that the GUI opens in the same position each time? And you want to store the position if the GUI is moved during run-time?

If so, then you know how to read the values using IniRead - you then need to put those values into the correct parameters of the GUICreate call (left & top). If you want to check for any changes in position during run-time then a simple way is to use IniWrite to save the current position as the script exits. You would need to do something like this:

Local $aWPos = WinGetPos($hWnd)
If IsArray($aWPos) Then
    IniWrite($sMyIniLocation, 'MAINWINPOS', 'XPOS', $aWPos[0])
    IniWrite($sMyIniLocation, 'MAINWINPOS', 'YPOS', $aWPos[1])
EndIf

Now you will have stored the correct values in the ini file to be read the next time the app is run.

All clear?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

17 minutes ago, TalesFromTheScript said:

I'm just not cut out for this, it would be easier learning Chinese.

No, it definitely would not :D.

I suspect your brain is just trapped at the moment. Please provide a complete, meaning runnable, example script so that we have a foundation for further explanation.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

Thanks Melba23, but now I have the X and Y values being saved in the ini, without it actually reading it when the GUI runs, it's back in the center of the screen each time it runs, with the ini changing if I move then close the GUI.

It has to almost be 100% fixed now!

; AutoIt 3.1.1

#include <GuiConstants.au3>
#include <AutoItConstants.au3>
#include <WindowsConstants.au3>

Global $sMyIniLocation = "MyFolder\WindowPosition.ini"
Global $nIniXPos = Int(IniRead($sMyIniLocation, 'MAINWINPOS', 'XPOS', Int(@DesktopWidth/2.5)))
Global $nIniYPos = Int(IniRead($sMyIniLocation, 'MAINWINPOS', 'YPOS', Int(@DesktopHeight/2.5)))

Func _myWM_MOVE($hWnd, $nMsg, $wParam, $lParam)
Local $aWPos = WinGetPos($hWnd)
    If IsArray($aWPos) Then
    IniWrite($sMyIniLocation, 'MAINWINPOS', 'XPOS', $aWPos[0])
    IniWrite($sMyIniLocation, 'MAINWINPOS', 'YPOS', $aWPos[1])
    EndIf
    Return
 EndFunc

GUIRegisterMsg(0x03, "_myWM_MOVE")
GUISetState()

;; GUICreate line I was using, it works...
;; GUICreate("My GUI", 600, 400, -1, -1, Default, $WS_EX_TOPMOST)

;; GUICreate line suggested by Melba23, same functionality...
GUICreate("My GUI", 600, 400, -1, -1, Default, BitOR($WS_EX_WINDOWEDGE, $WS_EX_TOPMOST))

;; The rest of the script is buttons etc

 

Edited by TalesFromTheScript
Link to comment
Share on other sites

  • Moderators

TalesFromTheScript,

Did you read what I wrote above?

Quote

 you know how to read the values using IniRead - you then need to put those values into the correct parameters of the GUICreate call (left & top)

Now look at the code you just posted:

GUICreate("My GUI", 600, 400, -1, -1, Default, $WS_EX_TOPMOST)

I see hard-coded values of -1 in both the "left" and "top" parameters - which in AutoIt means Default and so "centre of screen" when it comes to creating GUIs. What you should have in those parameters is the saved x & y coordinates you read from your ini file.

M23

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Sorry Melba23 I can't even work that out, it doesn't help that I have been awake for 20 minutes lol

Yes it is all working now, I opened 3 instances of the GUI and it always saves properly, wherever the last one was closed :) 

GUICreate("MyGUI", 600, 400, $nIniXPos, $nIniYPos, Default, $WS_EX_TOPMOST)

Sorry I was being an asshat yesterday but I just don't have any patience. I'm working on it.

Melba23 let me know if there's a place I can donate $10 or something, either to you or the forum. It's not much but you have helped a great deal.

Link to comment
Share on other sites

  • Moderators

TalesFromTheScript,

Quote

Sorry I was being an asshat yesterday but I just don't have any patience. I'm working on it.

Apology accepted on behalf of those who responded to that thread. Patience is a great asset if you want to learn coding - keep on working at it!

There is a "Donate" on the Home page at top right - evrey little helps pay the server costs.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I noticed something weird, it doesn't always happen but sometimes the GUI isn't visible on screen, when I check the ini file for the window position, it says:

[MAINWINPOS]
XPOS=-32000
YPOS=-32000

The GUI exists and can be closed from the taskbar.

I thought it seemed to be happening if I ran a game that changed the desktop resolution, but I think I got it to do it without running that game.

The solution is to just delete the ini file but I wonder why it's sometimes doing this.

A typical value that's right looks like this:

[MAINWINPOS]
XPOS=1316
YPOS=467


 

Link to comment
Share on other sites

This is happening when you minimize a window.  A minimized window will be positioned at -32000 / -32000.  You need to check the state of the window before you write to the ini file.

Edited by Nine
Link to comment
Share on other sites

I have no idea how and will just end up messing it up.

I'll just have to make sure it's not minimized whenever I close it.

I was thinking, even if by some miracle I managed to have it checking the state, isn't it only going to do the same thing if it's closed while minimized? Saving the coordinates at -32000?

Edited by TalesFromTheScript
Link to comment
Share on other sites

This is part of your original code --

Func _myWM_MOVE($hWnd, $nMsg, $wParam, $lParam)
Local $aWPos = WinGetPos($hWnd)
    If IsArray($aWPos) Then
    IniWrite($sMyIniLocation, 'MAINWINPOS', 'XPOS', $aWPos[0])
    IniWrite($sMyIniLocation, 'MAINWINPOS', 'YPOS', $aWPos[1])
    EndIf
    Return
 EndFunc

You need to check the position before blindly writing the contents to the ini file. Alternatively, you could use WinGetState to check the window's state.

Link to comment
Share on other sites

You should also check if the hWnd is indeed the handle of your GUI.  If you show an _ArrayDisplay for example, it will be intercepted by your handler and you will get false coordinates.

Link to comment
Share on other sites

  • Moderators

TalesFromTheScript,

Quote

You need to check the position before blindly writing the contents to the ini file

That could be as simple as checking the value is not -32000 before saving - you would use an If...EndIf structure to do this.

Quote

you could use WinGetState to check the window's state

This means checking that the window is not minimized before saving - again an If...EndIf structure but looking at the result from WinGetState.

Quote

check if the hWnd is indeed the handle of your GUI

Windows messages are sent by all the various windows and controls in the system - you need to make sure that the message you receive is indeed from your own GUI. You do this by using an If...EndIf structure (sound familiar?) checking that the value of $hWnd in your message is the same as the value returned by your GUICreate function - that way you are sure it is your GUI being resized and not any other.

Back down to head level now?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I'll try to fix it at some point but I don't know what I'm doing.

The script uses batch files to download and process videos. It's all perfected now apart from this -32000 thing.

I got sick of using things like 4K Downloader and decided to make my own menu that does what I want :) 

There's other menus apart from this, for converting video, audio, making your video smaller etc.

Every menu has the same problem this one has, but if I can fix it for this one I know how to fix it for the rest.

This is the complete script as it is currently:

; AutoIt 3.1.1

#include <GuiConstants.au3>
#include <AutoItConstants.au3>
#include <WindowsConstants.au3>

Global $sMyIniLocation = "----\WinPos\WinPos_DownloadVideo.ini"
;; Raising DesktopWidth moves the GUI left
;; Raising DesktopHeight moves the GUI up
Global $nIniXPos = Int(IniRead($sMyIniLocation, 'MAINWINPOS', 'XPOS', Int(@DesktopWidth/2.95)))
Global $nIniYPos = Int(IniRead($sMyIniLocation, 'MAINWINPOS', 'YPOS', Int(@DesktopHeight/3.95)))

Func _myWM_MOVE($hWnd, $nMsg, $wParam, $lParam)
Local $aWPos = WinGetPos($hWnd)
    If IsArray($aWPos) Then
    IniWrite($sMyIniLocation, 'MAINWINPOS', 'XPOS', $aWPos[0])
    IniWrite($sMyIniLocation, 'MAINWINPOS', 'YPOS', $aWPos[1])
    EndIf
    Return
 EndFunc

GUIRegisterMsg(0x03, "_myWM_MOVE")
GUISetState()

; GUI
GUICreate("Download Video", 590, 515, $nIniXPos, $nIniYPos, Default, $WS_EX_TOPMOST)
GuiSetIcon("ffmpeg.ico", 0)
; GUISetBkColor(0x990000)

; PIC
; GuiCtrlCreatePic("pic.jpg", 0, 0, 300, 700)

; BUTTONS
$button1 = GUICtrlCreateButton ("Download Video/Channel", 30,20,530,35,$BS_ICON)
GUICtrlSetFont ($button1, 13, 700, 0, "Segoe UI")
GUICtrlSetBkColor(-1, 0xffad99)
GUICtrlSetImage (-1, "Icon2.ico",-1)

$button2 = GUICtrlCreateButton ("Download Videos Before Date (Channel)", 30,60,530,35,$BS_ICON)
GUICtrlSetFont ($button2, 13, 700, 0, "Segoe UI")
GUICtrlSetBkColor(-1, 0xffad99)
GUICtrlSetImage (-1, "Icon2.ico",-1)

$button3 = GUICtrlCreateButton ("Download Videos After Date (Channel)", 30,100,530,35,$BS_ICON)
GUICtrlSetFont ($button3, 13, 700, 0, "Segoe UI")
GUICtrlSetBkColor(-1, 0xffad99)
GUICtrlSetImage (-1, "Icon2.ico",-1)

$button4 = GUICtrlCreateButton ("Download Video and Normalize Audio", 30,140,530,35,$BS_ICON)
GUICtrlSetFont ($button4, 13, 700, 0, "Segoe UI")
GUICtrlSetBkColor(-1, 0xffad99)
GUICtrlSetImage (-1, "Icon2.ico",-1)

$button5 = GUICtrlCreateButton ("Download Video/Normalize/Mono/Save as MP4", 30,180,530,35,$BS_ICON)
GUICtrlSetFont ($button5, 13, 700, 0, "Segoe UI")
GUICtrlSetBkColor(-1, 0xffcc00)
GUICtrlSetImage (-1, "Icon2.ico",-1)

$button6 = GUICtrlCreateButton ("Download Video and Save as MP3 Stereo 128k", 30,220,530,35,$BS_ICON)
GUICtrlSetFont ($button6, 13, 700, 0, "Segoe UI")
GUICtrlSetBkColor(-1, 0xffad99)
GUICtrlSetImage (-1, "Icon2.ico",-1)

$button7 = GUICtrlCreateButton ("Download Video/Normalize/Trim/Save MP3 Mono 96k", 30,260,530,35,$BS_ICON)
GUICtrlSetFont ($button7, 13, 700, 0, "Segoe UI")
GUICtrlSetBkColor(-1, 0xffb3ff)
GUICtrlSetImage (-1, "Icon2.ico",-1)

$button8 = GUICtrlCreateButton ("Download Video and Save as WAV Audio", 30,300,530,35,$BS_ICON)
GUICtrlSetFont ($button8, 13, 700, 0, "Segoe UI")
GUICtrlSetBkColor(-1, 0xffad99)
GUICtrlSetImage (-1, "Icon2.ico",-1)

$button9 = GUICtrlCreateButton ("Download Subtitles From Video/Channel", 30,340,530,35,$BS_ICON)
GUICtrlSetFont ($button9, 13, 700, 0, "Segoe UI")
GUICtrlSetBkColor(-1, 0xffad99)
GUICtrlSetImage (-1, "Icon2.ico",-1)

$button10 = GUICtrlCreateButton ("Download Subtitles Before Date (Channel)", 30,380,530,35,$BS_ICON)
GUICtrlSetFont ($button10, 13, 700, 0, "Segoe UI")
GUICtrlSetBkColor(-1, 0xffad99)
GUICtrlSetImage (-1, "Icon2.ico",-1)

$button11 = GUICtrlCreateButton ("Download Subtitles After Date (Channel)", 30,420,530,35,$BS_ICON)
GUICtrlSetFont ($button11, 13, 700, 0, "Segoe UI")
GUICtrlSetBkColor(-1, 0xffad99)
GUICtrlSetImage (-1, "Icon2.ico",-1)

$button12 = GUICtrlCreateButton ("Open NEW Folder", 30,460,530,35,$BS_ICON)
GUICtrlSetFont ($button12, 13, 700, 0, "Segoe UI")
GUICtrlSetBkColor(-1, 0xcccccc)
GUICtrlSetImage (-1, "Icon2.ico",-1)

GUISetState()

While 1
$msg = GUIGetMsg()
Select

Case $msg = $GUI_EVENT_CLOSE
Exit

Case $msg = $button1
Run("----\# Download Video (from Clipboard Link).bat")

Case $msg = $button2
Run("----\# Download Videos Before Date.bat")

Case $msg = $button3
Run("----\# Download Videos After Date.bat")

Case $MSG = $button4
Run("----\# Download Video and Normalize.bat")

Case $MSG = $button5
Run("----\# Download Video, Normalize, Mono, Save as MP4.bat")

Case $MSG = $button6
Run("----\# Download Video and Save as MP3 (Stereo, 128k).bat")

Case $MSG = $button7
Run("----\# Download Video, Normalize, Trim, Save as MP3 (Mono, 96k).bat")

Case $MSG = $button8
Run("----\# Download WAV Audio from Video (from Clipboard Link).bat")

Case $MSG = $button9
Run("----\# Download Subtitles (from Clipboard Link).bat")

Case $MSG = $button10
Run("----\# Download Subtitles Before Date.bat")

Case $MSG = $button11
Run("----\# Download Subtitles After Date.bat")

Case $MSG = $button12
Run("----\# Open NEW Folder.bat")

Case Else
;;;
EndSelect
WEnd

 

Edited by TalesFromTheScript
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...