PcExpert Posted January 18, 2006 Share Posted January 18, 2006 Hello, Howto create a MsgBOX with a OK and CANCEL button. But when you want to push the CANCEL button it goes away. I know how rto do the first part, but how do I create that CANCEL button that goes away? Link to comment Share on other sites More sharing options...
Oxin8 Posted January 18, 2006 Share Posted January 18, 2006 it's in the help file. If MsgBox(1,"Hello","Want to continue?") = 2 Then ;code if cancel was selected EndIf ~My Scripts~ *********_XInput UDF for Xbox 360 ControllerSprayPaint_MouseMovePlus Link to comment Share on other sites More sharing options...
PcExpert Posted January 18, 2006 Author Share Posted January 18, 2006 Thanks, but that wasn't the thing I need. I mean: If you want to push the CANCEL button it disappears. What's the code to get that to work? Link to comment Share on other sites More sharing options...
BigDod Posted January 18, 2006 Share Posted January 18, 2006 Why would you want a cancel button that disappears if you try to press it ? Are you up to no good ? Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother Link to comment Share on other sites More sharing options...
Oxin8 Posted January 18, 2006 Share Posted January 18, 2006 Why would you want a cancel button that disappears if you try to press it ?Are you up to no good ?It would seem so... I don't how much help you're gonna get trying to do something like that... I'll see if I can get something worked out for you. If you're gonna be up to no good though, you're probably better off learning how to do things on your own. We don't really take kind to virus like creations here... ~My Scripts~ *********_XInput UDF for Xbox 360 ControllerSprayPaint_MouseMovePlus Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 18, 2006 Moderators Share Posted January 18, 2006 First... What goes away when you press the cancel button... The MsgBox or the Cancel button? Second... If it's the MsgBox() then what do you want to do while it 'goes away'? Is there a specific task, then you want to bring it back? Probably should elaborate just a tad more Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
PcExpert Posted January 18, 2006 Author Share Posted January 18, 2006 It is not for no good things or samething. It's gonna be a program that you can start by yourself and then it does samethings. It is the same as a dutch website. There are coming some msgboxes with text like "Hello, why have you started this program, the title of the program said 'don't start". That's all Link to comment Share on other sites More sharing options...
PcExpert Posted January 18, 2006 Author Share Posted January 18, 2006 SmOke_N, it's the CANCEL button that disappears. And when it goes a way you will have to push the OK button. Link to comment Share on other sites More sharing options...
BigDod Posted January 18, 2006 Share Posted January 18, 2006 SmOke_N, it's the CANCEL button that disappears. And when it goes a way you will have to push the OK button.Why bother having a cancel button at all. Surely you just need a msgbox that just has an ok button. Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother Link to comment Share on other sites More sharing options...
PcExpert Posted January 18, 2006 Author Share Posted January 18, 2006 (edited) Sorry, but I forgot something. When youre mouse isn't at the CANCEL button, it appears. and then you have to push the OK button Edited January 18, 2006 by PcExpert Link to comment Share on other sites More sharing options...
Bert Posted January 18, 2006 Share Posted January 18, 2006 The simple thing to do is have 2 msgboxs, one with the cancel button and the OK, and one just with ok. If you press cancel, the fist msgbox will close, and the second will open. It would not be noticed by the user that you used 2 windows. The Vollatran project  My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Oxin8 Posted January 18, 2006 Share Posted January 18, 2006 So I threw something together for ya. I think it's what you had in mine. Since MsgBox pauses the script, you're gonna need two running(correct me if I'm wrong). If you need in it one exe, look at FileInstall and Run in the help file. The first script is simple. Just opens the MsgBox. MsgBox(1,"Hello","Press Cancel to quit.") The second monitors the mouse position and takes appropriate action. Opt("MouseCoordMode",0) WinWaitActive("Hello") While WinExists("Hello") $pos = MouseGetPos() If $pos[0]>93 AND $pos[0]<171 AND $pos[1]>61 AND $pos[1]<86 Then ControlHide( "Hello", "", 2) Else ControlShow( "Hello", "", 2) EndIf Sleep(10) WEnd Hope that's what you wanted. ~My Scripts~ *********_XInput UDF for Xbox 360 ControllerSprayPaint_MouseMovePlus Link to comment Share on other sites More sharing options...
PcExpert Posted January 18, 2006 Author Share Posted January 18, 2006 Thanks, thats it! Link to comment Share on other sites More sharing options...
herewasplato Posted January 18, 2006 Share Posted January 18, 2006 I have a little joke exe that I got from somewhere that displays this text (typos included):Dear Americans. Given my behavior with regards to the Lewinsky matter, I've decided to let my fait be decided by public vote. The answers will be tabulated and I will do what the majority of voters decide I should. I place myself in your hands.YESNOShould I, Bill Clinton, resign and leave public life in shame?The 'YES' button moves away from the mouse... once you give up and press "NO", you get:Thanks for your honest vote of support!Let's hope that PcExpert is going for humor and not evil :-) [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
PcExpert Posted January 18, 2006 Author Share Posted January 18, 2006 I'm Going for humor Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 18, 2006 Moderators Share Posted January 18, 2006 (edited) LOL... This was kind of fun to make!!expandcollapse popup#include <GUICONSTANTS.AU3> #NoTrayIcon Opt('MouseCoordMode', 2) $MyBox = _MsgBox(2, 'Catch Me', 'Click OK if you think that this is funny!') If $MyBox = 6 Then MsgBox(0, 'Good', "I'm glad you agree with me") Func _MsgBox($mb_Icon, $mb_Title, $mb_Text, $mb_Time = '') Local $StrnLenText = MsgLongestString($mb_Text) Local $NumberOfLines = (UBound(StringSplit($mb_Text, @CRLF)) - 1) * 5 Local $Button1Txt = "OK" Local $Button2Txt = "Cancel" Local $MsgValue = 0 Local $TOP = 45 + $NumberOfLines Local $WIDTH = 60 + StringLen($Button1Txt) Local $BUTTON1LEFT = 30 + ($StrnLenText / 2) Local $BUTTON2LEFT = 100 + ($StrnLenText / 2) Local $Timer = '' ClipPut($TOP & @CRLF & $WIDTH & @CRLF & $BUTTON1LEFT & @CRLF & $BUTTON2LEFT) $iMsgBox = GUICreate($mb_Title, $StrnLenText + 190, 100 + $NumberOfLines, -1, -1, 0x00400000, 0x00000008) GUICtrlCreateLabel($mb_Text, 60, 10) GUICtrlCreateIcon(@SystemDir & "\User32.dll", $mb_Icon, 10, 10, 35, 35) $OK = GUICtrlCreateButton($Button1Txt, $BUTTON1LEFT, $TOP, $WIDTH, 25) $Cancel = GUICtrlCreateButton($Button2Txt, $BUTTON2LEFT, $TOP, $WIDTH, 25) GUISetState() If $mb_Time <> '' Then $Timer = TimerInit() While 1 $imsg = GUIGetMsg() Select Case $imsg = $OK $MsgValue = 6 ExitLoop Case $imsg = $Cancel $MsgValue = 7 MsgBox(0, 'Caught', 'Oh!!, you caught the "Cancel" button!!') Case $mb_Time <> '' If TimerDiff($Timer) / 1000 >= $mb_Time Then ExitLoop EndSelect Local $MousePos = MouseGetPos() GUISetState($GUI_FOCUS) While IsArray($MousePos) And $MousePos[0] >= $BUTTON2LEFT And $MousePos[0] <= $BUTTON2LEFT + $WIDTH And $MousePos[1] >= $TOP And $MousePos[1] <= $TOP + 25 $MousePos = MouseGetPos() If ControlCommand($iMsgBox, 'Cancel', $Cancel, 'IsVisible', '') Then ControlHide($iMsgBox, 'Cancel', 'Button2') WEnd If Not ControlCommand($iMsgBox, 'Cancel', $Cancel, 'IsVisible', '') Then ControlShow($iMsgBox, 'Cancel', 'Button2') WEnd GUIDelete($iMsgBox) Return $MsgValue EndFunc Func MsgLongestString($sText) Local $sSplit = StringSplit($sText, @CRLF) Local $Times = '' If Not @error Then ArraySortByLen($sSplit) If StringLen($sSplit[1]) <= 100 Then $Times = 2.25 If StringLen($sSplit[1]) >= 101 And StringLen($sSplit[1]) <= 150 Then $Times = 2.5 If StringLen($sSplit[1]) >= 151 And StringLen($sSplit[1]) <= 201 Then $Times = 3 If StringLen($sSplit[1]) >= 202 Then $Times = 3.25 Return Round(StringLen($sSplit[1])*$Times) Else If StringLen($sText) <= 100 Then $Times = 2.25 If StringLen($sText) >= 101 And StringLen($sText) <= 150 Then $Times = 2.5 If StringLen($sText) >= 151 And StringLen($sText) <= 201 Then $Times = 3 If StringLen($sText) >= 202 Then $Times = 3.25 Return Round(StringLen($sText)*$Times) EndIf EndFunc Func ArraySortByLen(ByRef $nArray, $Start = 1) For $i = $Start To UBound($nArray) - 2 Local $SE = $i For $x = $i To UBound($nArray) - 1 If StringLen($nArray[$SE]) < StringLen($nArray[$x]) Then $SE = $x Next Local $HLD = $nArray[$i] $nArray[$i] = $nArray[$SE] $nArray[$SE] = $HLD Next EndFunc Edited January 18, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
herewasplato Posted January 18, 2006 Share Posted January 18, 2006 LOL... This was kind of fun to make!!You don't need this line do you?ClipPut($TOP & @CRLF & $WIDTH & @CRLF & $BUTTON1LEFT & @CRLF & $BUTTON2LEFT)It seems to work without it. The reason why I noticed - I was running the code from the clipboard and could only run it once...Good code! Now make the cancel button move around like the YES button in vote.exe:http://www.soimmature.com/sub_pages/movies_and_games.html:-) [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 18, 2006 Moderators Share Posted January 18, 2006 You don't need this line do you?ClipPut($TOP & @CRLF & $WIDTH & @CRLF & $BUTTON1LEFT & @CRLF & $BUTTON2LEFT)It seems to work without it. The reason why I noticed - I was running the code from the clipboard and could only run it once...Good code! Now make the cancel button move around like the YES button in vote.exe:http://www.soimmature.com/sub_pages/movies_and_games.html:-)Ha... that line was when I was debugging it. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 18, 2006 Moderators Share Posted January 18, 2006 Here Plato, this is as much as I could think at the moment... I need to go to bed!! See what any of ya'll can do with it ... Have fun!expandcollapse popup#include <GUICONSTANTS.AU3> #NoTrayIcon Opt('MouseCoordMode', 2) HotKeySet('{ESC}', 'EXITNOW') $MyBox = _MsgBox(2, 'Catch Me', 'Click OK if you think that this is funny!') If $MyBox = 6 Then MsgBox(0, 'Good', "I'm glad you agree with me") Func _MsgBox($mb_Icon, $mb_Title, $mb_Text, $mb_Time = '') Local $StrnLenText = MsgLongestString($mb_Text) Local $NumberOfLines = (UBound(StringSplit($mb_Text, @CRLF)) - 1) * 5 Local $Button1Txt = "OK" Local $Button2Txt = "Cancel" Local $MsgValue = 0 Local $TOP = 45 + $NumberOfLines Local $WIDTH = 60 + StringLen($Button1Txt) Local $BUTTON1LEFT = 30 + ($StrnLenText / 2) Local $BUTTON2LEFT = 100 + ($StrnLenText / 2) Local $GUIWIDTH = $StrnLenText + 190 Local $GUIHEIGHT = 100 + $NumberOfLines Local $Timer = '' Dim $COORDS[4] ;ClipPut($TOP & @CRLF & $WIDTH & @CRLF & $BUTTON1LEFT & @CRLF & $BUTTON2LEFT) $iMsgBox = GUICreate($mb_Title, $GUIWIDTH, $GUIHEIGHT, -1, -1, 0x00400000, 0x00000008) GUICtrlCreateLabel($mb_Text, 60, 10) GUICtrlCreateIcon(@SystemDir & "\User32.dll", $mb_Icon, 10, 10, 35, 35) $OK = GUICtrlCreateButton($Button1Txt, $BUTTON1LEFT, $TOP, $WIDTH, 25) $Cancel = GUICtrlCreateButton($Button2Txt, $BUTTON2LEFT, $TOP, $WIDTH, 25) GUISetState() If $mb_Time <> '' Then $Timer = TimerInit() While 1 $imsg = GUIGetMsg() $COORDS = WinGetPos($iMsgBox) _MouseTrap($coords[0] + 15, $coords[1] + 35, $coords[0] + $coords[2] - 15, $coords[1] + $coords[3] - 20) Select Case $imsg = $OK $MsgValue = 6 ExitLoop Case $imsg = $Cancel $MsgValue = 7 MsgBox(0, 'Caught', 'Oh!!, you caught the "Cancel" button!!') Case $mb_Time <> '' If TimerDiff($Timer) / 1000 >= $mb_Time Then ExitLoop EndSelect Local $MousePos = MouseGetPos() Local $ControlPos = ControlGetPos($iMsgBox, 'Cancel', 'Button2') GUISetState($GUI_FOCUS) While $MousePos[0] >= $ControlPos[0] - 1 And $MousePos[0] <= $ControlPos[0] + $ControlPos[2] + 1 And $MousePos[1] >= $ControlPos[1] - 1 And $MousePos[1] <= $ControlPos[1] + $ControlPos[3] + 1 $COORDS = WinGetPos($iMsgBox) _MouseTrap($coords[0] + 15, $coords[1] + 435, $coords[0] + $coords[2] - 15, $coords[1] + $coords[3] - 20) $MousePos = MouseGetPos() $ControlPos = ControlGetPos($iMsgBox, 'Cancel', 'Button2') If $ControlPos[0] <= $GUIWIDTH - $WIDTH And $ControlPos[1] <= $GUIHEIGHT - $TOP Then ControlMove($iMsgBox, 'Cancel', 'Button2', $MousePos[0] + 25, $MousePos[1] + 25) Else ControlMove($iMsgBox, 'Cancel', 'Button2', $MousePos[0] - 25, $MousePos[1] - 25) EndIf WEnd $ControlPos = ControlGetPos($iMsgBox, 'Cancel', 'Button2') If $MousePos[0] - $ControlPos[0] > 80 And $MousePos[1] - $ControlPos[1] > 50 Then ControlMove($iMsgBox, 'Cancel', 'Button2', $BUTTON2LEFT, $TOP) EndIf WEnd GUIDelete($iMsgBox) Return $MsgValue EndFunc Func MsgLongestString($sText) Local $sSplit = StringSplit($sText, @CRLF) Local $Times = '' If Not @error Then ArraySortByLen($sSplit) If StringLen($sSplit[1]) <= 100 Then $Times = 2.25 If StringLen($sSplit[1]) >= 101 And StringLen($sSplit[1]) <= 150 Then $Times = 2.5 If StringLen($sSplit[1]) >= 151 And StringLen($sSplit[1]) <= 201 Then $Times = 3 If StringLen($sSplit[1]) >= 202 Then $Times = 3.25 Return Round(StringLen($sSplit[1])*$Times) Else If StringLen($sText) <= 100 Then $Times = 2.25 If StringLen($sText) >= 101 And StringLen($sText) <= 150 Then $Times = 2.5 If StringLen($sText) >= 151 And StringLen($sText) <= 201 Then $Times = 3 If StringLen($sText) >= 202 Then $Times = 3.25 Return Round(StringLen($sText)*$Times) EndIf EndFunc Func ArraySortByLen(ByRef $nArray, $Start = 1) For $i = $Start To UBound($nArray) - 2 Local $SE = $i For $x = $i To UBound($nArray) - 1 If StringLen($nArray[$SE]) < StringLen($nArray[$x]) Then $SE = $x Next Local $HLD = $nArray[$i] $nArray[$i] = $nArray[$SE] $nArray[$SE] = $HLD Next EndFunc Func EXITNOW() Exit EndFunc Func _MouseTrap($i_left = 0, $i_top = 0, $i_right = 0, $i_bottom = 0) Local $av_ret If @NumParams == 0 Then $av_ret = DllCall("user32.dll", "int", "ClipCursor", "int", 0) Else If @NumParams == 2 Then $i_right = $i_left + 1 $i_bottom = $i_top + 1 EndIf Local $Rect = DllStructCreate("int;int;int;int") If @error Then Return 0 DllStructSetData($Rect, 1, $i_left) DllStructSetData($Rect, 2, $i_top) DllStructSetData($Rect, 3, $i_right) DllStructSetData($Rect, 4, $i_bottom) $av_ret = DllCall("user32.dll", "int", "ClipCursor", "ptr", DllStructGetPtr($Rect)) ; DllStructDelete($Rect) EndIf Return $av_ret[0] EndFunc Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
herewasplato Posted January 18, 2006 Share Posted January 18, 2006 Here Plato, this is as much as I could think at the moment...I wondered where you were going with mousetrap - had to DL beta to find out.Good job - only now, PcExpert does not have anything left to code...... :-) [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now