Jump to content

How to start my script from right click menue


Recommended Posts

Hi all,

When you rightclick on the titlebar, a menu is appearing with Restore,Move,Size,...

Is there a way the i can add myscript.exe to this menu.

below a link to a screenshot of the menu.

hope you can click on the link below to see a screenshot. (because i don't know how to add a picture)

Link to screenshot of menu

i want this because i have 2 screens and i want a quick way to move and maximize a window to the other screen.

Thanks for the help.

Kurt.

Link to comment
Share on other sites

I'm trying to look into how to do something like this, and I think I've found the correct functions to call (using DllCall), but I'm not sure about where the error(s) are (the code doesn't work correctly, AutoIt crashes when it runs).

This is the code I have atm:

Opt("WinTitleMatchMode", 4)

Global Const $MIIM_TYPE = 0x00000010
Global Const $MIIM_STRING = 0x00000040
Global Const $MIIM_FTYPE = 0x00000100

Global Const $MFT_STRING = 0x0000

Dim $ItemDataString = "Test"
Dim $WindowHandle = WinGetHandle("[CLASS:SciTEWindow]")

If @error Then
    MsgBox(0, "Error", "There was an error getting the window handle!")
    Exit
EndIf

$HMENU = DllCall("user32.dll", "hwnd", "GetSystemMenu", "hwnd", $WindowHandle, "int", False)
If @error Then
    MsgBox(0, "Error", "An error occured when getting the SystemMenu: " & @error)
    Exit
EndIf

$MENUITEMINFO = DllStructCreate("uint;uint;uint;uint;uint;hwnd;hwnd;hwnd;ulong_ptr;char;uint;hwnd")
If @error Then
    MsgBox(0, "Error", "There was an error while creating the structure: " & @error)
    Exit
EndIf

DllStructSetData($MENUITEMINFO, 2, $MIIM_STRING+$MIIM_FTYPE)
DllStructSetData($MENUITEMINFO, 3, $MFT_STRING)
DllStructSetData($MENUITEMINFO, 10, $ItemDataString)
DllStructSetData($MENUITEMINFO, 11, StringLen($ItemDataString))
DllStructSetData($MENUITEMINFO, 1, DllStructGetSize($MENUITEMINFO)) ; not sure if this needs to be set after all the data is set, or if it can be set before..

DllCall("user32.dll", "int", "InsertMenuItem", "hwnd", $HMENU[0], "uint", 1, "byte", 1, "ptr", DllStructGetPtr($MENUITEMINFO))
If @error Then
    MsgBox(0, "Error", "There was an error in the InsertMenuItem function: " & @error)
EndIf

$MENUITEMINFO = 0

Maybe someone of the more experienced users with DllCall can shine some light onto this?

Reference pages with the functions:

GetSystemMenu: http://msdn2.microsoft.com/en-us/library/ms647985.aspx

InsertMenuItem: http://msdn2.microsoft.com/en-us/library/m...988(VS.85).aspx

Edited by FreeFry
Link to comment
Share on other sites

I solved my problem in another way.

the following script moves the active window to the other screen (left to right or right to left)

WinSetState("","", @sw_RESTORE )
$size = WinGetPos("")

if $size[0] < @DesktopWidth-4 Then;must be -4 or it stays on the right screen
; is left, move to right
    WinMove("", "", @DesktopWidth + 1, 0, 1000, 500);@DesktopWidth + 1 as x coordinate brings you in screen 2
Else
; is right, move to left
    WinMove("", "", 50, 0, 1000, 5000)
Endif
WinSetState("","", @SW_MAXIMIZE );maximize again

To make it work with all screens you must create a shortcut to this script on the desktop and assign a shortcut key to this script

(rightclick on shortcut --> properties --> shortcut tab --> choose shortcut combination) (for me ctrl-alt-W because i can use only my left hand)

The script must be closed or it will only be activated instead of moving.

please let me know if anybody know how to make it work with a right click on the title. (this would be better because then i do not have to use the keyboard).

If you, experienced users, know a better or quicker way, please let me know as well.

Thanks

Kurt.

Link to comment
Share on other sites

I guess you could just use an AutoIt Hotkey instead?

Something like this:

Opt("WinTitleMatchMode", 4)

HotKeySet("^!w", "_ToggleScreen")

While 1
    
    Sleep(1000) 
    
WEnd

Func _ToggleScreen()
    
    HotKeySet("^!w")
    
    Local $wHandle = WinGetHandle("[ACTIVE]")
    Local $wPos = WinGetPos($wHandle)
    
    If $wPos[0] < @DesktopWidth Then
        WinMove($wHandle, "", @DesktopWidth+$wPos[0], $wPos[1], $wPos[2], $wPos[3], 2)
    Else
        WinMove($wHandle, "", $wPos[0]-@DesktopWidth, $wPos[1], $wPos[2], $wPos[3], 2)
    EndIf
    
    HotKeySet("^!w", "_ToggleScreen")
    
EndFunc

Edit:

One workaround to make it possible to right click the title of a window and have a custom menu there could probably be done by detecting when a rightclick occurs, and then see if it was in the title area of the window which is active, and then draw a small gui with a few buttons there...

Edit:

Too bad that the AnimateWindow() API function doesn't work with windows that you do not "own", otherwise some neat effects could be made when moving the window...

Edited by FreeFry
Link to comment
Share on other sites

  • 2 weeks later...

Thanks FreeFry,

I'm new to AutoIt, just getting past Hello World!, looking for the "how to get off the ground"

starting points.

This ToggleScreen script is a sweet starting point.

And, as a noob, I have some questions.

1) What is the difference between

Opt("WinTitleMatchMode", 4)

Local $wHandle = WinGetHandle("[ACTIVE]")

and

Local $wHandle = WinGetHandle("")

?

2) You set the hotkey and then the first thing you do inside the function is turn it off.

Then the last thing you do is turn the hotkey back on again.

I'm presuming the hotkey stays active until you turn it off so you have to manually turn it off.

Is the point of this to keep another press of the same hotkey from interrupting the move

(e.g., stuttering in the pressing, autorepeat from holding it down, or just getting impatient

and pressing it again)?

3) Is there a reason that

@DesktopWidth+$wPos[0]

and

$wPos[0]-@DesktopWidth

are in opposite order? To emphasize the difference?

Would

$wPos[0]+@DesktopWidth

behave identically to the first, or is there an obscure rule about typing or some such

that I'm missing?

Thanks,

August

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...