I want to move the pop-up window to the right bottom of the corner

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
hello123789
Posts: 10
Joined: 21 May 2023, 07:43

I want to move the pop-up window to the right bottom of the corner

Post by hello123789 » 21 May 2023, 09:27

I've created a little pop-up program in AHK with the help of chatGPT (I have no knowledge of coding), and it works like a charm (after a lot of testing and reading myself)! Now what remains are a little improvements I want to make where ChatGPT is useless.

What I want to add:
As soon as I start the script the window/pop-up appears right at the center of the screen, and I have to move it manually every time.

Instead, I want the window to be positioned at the right bottom of the corner. And I want this to be applied to all and any screens and resolutions this program is opened on.

It seems I have created this code with AutoHotKey 1.1.36 (I installed v2, but a popup appeared said I needed 1.1).

____________________________

Examples of failed codes I tried that ChatGPT generated:

[Mod edit: Removed code. No need to post non-working ChatGPT code. Please respect the forum rules, especially about 'Inappropriate content' (4.)]

gregster
Posts: 9096
Joined: 30 Sep 2013, 06:48

Re: I want to move the pop-up window to the right bottom of the corner

Post by gregster » 21 May 2023, 09:58

Please don't post non-working ChatGPT code, it's against the forum rules: please see link above.

If you have taken some AI-generated code as a starting point and worked with it or made it work, that's acceptable. In that case, you could post your current code, so that your potential helpers can build on that working code.

Generally, you can use AHK v1 and v2 side-by-side - but those versions are not very compatible. ChatGPT's learning corpus is a few years old, so it usually puts out v1 code (or something that looks more or less like it), or outdated v2 code (from the time when v2 was still in earlier development phases).

hello123789
Posts: 10
Joined: 21 May 2023, 07:43

Re: I want to move the pop-up window to the right bottom of the corner

Post by hello123789 » 21 May 2023, 11:12

Sorry about that. Thanks for both of your clarifications.

I was contemplating about whether to post the entire code (it's work related), but I figured since I really want to add a code snippet irrelevant of the actual code then someone could offer assistance regardless.


Anyway, here is the code.

Code: Select all

#NoEnv
#SingleInstance force
#Persistent
 
; Version 3.1
 
; Grab active window
WinGetActiveTitle, activeWinTitle
 
; Create popup-window
Gui, +AlwaysOnTop
Gui, Add, Text, x18 y7 w200 h20, ID:
Gui, Add, Edit, vID x18 y30 w190 h20
Gui, Add, Button, x20 y630 w90 h30 gCopy, Copy
 
Gui, Show, w590 h690,
  
; size of main window
MainWinWidth := 320
MainWinHeight := 580
 
; Create popup for Draft window besides main window.
Gui, +AlwaysOnTop
Gui, Add, Edit, x%MainWinWidth%+10 y32 x260 w%MainWinWidth% h%MainWinHeight%,
  
return
 
; Function that runs when the button "Copy" is pressed
Copy:
Gui, Submit, NoHide
Clipboard =
(
ID:
%ID%
)
 
; show confirmation popup
MsgBox, 64, Copied, Copy successful! 
 
return
  
; Function to be executed when the GUI window is closed
GuiClose:
ExitApp
return

User avatar
RDC
Posts: 112
Joined: 29 Jan 2023, 10:22

Re: I want to move the pop-up window to the right bottom of the corner

Post by RDC » 21 May 2023, 12:00

This should do the trick...

Code: Select all

#NoEnv
#SingleInstance force
#Persistent
 
; Version 3.1
 
; Grab active window
WinGetActiveTitle, activeWinTitle
 
; Create popup-window
Gui, +AlwaysOnTop
Gui, Add, Text, x18 y7 w200 h20, ID:
Gui, Add, Edit, vID x18 y30 w190 h20
Gui, Add, Button, x20 y630 w90 h30 gCopy, Copy
 
Gui, Show, w590 h690,

; ----------------------------------
WinGetPos X, Y, Width, Height, A
MaxX := A_ScreenWidth - Width - 10 ; This will put the Gui to the right of the monitor...adjust the "10" value as needed.
MaxY := A_ScreenHeight - Height - 45 ; This will put the Gui above the taskbar...adjust the "45" value as needed.
WinMove A, ,%MaxX%, %MaxY%
; ----------------------------------

; size of main window
MainWinWidth := 320
MainWinHeight := 580
 
; Create popup for Draft window besides main window.
Gui, +AlwaysOnTop
Gui, Add, Edit, x%MainWinWidth%+10 y32 x260 w%MainWinWidth% h%MainWinHeight%,
  
return
 
; Function that runs when the button "Copy" is pressed
Copy:
Gui, Submit, NoHide
Clipboard =
(
ID:
%ID%
)
 
; show confirmation popup
MsgBox, 64, Copied, Copy successful! 
 
return
  
; Function to be executed when the GUI window is closed
GuiClose:
ExitApp
return

hello123789
Posts: 10
Joined: 21 May 2023, 07:43

Re: I want to move the pop-up window to the right bottom of the corner

Post by hello123789 » 24 May 2023, 12:52

Thank you! This worked beautifully!

I do wonder though if one can avoid/get rid of the visual effect of the window being moved from center to the right bottom corner? It's like a very quick flash that shows up on screen. I just want it to open in that position like it naturally opens there.

One other thing, I don't have my three screens setup right now to try this on, but on which of the three screens' bottom right corner will this appear on? If it's just random, can this also be adjusted in the code to choose which screen order this appears on?

Again, really appreciate your efforts!

RDC wrote:
21 May 2023, 12:00
This should do the trick...

Code: Select all


; ----------------------------------
WinGetPos X, Y, Width, Height, A
MaxX := A_ScreenWidth - Width - 10 ; This will put the Gui to the right of the monitor...adjust the "10" value as needed.
MaxY := A_ScreenHeight - Height - 45 ; This will put the Gui above the taskbar...adjust the "45" value as needed.
WinMove A, ,%MaxX%, %MaxY%
; ----------------------------------

User avatar
RDC
Posts: 112
Joined: 29 Jan 2023, 10:22

Re: I want to move the pop-up window to the right bottom of the corner

Post by RDC » 24 May 2023, 14:43

I do wonder though if one can avoid/get rid of the visual effect of the window being moved from center to the right bottom corner? It's like a very quick flash that shows up on screen. I just want it to open in that position like it naturally opens there.
The Gui Hide option fixes that. Then just have the Gui Show after the positioning.

Code: Select all

Gui, Show, Hide
; ----------------------------------
WinGetPos X, Y, Width, Height, A
MaxX := A_ScreenWidth - Width - 10 ; This will put the Gui to the right of the monitor...adjust the "10" value as needed.
MaxY := A_ScreenHeight - Height - 45 ; This will put the Gui above the taskbar...adjust the "45" value as needed.
WinMove A, ,%MaxX%, %MaxY%
; ----------------------------------
Gui, Show, w590 h690,
One other thing, I don't have my three screens setup right now to try this on, but on which of the three screens' bottom right corner will this appear on? If it's just random, can this also be adjusted in the code to choose which screen order this appears on?
This only works on the primary monitor. But there is a post further down about gui positions that may help.

hello123789
Posts: 10
Joined: 21 May 2023, 07:43

Re: I want to move the pop-up window to the right bottom of the corner

Post by hello123789 » 24 May 2023, 16:12

Sadly, this new add of "Gui, Show, Hide" didn't work well. It annulled the move to the right bottom corner and opens instead in the center like originally.

Code: Select all

Gui, Show, Hide

WinGetPos X, Y, Width, Height, A
MaxX := A_ScreenWidth - Width - 10 ; This will put the Gui to the right of the monitor...adjust the "10" value as needed.
MaxY := A_ScreenHeight - Height - 45 ; This will put the Gui above the taskbar...adjust the "45" value as needed.
WinMove A, ,%MaxX%, %MaxY%

Gui, Show, w590 h690,

hello123789
Posts: 10
Joined: 21 May 2023, 07:43

Re: I want to move the pop-up window to the right bottom of the corner

Post by hello123789 » 26 May 2023, 14:02

Sadly this code didn't work. What happens when I run the script with this updated code is that the folder I open the file from moves its position to the right bottom corner, not the actual file I've coded (that one just opens in the center of the screen as before).

So Gui, Show, Hide undoes your first successful code snippet.

And yes, I did move Gui, Show to after the positioning.

RDC wrote:
24 May 2023, 14:43
The Gui Hide option fixes that. Then just have the Gui Show after the positioning.

Code: Select all

Gui, Show, Hide
; ----------------------------------
WinGetPos X, Y, Width, Height, A
MaxX := A_ScreenWidth - Width - 10 ; This will put the Gui to the right of the monitor...adjust the "10" value as needed.
MaxY := A_ScreenHeight - Height - 45 ; This will put the Gui above the taskbar...adjust the "45" value as needed.
WinMove A, ,%MaxX%, %MaxY%
; ----------------------------------
Gui, Show, w590 h690,
RDC wrote:
24 May 2023, 14:43
This only works on the primary monitor. But there is a post further down about gui positions that may help.
Where?


[Mod edit: Fixed quote tags so some of the reply text is no longer inside a quoted post.]

User avatar
RDC
Posts: 112
Joined: 29 Jan 2023, 10:22

Re: I want to move the pop-up window to the right bottom of the corner

Post by RDC » 26 May 2023, 16:56

Just use the search bar for "positions"...
There are many posts on this and most appear to apply to Guis.
search.php?keywords=positions&fid%5B0%5D=76

Post Reply

Return to “Ask for Help (v1)”