Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Msgbox button label change?


  • Please log in to reply
16 replies to this topic
majstang
  • Members
  • 387 posts
  • Last active: Sep 27 2015 01:44 PM
  • Joined: 29 Aug 2008
Hi!

Is it possible to change the button label (OK, Cancel, Yes, No) to something else on messageboxes used by autohotkey?

MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
Have you tried the manual?

The names of the buttons can be customized by following this example.


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


majstang
  • Members
  • 387 posts
  • Last active: Sep 27 2015 01:44 PM
  • Joined: 29 Aug 2008
Thanks! Apparently I did miss that row of information :oops:

A question though. When testing the ChangeButtonName script I wonder if it is possible to make it faster in any way. When executing the script the button name change is delayed by a sec or so. It is so slow that it is no problem to see the original button names before the change occur. Changing SetTimer period value seem not to make any difference.

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007
Make a Gui it is easy but don't ask HOW, just read the docs, make one first and only THEN post your code if you get stuck.

hamlin
  • Guests
  • Last active:
  • Joined: --

Thanks! Apparently I did miss that row of information :oops:

A question though. When testing the ChangeButtonName script I wonder if it is possible to make it faster in any way. When executing the script the button name change is delayed by a sec or so. It is so slow that it is no problem to see the original button names before the change occur. Changing SetTimer period value seem not to make any difference.

This is a re-code of the example in the help file. It is based on the technique shown by Lexikos (in long lost post).
#SingleInstance, force
OnMessage(0x44, "WM_COMMNOTIFY") 
MsgBox, 4, Add or Delete, Choose a button:
IfMsgBox, YES 
    MsgBox, You chose Add. 
else 
    MsgBox, You chose Delete. 
ExitApp 

WM_COMMNOTIFY(wParam) { 
    if (wParam = 1027) { ; AHK_DIALOG 
        Process, Exist 
        DetectHiddenWindows, On 
        if WinExist("Add or Delete ahk_class #32770 ahk_pid " . ErrorLevel) { 
          ControlSetText, Button1, &Add 
          ControlSetText, Button2, &Delete
        } 
    } 
}


majstang
  • Members
  • 387 posts
  • Last active: Sep 27 2015 01:44 PM
  • Joined: 29 Aug 2008
That is the stuff im looking for :D
Thanks for the tip @hamlin!
Much more comfortable sticking with MsgBoxes...the GUI instructions are really messy to say att least. I will have to learn it sometime in the future though.

Regards
Majstang

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007
After you've learned about GUI you will laugh at the complicated solution provided by hamlin. The Gui code will be short, more elegant and easier to maintain and expand. But of course you are much better of watching recorded TV shows than actually trying to learn something new. :D

majstang
  • Members
  • 387 posts
  • Last active: Sep 27 2015 01:44 PM
  • Joined: 29 Aug 2008
Well, since you are making fun of my lazyness I wonder if you could show me a GUI example with this code then :wink:
The hard part with GUI is I have no idea on how/where to insert my own code in the GUI, much easier with method which is known and familiar. Me trying the GUI method will require so much trial and error I would waste half my vacation :lol:

This code works beautiful btw.

#SingleInstance, force
OnMessage(0x44, "WM_COMMNOTIFY")
MsgBox, 4, SOVRUM TV eller HEMMABIO TV, Vilken TV vill du använda för att titta på %1%?
IfMsgBox Yes
{
  Run, E:\AVI_VOB_BLU-RAY_AC3-tools\AVI & DIVX-tools\Media Player Classic\mplayerc_homecinema_x86_v1.2.908.0\mplayerc.exe "%1%"
  Sleep, 1000
  Postmessage, 0x111, 886,,, ahk_class MediaPlayerClassicW ; options
  SendInput, {Up 16} ; focus first entry
  SendInput, {Down 7} ; output
  Sleep, 3000
  ControlGet, OutputVar, Choice, , ComboBox2, ahk_class #32770
    If OutputVar = DirectSound: ATI HD Audio rear output (00200000)
     {
       PostMessage, 0x112, 0xF060,,, ahk_class #32770,
       ;ControlClick, OK, ahk_class #32770
       Sleep, 500
       Postmessage, 0x111, 830,,, ahk_class MediaPlayerClassicW ; full screen
     }
    If OutputVar = DirectSound: Realtek HD Audio output (00200000)
     {
       Control, Choose, 7, ComboBox2, ahk_class #32770
       ControlClick, OK, ahk_class #32770
       WinClose, ahk_class MediaPlayerClassicW
       Run, mplayerc.exe, E:\AVI_VOB_BLU-RAY_AC3-tools\AVI & DIVX-tools\Media Player Classic\mplayerc_homecinema_x86_v1.2.908.0
       Sleep, 1000
       Postmessage, 0x111, 800,,, ahk_class MediaPlayerClassicW ; open file
       SendInput, {ENTER}
       Sleep, 5000
       Postmessage, 0x111, 830,,, ahk_class MediaPlayerClassicW ; full screen
      }
}
Else
{
  Run, E:\AVI_VOB_BLU-RAY_AC3-tools\AVI & DIVX-tools\Media Player Classic\mplayerc_homecinema_x86_v1.2.908.0\mplayerc.exe "%1%"
  Sleep, 1000
  Postmessage, 0x111, 886,,, ahk_class MediaPlayerClassicW ; options
  SendInput, {Up 16} ; focus first entry
  SendInput, {Down 7} ; output
  Sleep, 3000
  ControlGet, OutputVar, Choice, , ComboBox2, ahk_class #32770

    If OutputVar = DirectSound: Realtek HD Audio output (00200000)
     {
       PostMessage, 0x112, 0xF060,,, ahk_class #32770,
       ;ControlClick, OK, ahk_class #32770
       Sleep, 500
       Postmessage, 0x111, 830,,, ahk_class MediaPlayerClassicW ; full screen
     }
    If OutputVar = DirectSound: ATI HD Audio rear output (00200000)
     {
       Control, Choose, 8, ComboBox2, ahk_class #32770
       ControlClick, OK, ahk_class #32770
       WinClose, ahk_class MediaPlayerClassicW
       Run, mplayerc.exe, E:\AVI_VOB_BLU-RAY_AC3-tools\AVI & DIVX-tools\Media Player Classic\mplayerc_homecinema_x86_v1.2.908.0
       Sleep, 1000
       Postmessage, 0x111, 800,,, ahk_class MediaPlayerClassicW ; open file
       SendInput, {ENTER}
       Sleep, 5000
       Postmessage, 0x111, 830,,, ahk_class MediaPlayerClassicW ; full screen
     }
}
ExitApp

WM_COMMNOTIFY(wParam)
{
    if (wParam = 1027)
      {
        ;AHK_DIALOG
        Process, Exist
        DetectHiddenWindows, On
        if WinExist("SOVRUM TV eller HEMMABIO TV ahk_class #32770 ahk_pid " . ErrorLevel)
          {
            ControlSetText, Button1, &Sovrum TV
            ControlSetText, Button2, &Hemmabio TV
          }
      }
}


ShamWow
  • Members
  • 75 posts
  • Last active: Nov 20 2010 02:38 AM
  • Joined: 28 Jul 2010
If for some reason you can't change it to what you want it to say, it's best to build a gui, and then use GuiControl,, ButtonName, Label

Cheers.

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007
Gui, Add, Text  , , What are you going to do?

Gui, Add, Button, gWatch, Watch TV

Gui, Add, Button, xp+70 yp gLearn, Learn some new skills

Gui, Show, w200 h100 center, What are you going to do?

Return



Watch:

MsgBox Good for you!

Return



Learn:

Run http://www.autohotkey.com/docs/commands/Gui.htm

Return



Esc::

GuiClose:

ExitApp

Return


majstang
  • Members
  • 387 posts
  • Last active: Sep 27 2015 01:44 PM
  • Joined: 29 Aug 2008
Ok, thanks for your VERY funny example @hugov :lol:
Tried to insert my own code in your script and did some other changes to get it to work similar to the earlier very complicated msgbox example, according to you. Two big issues arised which i do not know how to fix.

- Buttons are not centered. Since the videofile name varies in length, buttons end up all over inside the gui. I cant find any instructions on how to make buttons stay on center near bottom gui boarder all the time.

EDIT: Fixed the second issue with exchanging
ControlClick, Button22, ahk_class #32770
with
SendInput, {ENTER}
- The change of audiorenderer stopped working with this code. Despite the script does change audiorenderer (which is possible to see with own eyes), but it does not stick. An anomalie I can not understand at all, since the exact same code works great in the MsgBox example.

Gui, Add, Text,, Which TV do you wanna use for watching %1%?
Gui, Add, Button, gBedroom, Bedroom TV
Gui, Add, Button, xp+80 yp gHomecinema, Homecinema TV
Gui, Show, AutoSize center, BEDROOM TV eller HOMECINEMA TV?
Return

Bedroom:
  Run, E:\AVI_VOB_BLU-RAY_AC3-tools\AVI & DIVX-tools\Media Player Classic\mplayerc_homecinema_x86_v1.2.908.0\mplayerc.exe "%1%"
  Sleep, 1000
  Postmessage, 0x111, 886,,, ahk_class MediaPlayerClassicW ; options
  SendInput, {Up 16} ; focus first entry
  SendInput, {Down 7} ; output
  Sleep, 3000
  ControlGet, OutputVar, Choice, , ComboBox2, ahk_class #32770
    If OutputVar = DirectSound: ATI HD Audio rear output (00200000)
     {
       PostMessage, 0x112, 0xF060,,, ahk_class #32770,
       ;ControlClick, Button22, ahk_class #32770
       Sleep, 500
       Postmessage, 0x111, 830,,, ahk_class MediaPlayerClassicW ; full screen
     }
    If OutputVar = DirectSound: Realtek HD Audio output (00200000)
     {
       Control, Choose, 7, ComboBox2, ahk_class #32770
       ControlClick, Button22, ahk_class #32770
       WinClose, ahk_class MediaPlayerClassicW
       Run, mplayerc.exe, E:\AVI_VOB_BLU-RAY_AC3-tools\AVI & DIVX-tools\Media Player Classic\mplayerc_homecinema_x86_v1.2.908.0
       Sleep, 1000
       Postmessage, 0x111, 800,,, ahk_class MediaPlayerClassicW ; open file
       SendInput, {ENTER}
       Sleep, 5000
       Postmessage, 0x111, 830,,, ahk_class MediaPlayerClassicW ; full screen
      }
ExitApp
Return


Homecinema:
  Run, E:\AVI_VOB_BLU-RAY_AC3-tools\AVI & DIVX-tools\Media Player Classic\mplayerc_homecinema_x86_v1.2.908.0\mplayerc.exe "%1%"
  Sleep, 1000
  Postmessage, 0x111, 886,,, ahk_class MediaPlayerClassicW ; options
  SendInput, {Up 16} ; focus first entry
  SendInput, {Down 7} ; output
  Sleep, 3000
  ControlGet, OutputVar, Choice, , ComboBox2, ahk_class #32770

    If OutputVar = DirectSound: Realtek HD Audio output (00200000)
     {
       PostMessage, 0x112, 0xF060,,, ahk_class #32770,
       ;ControlClick, Button22, ahk_class #32770
       Sleep, 500
       Postmessage, 0x111, 830,,, ahk_class MediaPlayerClassicW ; full screen
     }
    If OutputVar = DirectSound: ATI HD Audio rear output (00200000)
     {
       Control, Choose, 8, ComboBox2, ahk_class #32770
       ControlClick, Button22, ahk_class #32770
       WinClose, ahk_class MediaPlayerClassicW
       Run, mplayerc.exe, E:\AVI_VOB_BLU-RAY_AC3-tools\AVI & DIVX-tools\Media Player Classic\mplayerc_homecinema_x86_v1.2.908.0
       Sleep, 1000
       Postmessage, 0x111, 800,,, ahk_class MediaPlayerClassicW ; open file
       SendInput, {ENTER}
       Sleep, 5000
       Postmessage, 0x111, 830,,, ahk_class MediaPlayerClassicW ; full screen
     }
ExitApp
Return


Esc::
GuiClose:
ExitApp
Return


SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007

Ok, thanks for your VERY funny example @hugov :lol:

Glad you liked it. If you click the learn button and look up gui, add, button you can see you can position each button on a specific X Y location and set the width & height of each button as well.

majstang
  • Members
  • 387 posts
  • Last active: Sep 27 2015 01:44 PM
  • Joined: 29 Aug 2008

Ok, thanks for your VERY funny example @hugov :lol:

Glad you liked it. If you click the learn button and look up gui, add, button you can see you can position each button on a specific X Y location and set the width & height of each button as well.

Dont think you quite understand my script, probably cuz you didnt test it before giving me pointers. The %1% show the name on the file in gui/msgbox that will be played and this name will have different amout of letters each time. If setting buttons to a specific X and Y coordinate, the position of the buttons will fluctuate back and forth depending on how long the filename is. Why bother with this when I already have a msgbox doing everything that i want per automatic.

Thanks, for your help! Upside you actually got what you wanted, I now have much better understanding of the gui concept than before...mission accomplished, @hugov :wink:

SoLong&Thx4AllTheFish
  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007
You can calculate the x/y pos if you wanted to :wink: Anway, we all love raymond that's for sure :!: :D

majstang
  • Members
  • 387 posts
  • Last active: Sep 27 2015 01:44 PM
  • Joined: 29 Aug 2008

You can calculate the x/y pos if you wanted to :wink: Anway, we all love raymond that's for sure :!: :D


After you've learned about GUI you will laugh at the complicated solution provided by hamlin. The Gui code will be short, more elegant and easier to maintain and expand. But of course you are much better of watching recorded TV shows than actually trying to learn something new. :D

Now it is you that suggest a really complicated method. The GUI way is not suited for the code im using because of the way the messagebox constantly varies in size on the x-axis. A messagebox has fixed parameters and deals with this very well per automatic, while a GUI not so well unless you are really skilled in autohotkey.

If it is so easy as you say please show me a gui that has all the characteristics as and looks exactly like the msgbox im using in my code example?

For the script to work you have to associate .AVI files with your compiled .exe which is containing this code. When executing .AVI files on your computer the msgbox pops up and gives you two different options.


#SingleInstance, force
OnMessage(0x44, "WM_COMMNOTIFY")

MsgBox, 4, BEDROOM TV or HOMECINEMA TV, Which TV do you wanna use for watching %1%?
SetTimer, WatchForMenu, 5
IfMsgBox Yes
{
  Run, E:\AVI_VOB_BLU-RAY_AC3-tools\AVI & DIVX-tools\Media Player Classic\mplayerc_homecinema_x86_v1.2.908.0\mplayerc.exe "%1%"
  Sleep, 1000
  Postmessage, 0x111, 886,,, ahk_class MediaPlayerClassicW ; options
  SendInput, {Up 16} ; focus first entry
  SendInput, {Down 7} ; output
  Sleep, 3000
  ControlGet, OutputVar, Choice, , ComboBox2, ahk_class #32770
    If OutputVar = DirectSound: ATI HD Audio rear output (00200000)
     {
       PostMessage, 0x112, 0xF060,,, ahk_class #32770,
       ;ControlClick, OK, ahk_class #32770
       Sleep, 500
       Postmessage, 0x111, 830,,, ahk_class MediaPlayerClassicW ; full screen
     }
    If OutputVar = DirectSound: Realtek HD Audio output (00200000)
     {
       Control, Choose, 7, ComboBox2, ahk_class #32770
       SendInput, {ENTER}
       ;ControlClick, OK, ahk_class #32770
       WinClose, ahk_class MediaPlayerClassicW
       Run, mplayerc.exe, E:\AVI_VOB_BLU-RAY_AC3-tools\AVI & DIVX-tools\Media Player Classic\mplayerc_homecinema_x86_v1.2.908.0
       Sleep, 1000
       Postmessage, 0x111, 800,,, ahk_class MediaPlayerClassicW ; open file
       SendInput, {ENTER}
       Sleep, 5000
       Postmessage, 0x111, 830,,, ahk_class MediaPlayerClassicW ; full screen
      }
}
Else
{
  Run, E:\AVI_VOB_BLU-RAY_AC3-tools\AVI & DIVX-tools\Media Player Classic\mplayerc_homecinema_x86_v1.2.908.0\mplayerc.exe "%1%"
  Sleep, 1000
  Postmessage, 0x111, 886,,, ahk_class MediaPlayerClassicW ; options
  SendInput, {Up 16} ; focus first entry
  SendInput, {Down 7} ; output
  Sleep, 3000
  ControlGet, OutputVar, Choice, , ComboBox2, ahk_class #32770

    If OutputVar = DirectSound: Realtek HD Audio output (00200000)
     {
       PostMessage, 0x112, 0xF060,,, ahk_class #32770,
       ;ControlClick, OK, ahk_class #32770
       Sleep, 500
       Postmessage, 0x111, 830,,, ahk_class MediaPlayerClassicW ; full screen
     }
    If OutputVar = DirectSound: ATI HD Audio rear output (00200000)
     {
       Control, Choose, 8, ComboBox2, ahk_class #32770
       SendInput, {ENTER}
       ;ControlClick, OK, ahk_class #32770
       WinClose, ahk_class MediaPlayerClassicW
       Run, mplayerc.exe, E:\AVI_VOB_BLU-RAY_AC3-tools\AVI & DIVX-tools\Media Player Classic\mplayerc_homecinema_x86_v1.2.908.0
       Sleep, 1000
       Postmessage, 0x111, 800,,, ahk_class MediaPlayerClassicW ; open file
       SendInput, {ENTER}
       Sleep, 5000
       Postmessage, 0x111, 830,,, ahk_class MediaPlayerClassicW ; full screen
     }
}
ExitApp
;return  ; End of auto-execute section.

WatchForMenu:
DetectHiddenWindows, on  ; Might allow detection of menu sooner.
IfWinExist, ahk_class #32770
   WinSet, Transparent, 0  ; Uses the window found by the above line.
return


WM_COMMNOTIFY(wParam)
{
    if (wParam = 1027)
      {
        ;AHK_DIALOG
        Process, Exist
        DetectHiddenWindows, On
        if WinExist("BEDROOM TV or HOMECINEMA TV ahk_class #32770 ahk_pid " . ErrorLevel)
          {
            ControlSetText, Button1, &Bedroom TV
            ControlSetText, Button2, &Homecinema TV
          }
      }
}