Jump to content

orbs

Active Members
  • Posts

    1,656
  • Joined

  • Last visited

  • Days Won

    6

orbs last won the day on August 13

orbs had the most liked content!

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

orbs's Achievements

  1. "Everything" is a powerful engine, incorporating it into AutoIt is welcome. your function however does not receive search criteria? as i understand, it depends on your manual search in the Everything GUI, and only retrieves its results to an array? also, are you aware Everything has a CLI? it is probably easier and safer to manipulate, and most definitely easier to pass search criteria to.
  2. one way would be to use it as intended: do not store the password in your script, instead have your script ask you for the password (via inputBox() for example). this is feasible when you don't need to do it too often. if you do, you can streamline the process by using an external password manager (KeePass for example), which can automatically insert the password when prompted. but that's not how i would go about this. i'd consider storing the username and password in the built-in Windows Credential Manager. you can query it to retrieve the credentials, and have your code insert them where required. now, of course if a malicious actor gains access to your environment, any and all methods suggested are compromised. so i'm assuming the purpose is to prevent someone from discovering your password if all they have is the contents of your script. P.S. if you compile your script to executable, that's the first barrier you can put against prying eyes. if those eyes belong to your over-the-average-curious end user, that should throw them off.
  3. thank you, had you posted this earlier you would have saved me a lot of work 🙂
  4. thank you @Musashi. that was indeed the case. i removed a few old screenshots from old forum posts. now i have ~4MB free... will use them for a good cause 🙂 @argumentum thank you for the reminder, i missed to upload the icon... update in first post. also, can i safely presume you do not have MS-Office installed? your screenshot shows an unexpected character for "New Puzzle" (2nd blue from the top, compare to my screenshot on the first post). this is because it uses the "Wingdings 3" font. the other characters use the "Webdings" or "Wingdings" fonts, shipped with Windows; however "Wingdings 2" and "Wingdings 3" fonts are shipped with other MS products, notably Office. you obviously do not have that font installed; hence i conclude i need to be more meticulous in my choice of fonts... and... that hell of a mess occasionally referred to as "DPI" came over for a visit. i scripted the app in a 150% DPI, just tested it on 100% and 125%, the results are horid. so i'll need to delve into that one as well...
  5. sorry about that, must've been a copy/paste issue. fixed. b.t.w. who are you calling "tiny"? 🙂 try a larger grid...
  6. AHH! just when i was beginning to think i understood something... 🙂
  7. Goal: select the squares to match every row and column results (screenshot below). you can change the puzzle type (addition or multiplication), grid size (3x3 to 9x9), and other preferences. Dependency: this app is also a showcase for the WinPose UDF (which was actually developed for it). Script: #Region wrapper directives #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=N #AutoIt3Wrapper_Compile_both=N #AutoIt3Wrapper_Icon=MagicMath.ico #AutoIt3Wrapper_UseUpx=N #AutoIt3Wrapper_Res_Description=Magic Math #AutoIt3Wrapper_Res_Fileversion=1.0.0.0 #AutoIt3Wrapper_Res_ProductVersion=1.0.0.0 #AutoIt3Wrapper_Res_LegalCopyright=Or Ben Shabat (or.ben.shabat@gmail.com) #AutoIt3Wrapper_Run_Au3Stripper=y #Au3Stripper_Parameters=/SO /RM #EndRegion wrapper directives #NoTrayIcon #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <ColorConstants.au3> #include <FontConstants.au3> #include <AutoItConstants.au3> #include <EditConstants.au3> #include <Math.au3> #include 'WinPose.au3' ; init ; - general Global Const $sAppName = 'Magic Math' ; - colors Global Const $iDefaultSqrSize = 45 Global Const $iDefaultColCount = 5 Global Const $iDefaultRowCount = 5 Global Const $iDefaultResizeSpeed = 50 Global Const $iColor_BoxText = $COLOR_BLACK Global Const $iColor_BoxTextError = $COLOR_RED Global Const $iColor_BoxUnchecked = $COLOR_LIGHTGRAY Global Const $iColor_BoxChecked = $COLOR_LIGHTGREEN Global Const $iColor_BoxEliminated = $COLOR_DARKGRAY Global Const $iColor_BoxResult = $COLOR_PEACHPUFF Global Const $iColor_MenuItem = $COLOR_DARKBLUE Global Const $iColor_MenuItemPressed = $COLOR_LIGHTGRAY Global Const $iColor_MenuItemEmphasis = $COLOR_WHITE Global Const $iColor_Vprimary = $COLOR_LIMEGREEN Global Const $iColor_Vsecondary = $COLOR_AQUA ; - symbols Global Const $symSetup = Chr(64) ; Webdings Global Const $symRenew = Chr(81) ; Wingdings 3 Global Const $symSolve = Chr(97) ; Webdings Global Const $symHelp = Chr(115) ; Webdings Global Const $symP = Chr(200) ; Wingdings 2 Global Const $symX = Chr(208) ; Wingdings 2 Global Const $symV = Chr(252) ; Wingdings ; declare variables Global $bPuzzleTypeIsAddition = True Global $iColCount = $iDefaultColCount, $iRowCount = $iDefaultRowCount, $iSqrSize = $iDefaultSqrSize, $iResizeSpeed = $iDefaultResizeSpeed Global $iGUI_Width, $iGUI_Height, $hGUI Global $aPos, $iWDiff, $iHDiff ; - main GUI Global $gMenu_New, $gMenu_Solve, $gMenu_Pref, $gMenu_Help, $gdGUIStart, $gdGUIEnd, $gdGridStart, $gdGridEnd Global Enum $iGrid_iValue, $iGrid_gID, $iGrid_bSelected, $iGrid_bChecked, $iGrid_bEliminated, $iGrid_iDimCount Global $aGrid[$iColCount][$iRowCount][$iGrid_iDimCount] Global Enum $iResult_iValue, $iResult_iDiff, $iResult_iDimCount Global $aResultOfRow[$iRowCount][$iResult_iDimCount] Global $aResultOfCol[$iColCount][$iResult_iDimCount] Global $gPuzzleType Global $bUserInputAllowed Global $bCheckForVictory ; - pref GUI Global $gPuzzleType_Addition, $gPuzzleType_Multiplication, _ $gGridWidth_Down, $gGridWidth_Data, $gGridWidth_Up, _ $gGridHeight_Down, $gGridHeight_Data, $gGridHeight_Up, _ $gSqrSize_Down, $gSqrSize_Data, $gSqrSize_Up, _ $gResizeSpeed_data, _ $gOK ; GUI $iGUI_Width = $iSqrSize * ($iColCount + 3) + 2 $iGUI_Height = $iSqrSize * ($iRowCount + 2) + 2 $hGUI = GUICreate($sAppName, $iGUI_Width, $iGUI_Height) $aPos = WinGetPos($hGUI) $iWDiff = $aPos[2] - $iGUI_Width $iHDiff = $aPos[3] - $iGUI_Height BuildGUI() GUISetState(@SW_SHOW, $hGUI) ; main loop Global $msg Global $aCursorInfo $bCheckForVictory = False While True $msg = GUIGetMsg() Switch $msg Case $gMenu_New GUICtrlSetBkColor($gMenu_New, $iColor_MenuItemPressed) Sleep(100) Renew() Sleep(100) GUICtrlSetBkColor($gMenu_New, $GUI_BKCOLOR_TRANSPARENT) Case $gMenu_Solve GUICtrlSetBkColor($gMenu_Solve, $iColor_MenuItemPressed) Sleep(100) Solve() Sleep(100) GUICtrlSetBkColor($gMenu_Solve, $GUI_BKCOLOR_TRANSPARENT) Case $gMenu_Pref GUICtrlSetBkColor($gMenu_Pref, $iColor_MenuItemPressed) Sleep(100) BuildGUI(Pref()) Sleep(100) GUICtrlSetBkColor($gMenu_Pref, $GUI_BKCOLOR_TRANSPARENT) Case $gMenu_Help GUICtrlSetBkColor($gMenu_Help, $iColor_MenuItemPressed) Sleep(100) BuildGUI(Help()) Sleep(100) GUICtrlSetBkColor($gMenu_Help, $GUI_BKCOLOR_TRANSPARENT) Case $gdGridStart To $gdGridEnd If $bUserInputAllowed Then For $iRow = 0 To $iRowCount - 1 For $iCol = 0 To $iColCount - 1 If $msg = $aGrid[$iCol][$iRow][$iGrid_gID] Then $aGrid[$iCol][$iRow][$iGrid_bEliminated] = False $aGrid[$iCol][$iRow][$iGrid_bChecked] = Not $aGrid[$iCol][$iRow][$iGrid_bChecked] GUICtrlSetBkColor($aGrid[$iCol][$iRow][$iGrid_gID], $aGrid[$iCol][$iRow][$iGrid_bChecked] ? $iColor_BoxChecked : $iColor_BoxUnchecked) EndIf Next Next $bCheckForVictory = True EndIf Case $GUI_EVENT_SECONDARYUP $aCursorInfo = GUIGetCursorInfo() If $aCursorInfo[4] > $gdGridStart And $aCursorInfo[4] < $gdGridEnd Then If $bUserInputAllowed Then For $iRow = 0 To $iRowCount - 1 For $iCol = 0 To $iColCount - 1 If $aCursorInfo[4] = $aGrid[$iCol][$iRow][$iGrid_gID] Then $aGrid[$iCol][$iRow][$iGrid_bChecked] = False $aGrid[$iCol][$iRow][$iGrid_bEliminated] = Not $aGrid[$iCol][$iRow][$iGrid_bEliminated] GUICtrlSetBkColor($aGrid[$iCol][$iRow][$iGrid_gID], $aGrid[$iCol][$iRow][$iGrid_bEliminated] ? $iColor_BoxEliminated : $iColor_BoxUnchecked) EndIf Next Next $bCheckForVictory = True EndIf EndIf Case $GUI_EVENT_CLOSE ExitLoop EndSwitch If $bCheckForVictory Then If IsVictoryAchieved() Then ShowVictory() GUICtrlSetBkColor($gMenu_New, $iColor_MenuItemEmphasis) Sleep(125) Renew() Sleep(125) GUICtrlSetBkColor($gMenu_New, $GUI_BKCOLOR_TRANSPARENT) EndIf $bCheckForVictory = False EndIf WEnd Func Renew($bNew = True) $bUserInputAllowed = True Local $bNoZeroResults GUISetState(@SW_LOCK) Do $bNoZeroResults = True For $iRow = 0 To $iRowCount - 1 For $iCol = 0 To $iColCount - 1 If $bNew Then $aGrid[$iCol][$iRow][$iGrid_iValue] = $bPuzzleTypeIsAddition ? Random(1, 9, 1) : Random(2, 9, 1) $aGrid[$iCol][$iRow][$iGrid_bSelected] = (Random() < 0.5) $aGrid[$iCol][$iRow][$iGrid_bChecked] = False $aGrid[$iCol][$iRow][$iGrid_bEliminated] = False EndIf GUICtrlSetData($aGrid[$iCol][$iRow][$iGrid_gID], $aGrid[$iCol][$iRow][$iGrid_iValue]) GUICtrlSetColor($aGrid[$iCol][$iRow][$iGrid_gID], $iColor_BoxText) Select Case $aGrid[$iCol][$iRow][$iGrid_bChecked] GUICtrlSetBkColor($aGrid[$iCol][$iRow][$iGrid_gID], $iColor_BoxChecked) Case $aGrid[$iCol][$iRow][$iGrid_bEliminated] GUICtrlSetBkColor($aGrid[$iCol][$iRow][$iGrid_gID], $iColor_BoxEliminated) Case Else GUICtrlSetBkColor($aGrid[$iCol][$iRow][$iGrid_gID], $iColor_BoxUnchecked) EndSelect GUICtrlSetCursor($aGrid[$iCol][$iRow][$iGrid_gID], $MCID_ARROW) Next Next Local $iResult For $iRow = 0 To $iRowCount - 1 $iResult = 0 For $iCol = 0 To $iColCount - 1 If $aGrid[$iCol][$iRow][$iGrid_bSelected] Then $iResult = Accumulate($iResult, $aGrid[$iCol][$iRow][$iGrid_iValue]) Next If $iResult = 0 Then $bNoZeroResults = False GUICtrlSetData($aResultOfRow[$iRow][$iResult_iValue], $iResult) GUICtrlSetFont($aResultOfRow[$iRow][$iResult_iValue], _Min($iSqrSize / 3, $iSqrSize / StringLen($iResult))) Next For $iCol = 0 To $iColCount - 1 $iResult = 0 For $iRow = 0 To $iRowCount - 1 If $aGrid[$iCol][$iRow][$iGrid_bSelected] Then $iResult = Accumulate($iResult, $aGrid[$iCol][$iRow][$iGrid_iValue]) Next If $iResult = 0 Then $bNoZeroResults = False GUICtrlSetData($aResultOfCol[$iCol][$iResult_iValue], $iResult) GUICtrlSetFont($aResultOfCol[$iCol][$iResult_iValue], _Min($iSqrSize / 3, $iSqrSize / StringLen($iResult))) Next Until $bNoZeroResults GUISetState(@SW_UNLOCK) EndFunc ;==>Renew Func Accumulate(ByRef $iBase, $iDelta) If $iBase = 0 Then Return $iDelta If $bPuzzleTypeIsAddition Then Return $iBase + $iDelta Else Return $iBase * $iDelta EndIf EndFunc ;==>Accumulate Func Solve() $bUserInputAllowed = False For $iRow = 0 To $iRowCount - 1 For $iCol = 0 To $iColCount - 1 GUICtrlSetBkColor($aGrid[$iCol][$iRow][$iGrid_gID], $aGrid[$iCol][$iRow][$iGrid_bSelected] ? $iColor_BoxChecked : $iColor_BoxEliminated) If $aGrid[$iCol][$iRow][$iGrid_bSelected] <> $aGrid[$iCol][$iRow][$iGrid_bChecked] Then GUICtrlSetColor($aGrid[$iCol][$iRow][$iGrid_gID], $iColor_BoxTextError) GUICtrlSetCursor($aGrid[$iCol][$iRow][$iGrid_gID], $MCID_NO) Next Next EndFunc ;==>Solve Func IsVictoryAchieved() Local $iResult For $iRow = 0 To $iRowCount - 1 $iResult = 0 For $iCol = 0 To $iColCount - 1 If $aGrid[$iCol][$iRow][$iGrid_bChecked] Then $iResult = Accumulate($iResult, $aGrid[$iCol][$iRow][$iGrid_iValue]) Next If GUICtrlRead($aResultOfRow[$iRow][$iResult_iValue]) <> $iResult Then Return False Next For $iCol = 0 To $iColCount - 1 $iResult = 0 For $iRow = 0 To $iRowCount - 1 If $aGrid[$iCol][$iRow][$iGrid_bChecked] Then $iResult = Accumulate($iResult, $aGrid[$iCol][$iRow][$iGrid_iValue]) Next If GUICtrlRead($aResultOfCol[$iCol][$iResult_iValue]) <> $iResult Then Return False Next Return True EndFunc ;==>IsVictoryAchieved Func ShowVictory() Sleep(150) Local $gV = GUICtrlCreateLabel($symV, 0, 0, $iGUI_Width, $iGUI_Height, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont($gV, _Min($iGUI_Height, $iGUI_Width) * 0.6, Default, Default, 'Wingdings') GUICtrlSetBkColor($gV, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetColor($gV, $iColor_Vprimary) For $i = 1 To 2 Sleep(125) GUICtrlSetColor($gV, $iColor_Vsecondary) Sleep(125) GUICtrlSetColor($gV, $iColor_Vprimary) Next Sleep(1000) GUICtrlDelete($gV) Sleep(250) EndFunc ;==>ShowVictory Func BuildGUI($bNew = True) GUISetFont($iSqrSize / 3, Default, Default, 'Tahoma') ; GUI contents $gdGUIStart = GUICtrlCreateDummy() ; - menu $gMenu_Pref = GUICtrlCreateLabel($symSetup, 1, 1 + $iSqrSize / 2, $iSqrSize * 1.5 - 2, $iSqrSize - 2, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetTip(-1, 'Set your preferences and construct a new puzzle', 'Setup') GUICtrlSetFont(-1, $iSqrSize / 2, Default, Default, 'Webdings') GUICtrlSetColor(-1, $iColor_MenuItem) GUICtrlSetCursor(-1, $MCID_HAND) $gMenu_New = GUICtrlCreateLabel($symRenew, 1, $iSqrSize + 1 + $iSqrSize / 2, $iSqrSize * 1.5 - 2, $iSqrSize - 2, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetTip(-1, 'Construct a new puzzle using current preferences', 'New Puzzle') GUICtrlSetFont(-1, $iSqrSize / 2, Default, Default, 'Wingdings 3') GUICtrlSetColor(-1, $iColor_MenuItem) GUICtrlSetCursor(-1, $MCID_HAND) $gMenu_Solve = GUICtrlCreateLabel($symV, 1, $iSqrSize * 2 + 1 + $iSqrSize / 2, $iSqrSize * 1.5 - 2, $iSqrSize - 2, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetTip(-1, 'I give up :(', 'Show Solution') GUICtrlSetFont(-1, $iSqrSize / 2, Default, Default, 'Wingdings') GUICtrlSetColor(-1, $iColor_MenuItem) GUICtrlSetCursor(-1, $MCID_HAND) $gMenu_Help = GUICtrlCreateLabel($symHelp, 1, $iSqrSize * 3 + 1 + $iSqrSize / 2, $iSqrSize * 1.5 - 2, $iSqrSize - 2, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetTip(-1, 'What do I do here?', 'Instructions') GUICtrlSetFont(-1, $iSqrSize / 2, Default, Default, 'Webdings') GUICtrlSetColor(-1, $iColor_MenuItem) GUICtrlSetCursor(-1, $MCID_HAND) ; - grid ; -- center part ReDim $aGrid[$iColCount][$iRowCount][$iGrid_iDimCount] $gdGridStart = GUICtrlCreateDummy() For $iRow = 0 To $iRowCount - 1 For $iCol = 0 To $iColCount - 1 $aGrid[$iCol][$iRow][$iGrid_gID] = GUICtrlCreateLabel('', ($iCol + 1) * $iSqrSize + 2 + $iSqrSize / 2, $iRow * $iSqrSize + 2 + $iSqrSize / 2, $iSqrSize - 2, $iSqrSize - 2, BitOR($SS_CENTER, $SS_CENTERIMAGE)) Next Next $gdGridEnd = GUICtrlCreateDummy() ; -- results of rows ReDim $aResultOfRow[$iRowCount][$iResult_iDimCount] For $iRow = 0 To $iRowCount - 1 $aResultOfRow[$iRow][$iResult_iValue] = GUICtrlCreateLabel('', ($iColCount + 1) * $iSqrSize + 2 + $iSqrSize / 2, $iRow * $iSqrSize + 2 + $iSqrSize / 2, $iSqrSize - 2, $iSqrSize - 2, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetBkColor(-1, $iColor_BoxResult) Next ; -- results of cols ReDim $aResultOfCol[$iColCount][$iResult_iDimCount] For $iCol = 0 To $iColCount - 1 $aResultOfCol[$iCol][$iResult_iValue] = GUICtrlCreateLabel('', ($iCol + 1) * $iSqrSize + 2 + $iSqrSize / 2, $iRowCount * $iSqrSize + 2 + $iSqrSize / 2, $iSqrSize - 2, $iSqrSize - 2, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetBkColor(-1, $iColor_BoxResult) Next ; -- puzzle type GUICtrlCreateLabel($bPuzzleTypeIsAddition ? $symP : $symX, ($iColCount + 1) * $iSqrSize + 2 + $iSqrSize / 2, $iRowCount * $iSqrSize + 2 + $iSqrSize / 2, $iSqrSize - 2, $iSqrSize - 2, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, Default, Default, Default, 'Wingdings 2') GUICtrlSetBkColor(-1, $iColor_MenuItemEmphasis) GUICtrlSetTip(-1, ($bPuzzleTypeIsAddition ? 'Addition' : 'Multplication'), 'Puzzle Type:') ; - populate grid Renew($bNew) ; finalize GUI $gdGUIEnd = GUICtrlCreateDummy() EndFunc ;==>BuildGUI Func Pref() Local Const $iSUI_W = 200, $iSUI_H = 280, $iSUI_ButtonH = 30, $iSUI_ButtonSpacing = 10 GUISetFont(9.5, Default, Default, 'Tahoma') Local $x = 10, $y = 10, $dy = 25 ; delete all controls DeleteAllControls() ; resize GUI WinSetTrans($hGUI, '', 192) WinSetTitle($hGUI, '', $sAppName & ' Setup') _WinPoseAroundCenter($hGUI, $iSUI_W + $iWDiff, $iSUI_H + $iHDiff, $iResizeSpeed) WinSetTrans($hGUI, '', 255) ; generate controls $gdGUIStart = GUICtrlCreateDummy() GUICtrlCreateLabel('Puzzle', $x, $y, 85, Default, $SS_CENTERIMAGE) GUICtrlSetFont(-1, Default, 600) $x += 5 $y += $dy GUICtrlCreateLabel('Puzzle Type:', $x, $y, 80, Default, $SS_CENTERIMAGE) $x += 90 $gPuzzleType_Addition = GUICtrlCreateLabel($symP, $x, $y, 41, 22, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, 12, Default, Default, 'Wingdings 2') $x += 42 $gPuzzleType_Multiplication = GUICtrlCreateLabel($symX, $x, $y, 41, 22, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, 12, Default, Default, 'Wingdings 2') Pref_RefreshPuzzleTypeButtons($gPuzzleType_Addition, $gPuzzleType_Multiplication) $x -= 42 $x -= 90 $y += $dy GUICtrlCreateLabel('Columns:', $x, $y, 80, Default, $SS_CENTERIMAGE) $x += 90 $gGridWidth_Down = GUICtrlCreateLabel('-', $x, $y, 23, 22, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, 13, 800) GUICtrlSetBkColor(-1, $COLOR_LIGHTGRAY) GUICtrlSetCursor(-1, $MCID_HAND) $x += 25 $gGridWidth_Data = GUICtrlCreateLabel($iColCount, $x, $y, 33, 22, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetBkColor(-1, $COLOR_LIGHTBLUE) $x += 35 $gGridWidth_Up = GUICtrlCreateLabel('+', $x, $y, 23, 22, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, 13, 800) GUICtrlSetBkColor(-1, $COLOR_LIGHTGRAY) GUICtrlSetCursor(-1, $MCID_HAND) $x -= 35 $x -= 25 $x -= 90 $y += $dy GUICtrlCreateLabel('Rows:', $x, $y, Default, Default, $SS_CENTERIMAGE) $x += 90 $gGridHeight_Down = GUICtrlCreateLabel('-', $x, $y, 23, 22, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, 13, 800) GUICtrlSetBkColor(-1, $COLOR_LIGHTGRAY) GUICtrlSetCursor(-1, $MCID_HAND) $x += 25 $gGridHeight_Data = GUICtrlCreateLabel($iRowCount, $x, $y, 33, 22, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetBkColor(-1, $COLOR_LIGHTBLUE) $x += 35 $gGridHeight_Up = GUICtrlCreateLabel('+', $x, $y, 23, 22, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, 13, 800) GUICtrlSetBkColor(-1, $COLOR_LIGHTGRAY) GUICtrlSetCursor(-1, $MCID_HAND) $x -= 35 $x -= 25 $x -= 90 $y += $dy $x -= 5 $y += $dy GUICtrlCreateLabel('Appearance', $x, $y, 85, Default, $SS_CENTERIMAGE) GUICtrlSetFont(-1, Default, 600) $y += $dy $x += 5 GUICtrlCreateLabel('Square Size:', $x, $y, Default, Default, $SS_CENTERIMAGE) $x += 90 $gSqrSize_Down = GUICtrlCreateLabel('-', $x, $y, 23, 22, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, 13, 800) GUICtrlSetBkColor(-1, $COLOR_LIGHTGRAY) GUICtrlSetCursor(-1, $MCID_HAND) $x += 25 $gSqrSize_Data = GUICtrlCreateLabel($iSqrSize, $x, $y, 33, 22, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetBkColor(-1, $COLOR_LIGHTBLUE) $x += 35 $gSqrSize_Up = GUICtrlCreateLabel('+', $x, $y, 23, 22, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetFont(-1, 13, 800) GUICtrlSetBkColor(-1, $COLOR_LIGHTGRAY) GUICtrlSetCursor(-1, $MCID_HAND) $x -= 35 $x -= 25 $x -= 90 $y += $dy GUICtrlCreateLabel('Resize speed:', $x, $y, Default, Default, $SS_CENTERIMAGE) $x += 90 $gResizeSpeed_data = GUICtrlCreateSlider($x, $y, 80) GUICtrlSetLimit(-1, 100) GUICtrlSetData(-1, $iResizeSpeed) $x -= 90 #cs FUTURE DEVELOPMENT ----- BUILD PHASE: allow zero sum/prod use 8 & 9 in multiplication puzzle (HARDER) increase/decrease target squares count (determine probability of a square to participate) allow negative numbers (HARDER) ----- GAME PHASE: show target squares count show current/target squares count allow marking cols & rows as balanced automatically mark cols & rows as balanced automatically mark invalid selection (div creating mod, sum/prod exceeding result) show diff calc allow hints allow real-time switch puzzle type #ce Local $gOK = GUICtrlCreateButton('Done', $iSUI_ButtonSpacing, $iSUI_H - $iSUI_ButtonH - $iSUI_ButtonSpacing, $iSUI_W - $iSUI_ButtonSpacing * 2, $iSUI_ButtonH) $gdGUIEnd = GUICtrlCreateDummy() ; user interaction While True $msg = GUIGetMsg() Switch $msg Case $gPuzzleType_Addition If Not $bPuzzleTypeIsAddition Then $bPuzzleTypeIsAddition = True Pref_RefreshPuzzleTypeButtons($gPuzzleType_Addition, $gPuzzleType_Multiplication) EndIf Case $gPuzzleType_Multiplication If $bPuzzleTypeIsAddition Then $bPuzzleTypeIsAddition = False Pref_RefreshPuzzleTypeButtons($gPuzzleType_Addition, $gPuzzleType_Multiplication) EndIf Case $gGridWidth_Up $iColCount = _Min($iColCount + 1, 9) GUICtrlSetData($gGridWidth_Data, $iColCount) Case $gGridWidth_Down $iColCount = _Max($iColCount - 1, 3) GUICtrlSetData($gGridWidth_Data, $iColCount) Case $gGridHeight_Up $iRowCount = _Min($iRowCount + 1, 9) GUICtrlSetData($gGridHeight_Data, $iRowCount) Case $gGridHeight_Down $iRowCount = _Max($iRowCount - 1, 3) GUICtrlSetData($gGridHeight_Data, $iRowCount) Case $gSqrSize_Up $iSqrSize = _Min($iSqrSize + 5, 60) GUICtrlSetData($gSqrSize_Data, $iSqrSize) Case $gSqrSize_Down $iSqrSize = _Max($iSqrSize - 5, 20) GUICtrlSetData($gSqrSize_Data, $iSqrSize) Case $gOK, $GUI_EVENT_CLOSE $iResizeSpeed = GUICtrlRead($gResizeSpeed_data) ExitLoop EndSwitch WEnd ; delete all controls DeleteAllControls() ; - resize GUI WinSetTrans($hGUI, '', 192) WinSetTitle($hGUI, '', $sAppName) $iGUI_Width = $iSqrSize * ($iColCount + 3) + 2 $iGUI_Height = $iSqrSize * ($iRowCount + 2) + 2 _WinPoseAroundCenter($hGUI, $iGUI_Width + $iWDiff, $iGUI_Height + $iHDiff, $iResizeSpeed) WinSetTrans($hGUI, '', 255) Return True EndFunc ;==>Pref Func Pref_RefreshPuzzleTypeButtons($gPuzzleType_Addition, $gPuzzleType_Multiplication) GUICtrlSetBkColor($gPuzzleType_Addition, $bPuzzleTypeIsAddition ? $COLOR_LIGHTBLUE : $COLOR_LIGHTGRAY) GUICtrlSetCursor($gPuzzleType_Addition, $bPuzzleTypeIsAddition ? $MCID_ARROW : $MCID_HAND) GUICtrlSetBkColor($gPuzzleType_Multiplication, $bPuzzleTypeIsAddition ? $COLOR_LIGHTGRAY : $COLOR_LIGHTBLUE) GUICtrlSetCursor($gPuzzleType_Multiplication, $bPuzzleTypeIsAddition ? $MCID_HAND : $MCID_ARROW) EndFunc ;==>Pref_RefreshPuzzleTypeButtons Func Help() Local Const $iSUI_W = 410, $iSUI_H = 350, $iSUI_ButtonH = 30, $iSUI_ButtonSpacing = 10 GUISetFont(9.5, Default, Default, 'Tahoma') Local $x = 15, $y = 10, $dy = 25 ; delete all controls DeleteAllControls() ; resize GUI WinSetTrans($hGUI, '', 192) WinSetTitle($hGUI, '', $sAppName & ' Instructions') _WinPoseAroundCenter($hGUI, $iSUI_W + $iWDiff, $iSUI_H + $iHDiff, $iResizeSpeed) WinSetTrans($hGUI, '', 255) ; generate controls $gdGUIStart = GUICtrlCreateDummy() GUICtrlCreateLabel('WARNING! This game may be highly addictive :-)' & @CRLF & @CRLF & _ 'Click the gray squares in the middle to select them and paint them green. The selected squares in every row must match the result of the row, displayed on the right-hand side; the selected squares in every column must match the result of the column, displayed at the bottom.' & @CRLF & @CRLF & _ 'If you eliminate a square, you may right-click it to paint it dark gray.' & @CRLF & @CRLF & _ 'The type of the puzzle - Addition or Multiplication - is indicated in the white square at the bottom-right corner.' & @CRLF & @CRLF & _ 'Click the "Tools" icon on the upper-left corner to change puzzle type, grid size and other preferences.' & @CRLF & @CRLF & _ 'Enjoy :-)', $x, $y, $iSUI_W - $x * 2, $iSUI_H - 60) $y += $dy $gOK = GUICtrlCreateButton('OK, I think I got it...', $iSUI_ButtonSpacing, $iSUI_H - $iSUI_ButtonH - $iSUI_ButtonSpacing, $iSUI_W - $iSUI_ButtonSpacing * 2, $iSUI_ButtonH) $gdGUIEnd = GUICtrlCreateDummy() ; user interaction While True $msg = GUIGetMsg() Switch $msg Case $gOK, $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd ; delete all controls DeleteAllControls() ; resize GUI WinSetTrans($hGUI, '', 192) WinSetTitle($hGUI, '', $sAppName) _WinPoseAroundCenter($hGUI, $iGUI_Width + $iWDiff, $iGUI_Height + $iHDiff, $iResizeSpeed) WinSetTrans($hGUI, '', 255) Return False EndFunc ;==>Help Func GuiCtrlDeleteAndZero(ByRef $gID) If GUICtrlDelete($gID) Then $gID = 0 Return 1 Else Return 0 EndIf EndFunc ;==>GuiCtrlDeleteAndZero Func DeleteAllControls() Local $gIDStart = $gdGUIStart Local $gIDEnd = $gdGUIEnd For $gID = $gIDStart To $gIDEnd GuiCtrlDeleteAndZero($gID) Next EndFunc ;==>DeleteAllControls Func _WinPoseAroundCenter($hGUI, $iNewWidth, $iNewHeight, $iSpeed = 0) Local $aPos = WinGetPos($hGUI) Local $x = $aPos[0] + $aPos[2] / 2 - $iNewWidth / 2 If $x < 0 Then $x = 0 If $x + $iNewWidth > @DesktopWidth Then $x = @DesktopWidth - $iNewWidth Local $y = $aPos[1] + $aPos[3] / 2 - $iNewHeight / 2 If $y < 0 Then $y = 0 If $y + $iNewHeight > @DesktopHeight Then $y = @DesktopHeight - $iNewHeight _WinPose($hGUI, '', $x, $y, $iNewWidth, $iNewHeight, $iSpeed) EndFunc ;==>_WinPoseAroundCenter enjoy! MagicMath.ico
  8. capturing WM_SIZE an redraw upon resize is an interesting approach. thank you both! i'll keep fiddling with this.
  9. Brief: native WinMove() has a "speed" parameter for a more fluent movement. unfortunately, that applies to the change in position, but not the change in size. the position changes in the specified "speed", but size changes abruptly. _WinPose() is similar to WinMove(), except that move and resize are simultaneous, both conform to the speed parameter. UDF: (save as "WinPose.au3") #include-once #include <WinAPISysWin.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _WinPose ; Description ...: same as native WinMove(), except that move and resize are simultaneous, both conform to the speed parameter. ; Syntax ........: _WinPose($hWnd, $sText, $x, $y, $w, $h[, $speed = 0]) ; Parameters ....: $hWnd - the title/hWnd/class of the window to pose. ; $sText - the text of the window to pose. ; $x - X coordinate to move to. ; $y - Y coordinate to move to. ; $w - [optional] new width of the window. ; $h - [optional] new height of the window. ; $speed - [optional] the speed to pose the window (smaller value = faster speed, 0 = instantaneous). ; Return values .: Success - a handle to the window. ; Failure - 0 if the window is not found (also sets @error to non-zero). ; Author ........: orbs ; Modified ......: ; Remarks .......: parameters and return values are practically identical to those of the native WinMove() function. ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _WinPose($hWnd, $sText, $x, $y, $w = Default, $h = Default, $speed = 0) ; find the window to move If Not IsHWnd($hWnd) Then $hWnd = WinGetHandle($hWnd, $sText) If @error Then Return SetError(1, 0, False) EndIf Local $aPos = WinGetPos($hWnd) If @error Then Return SetError(2, 0, False) ; initialize variables Local Enum $pos_x, $pos_y, $pos_w, $pos_h Local Enum $aiCurrent, $aiTarget, $aiDelta, $aiRatio Local $aPosTarget[4][4] = [[$aPos[$pos_x], $x, 0, 0], [$aPos[$pos_y], $y, 0, 0], [$aPos[$pos_w], $w, 0, 0], [$aPos[$pos_h], $h, 0, 0]] ; accomodate for Default keyword For $iElement = 0 To 3 If $aPosTarget[$iElement][$aiTarget] = Default Then $aPosTarget[$iElement][$aiTarget] = $aPos[$iElement] Next ; calculate delta For $iElement = 0 To 3 $aPosTarget[$iElement][$aiDelta] = $aPosTarget[$iElement][$aiTarget] - $aPosTarget[$iElement][$aiCurrent] Next ; find the maximum delta Local $iMaxElement = 0, $iMaxDelta = 0 For $iElement = 0 To 3 If Abs($aPosTarget[$iElement][$aiDelta]) > $iMaxDelta Then $iMaxElement = $iElement $iMaxDelta = $aPosTarget[$iElement][$aiDelta] EndIf Next ; accomodate for negative delta If ($aPosTarget[$iMaxElement][$aiTarget] - $aPos[$iMaxElement]) < 0 Then $iMaxDelta = -$iMaxDelta ; calculate ratio for all elements For $iElement = 0 To 3 $aPosTarget[$iElement][$aiRatio] = $aPosTarget[$iElement][$aiDelta] / $iMaxDelta Next ; move & resize the window gradually For $iStep = 0 To $iMaxDelta For $iElement = 0 To 3 $aPosTarget[$iElement][$aiCurrent] += $aPosTarget[$iElement][$aiRatio] Next For $i = 1 To $speed _WinAPI_MoveWindow($hWnd, _ $aPosTarget[$pos_x][$aiCurrent], _ $aPosTarget[$pos_y][$aiCurrent], _ $aPosTarget[$pos_w][$aiCurrent], _ $aPosTarget[$pos_h][$aiCurrent], False) Next Next ; validate final outcome is as expected Return WinMove($hWnd, '', $x, $y, $w, $h) EndFunc ;==>_WinPose Example: #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <AutoItConstants.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include 'WinPose.au3' Global Const $iMinW = 250, $iMinH = 100 Global $x, $y, $w, $h, $speed Global $hGUI = GUICreate('_WinPose() Example', $iMinW, $iMinH) Global $gButton = GUICtrlCreateButton('Click Me!', 25, 25, 200, 50) GUICtrlSetResizing(-1, $GUI_DOCKBORDERS) GUISetState(@SW_SHOW) Global $msg While True $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case $gButton $w = Random($iMinW, @DesktopWidth / 3, 1) $h = Random($iMinH, @DesktopHeight / 3, 1) $x = Random(0, @DesktopWidth - $w, 1) $y = Random(0, @DesktopHeight - $h, 1) $speed = Random(10, 100, 1) _WinPose($hGUI, '', $x, $y, $w, $h, $speed) EndSwitch WEnd click the button to pose the window in a new random position and size, in a random speed. enjoy 🙂
  10. so you are using a pic control instead of a label? functionality-wise that's fine. how do i set the background color of the text? the only reference to colors in the entire process seems to be in this line: Local $hBrush = _GDIPlus_LineBrushCreateFromRect($tRECTF, $iStartColor, $iEndColor, $iGradientMode) which refers to the gradient color edges. another thing, in a resizable GUI (add the style $WS_OVERLAPPEDWINDOW), when i resize the window, there's a weird effect: in the example by @Nine the text disappears. in the example by @UEZ the text stretches vertically to twice its size. various docking options apply, but still the text is distorted.
  11. so the thing is that the line GUISetState() should be after the creation of the label! interesting, i never noticed it made any difference... thank you. i'll keep studying this.
  12. so i created a label, got its handle, and tried to use it, but nothing is displayed: ; From Nine #include <GDIPlus.au3> #include <GUIConstants.au3> #include <ColorConstants.au3> Opt("MustDeclareVars", True) Example() Func Example() _GDIPlus_Startup() Local $hGUI = GUICreate("Example", 420, 420) GUISetState() ; create a label and use it instead of the entire GUI Local $gLabel = GUICtrlCreateLabel('', 10, 10, 400, 400) Local $hLabel = GUICtrlGetHandle($gLabel) Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hLabel) _GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF) Local $hBrush = _GDIPlus_LineBrushCreate(50, 200, 320, 200, 0xFF000000, 0xFFFFFFFF) Local $hFormat = _GDIPlus_StringFormatCreate() Local $hFamily = _GDIPlus_FontFamilyCreate("Arial") Local $hFont = _GDIPlus_FontCreate($hFamily, 28, 2) Local $tLayout = _GDIPlus_RectFCreate(80, 100, 320, 40) Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, "AutoIt Rulez !", $hFont, $tLayout, $hFormat) _GDIPlus_GraphicsDrawStringEx($hGraphic, "AutoIt Rulez !", $hFont, $aInfo[0], $hFormat, $hBrush) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_FontDispose($hFont) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() EndFunc ;==>Example am i missing something obvious here? _GDIPlus_GraphicsCreateFromHWND($hLabel) returns a valid handle, no @error.
  13. ok, so how do i make it more label-like? meaning, for start, can i specify coordinates and size, rather than let it occupy the entire GUI? also, does it have a control id? can i make it clickable, resizeable, transparent background, etc?
  14. thank you, that looks nice! i'm now trying to understand the process. is that a "graphic" control that occupies the entire GUI? i'm asking because if i try to set a background color to the GUI, it does not show: GUISetBkColor($COLOR_YELLOW) ; ^^ not visible. the graphic object takes up the entire GUI?
  15. the number 0 equals the boolean False any other number equals the boolean True so: 2 = True 3 = True (2 Or 3) = (True or True) = True so the condition is always met.
×
×
  • Create New...