Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 06/05/2018 in all areas

  1. Hello Earthshine - CDs are still used a lot in medical imaging for patients to bring their radiology exams to their doctors or hospital visits. I write a lot of code manipulating medical image data and I recently was working on a better method for importing CD data into our server repositories. I'm looking to be able to recover from scenarios where we can only read part of the CDs because some of the data is bad. I had considered writing and compiling a bit of code to just start the copy attempt and then I could monitor my own copy process to see if it has froze and then I could ProcessClose it, flag it as an error and move on to the next one. I was just hoping for a way to do it all in one script.
    1 point
  2. The console seems to be telling you what is wrong (last line). Can you open www.google.de manually in firefox?
    1 point
  3. We use FlexLM. It is possible that I could go "under the hood" to find the states, but I am trying to test it through the UI, as a user would. For example, our software has numerous APIs that can be called programmatically to do things that the software does. Like draw a box, for example. But this only tests the API, not the UI. I want to test the software by simulating users actually poking buttons in the UI. As an analogy, in the old days you could reach under the hood of your car and actuate the throttle linkage and rev the engine. You can also, of course, sit in the driver's seat and push the gas pedal to rev the engine. One is not an adequate test of the other. Just because I can rev the engine under the hood does not mean that the gas pedal works like it is supposed to. I'm trying to get through the actual user interface, not bypass it. This is why I am looking to UI automation solutions rather than just writing programs that access our internal APIs. Not to mention I think it will be easier. Steve
    1 point
  4. And you don't think that, instead, working with the vendor to resolve the issue of why applying the license file isn't making the right features available would be a better idea? AutoIt is great at doing almost anything you want to automate; just seems like you're trying to automate a way around not fixing the underlying issue.
    1 point
  5. ShellExecute("path\filename.exe") Run("path\filename.exe") Either of these functions can launch an exe from AutoIt. After typing the function, hover over function name and press F1 to bring up the help file containing additional parameter information.
    1 point
  6. Melba23

    Variables & Arrays

    pixelsearch, I do not "master" the Help file - it is the work of many people. But I will take a look and see how empty arrays might be mentioned. If you want a new feature to be added to AutoIt, then open a "Feature Request" in Trac (use the <Bug Tracker> link in the menu at the top of the page to access it. But you will need to provide a very good case as to why this feature needs to be added - development time is limited. We will have to agree to differ about arrays starting at 0/1 - I am so used to having a [0] element that I hardly notice, besides I often keep a count in there as is the case with so many arrays returned by AutoIt functions. M23
    1 point
  7. Melba23

    Updating a List View

    GPinzone, Sounds a very sensible solution. M23
    1 point
  8. I got it to work. Heres the code if someone needs it. Relevant Function Func _IsWindowOnCurrentVirtualDesktop($hWnd) $CLSID = "{aa509086-5ca9-4c25-8f95-589d3c07b48a}" $IID = "{a5cd92ff-29be-454c-8d04-d82879fb3f1b}" $TAG = "IsWindowOnCurrentVirtualDesktop hresult(hwnd;ptr*);" $IVirtualDesktopManager = ObjCreateInterface($CLSID, $IID, $TAG) $Result = False $IVirtualDesktopManager.IsWindowOnCurrentVirtualDesktop($hWnd, $Result) $IVirtualDesktopManager = 0 Return $Result EndFunc Entire Program #requireadmin #include <WinAPI.au3> #include <WinAPIProc.au3> #include <ProcessConstants.au3> $Process = ProcessList("processname.exe") For $i = 1 To $Process[0][0] $pid = $Process[$i][1] $handle = _WinAPI_OpenProcess($PROCESS_QUERY_INFORMATION+$PROCESS_SET_INFORMATION, False, $pid) $hWnd = _GetWindowHandleFromPid($pid) ProcessSetPriority ($pid, 0 ) ;set cpu priority _WinAPI_SetProcessAffinityMask($handle, 0x08) ;set cpu affinity ;msgbox(0,"",$Process[$i][0] & " " & $Process[$i][1] & " " & $handle & " " & $hWnd ) ;debug ;msgbox(0, "", _IsWindowOnCurrentVirtualDesktop($hWnd)) ;debug Next Func _IsWindowOnCurrentVirtualDesktop($hWnd) $CLSID = "{aa509086-5ca9-4c25-8f95-589d3c07b48a}" $IID = "{a5cd92ff-29be-454c-8d04-d82879fb3f1b}" $TAG = "IsWindowOnCurrentVirtualDesktop hresult(hwnd;ptr*);" $IVirtualDesktopManager = ObjCreateInterface($CLSID, $IID, $TAG) $Result = False $IVirtualDesktopManager.IsWindowOnCurrentVirtualDesktop($hWnd, $Result) $IVirtualDesktopManager = 0 Return $Result EndFunc Func _GetWindowHandleFromPid($pid) Local $aData = _WinAPI_EnumProcessWindows($pid) Return $aData[1][0] EndFunc ;~ 0x01 CPU1 binary to hex conversion reference chart with 1s for active cores and 0s for disabled ;~ 0x02 CPU2 ;~ 0x03 CPU1+2 ;~ 0x04 CPU3 ;~ 0x05 CPU1+3 ;~ 0x06 CPU2+3 ;~ 0x07 CPU1+2+3 ;~ 0x08 CPU4 ;~ 0x09 CPU1+4 ;~ 0x0A CPU2+4 ;~ 0x0B CPU1+2+4 ;~ 0x0C CPU3+4 ;~ 0x0E CPU1+3+4 ;~ 0x0F CPU1+2+3+4
    1 point
  9. attached below. ZLIB.zip
    1 point
  10. dragan

    Dice and Cards replacer

    Several nights ago, few friends of mine and me, wanted to play a board game, but we had no dices and had no cards, so I made one app in few sec. that simulates throwing dices and drawing cards. Today I decided to make more complete app for same purpose, and I came up with this script. I also didn't mention that app will store drawn cards into memory array, so it won't draw same card again (if you have only 1 deck, and if you have 2 decks it won't draw 2 of the same card) until all cards are selected, then the array resets and you have all the cards again. And if you have cards selected (to save for next drawing), and you reach the end of the deck, selected cards will be stored into memory automatically after deck is being reset. Reason for edit: added image to the post edit No.2 - v1.0.0.1: added low quality animations to it edit No.3 - v1.0.0.2: changed _GenerateRandomNumbers() functions, help from LaCastiglione, and changed "Poker" into "Sevens" tnx to nitekram edit No.4 - v1.0.0.3: added ability to select cards/dice you want to save for next throwing/drawing, all graphics are made using GDI+, also will calculate mid-color for cards (black vs red) and set label in that color. After decks number gets changed, all decks are being mixed automatically (to reset cards on the table). #NoTrayIcon #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #Include <GuiComboBox.au3> #include <GDIPlus.au3> Opt("GUICloseOnESC", 0) HotKeySet('{F9}', '_ThrowDices') HotKeySet('{F10}', '_DrawCards') Global $Title = 'Dice&Card Games Assistant' Global $version = '1.0.0.3' Global $width = 500, $height = 425 $Title &= ' - v' & $version Global $IniFile = @ScriptDir & '\config.ini' Global $DicesOn = False, $CardsOn = False Global $MouseState = 1, $LastHoveredDice = 0, $lasthoveredCard = 0 Global $CardsOverLap = False If NOT FileExists($IniFile) Then IniWrite($IniFile, 'Dices', 'Number', 7) IniWrite($IniFile, 'Cards', 'Number', 5) IniWrite($IniFile, 'Cards', 'Deck', 1) IniWrite($IniFile, 'Cards', 'DeckNumber', 1) IniWrite($IniFile, 'Options', 'Sound', 3) IniWrite($IniFile, 'Options', 'Animate', 3) EndIf Dim $CardsArray[1][5] _Form_Cards_Array($CardsArray, IniRead($IniFile, 'Cards', 'Deck', 1)) Dim $LastCards[1][8] Dim $LastDices[1][5] $Form1 = GUICreate($Title, $width, $height) GUISetBkColor(0xEEEEEE) GUICtrlCreateGroup('Dices', 5, 5, $width-10, 140) GUICtrlCreateLabel('Number of dices:', 20, 25, 85, 17) $DiceNumber = GUICtrlCreateInput(IniRead($IniFile, 'Dices', 'Number', '7'), 105, 25-3, 45, 20, BitOR($ES_CENTER, $ES_NUMBER)) GUICtrlCreateUpdown(-1) $ThrowDices = GUICtrlCreateButton('Throw dices [ hotkey = F9 ]', 160, 25-6, $width-35-180-50, 25) $DicesThrownLabel = GUICtrlCreateLabel('Thrown dice(s): /', 10, 123, $width-20, 17, $ES_CENTER) GUICtrlSetFont(-1, 10, 400, -1, 'Segoe UI') $clear_dice_button = GUICtrlCreateButton('Clear selection', 180+($width-35-180-70)+10, 25-6, 80, 25) GUICtrlCreateGroup("", -99, -99, 1, 1) $CardSetHeight = 145 GUICtrlCreateGroup('Cards', 5, $CardSetHeight+5, $width-10, 230) GUICtrlCreateLabel('Number of cards to draw:', 20, 25+$CardSetHeight, 85+40, 17) $CardsNumber = GUICtrlCreateInput(IniRead($IniFile, 'Cards', 'Number', '5'), 105+40, 25-3+$CardSetHeight, 45, 20, BitOR($ES_CENTER, $ES_NUMBER)) GUICtrlCreateUpdown(-1) GUICtrlCreateLabel('Deck type:', 145+45+20, 25+$CardSetHeight, 60, 17) $DeckType = GUICtrlCreateCombo('', 210+55, 25-3+$CardSetHeight, 100, -1, $CBS_DROPDOWNLIST) GUICtrlSetData(-1, 'Bridge - 2 to A|Sevens - 7 to A') _GUICtrlComboBox_SetCurSel($DeckType, IniRead($IniFile, 'Cards', 'Deck', '1')) GUICtrlCreateLabel('Decks No:', 385, 25+$CardSetHeight, 60, 17) $DecksNumber = GUICtrlCreateInput(IniRead($IniFile, 'Cards', 'DeckNumber', '1'), 440, 25-3+$CardSetHeight, 45, 20, BitOR($ES_CENTER, $ES_NUMBER)) GUICtrlCreateUpdown(-1) $DrawCards = GUICtrlCreateButton('Draw cards [ hotkey = F10 ]', 20+90, 50+$CardSetHeight, $width-40-175) $CardsDrawnLabel = GUICtrlCreateLabel('Drawn card(s): /', 10, 213+$CardSetHeight, $width-20, 17, $ES_CENTER) GUICtrlSetFont(-1, 10, 400, -1, 'SegoeUI') $Clear_Cards_Button = GUICtrlCreateButton('Clear selection', 20, 50+$CardSetHeight, 80, 25) $Mix_Cards_Button = GUICtrlCreateButton('Mix cards', 405, 50+$CardSetHeight, 80, 25) GUICtrlCreateGroup("", -99, -99, 1, 1) $PlaySounds = GUICtrlCreateCheckbox('Play sounds', 5, $height-35) GUICtrlSetState(-1, IniRead($IniFile, 'Options', 'Sound', '3')) $AnimateElements = GUICtrlCreateCheckbox('Animate elements', 120, $height-35) GUICtrlSetState(-1, IniRead($IniFile, 'Options', 'Animate', '3')) $CloseBUtton = GUICtrlCreateButton('Close', $width-110, $height-35, 100, 25) GUISetState(@SW_SHOW) _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($Form1) $hbitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic) $backbuffer = _GDIPlus_ImageGetGraphicsContext($hbitmap) $HotPen2 = _GDIPlus_PenCreate (0x5500CC00, 6) $HotPen3 = _GDIPlus_PenCreate (0xCC0000CC, 1) $HotBrush = _GDIPlus_BrushCreateSolid (0x200000CC) $BrushRed = _GDIPlus_BrushCreateSolid(0xFFCC0000) $BrushBlack = _GDIPlus_BrushCreateSolid(0xFF000000) $BrushWhite = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) $BackgroundBrush = _GDIPlus_BrushCreateSolid(0xFFEEEEEE) $hFormat = _GDIPlus_StringFormatCreate () _GDIPlus_StringFormatSetAlign($hFormat, 1) $hFamily = _GDIPlus_FontFamilyCreate ('Times New Roman') $hFont = _GDIPlus_FontCreate ($hFamily, 36, 1) _GDIPlus_GraphicsSetSmoothingMode($backbuffer, 2) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUIRegisterMsg(0xF,"MY_PAINT") OnAutoItExitRegister( "QuitApplication" ) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_RESTORE _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height) Case $DeckType _Form_Cards_Array($CardsArray, _GUICtrlComboBox_GetCurSel($DeckType)) _MixCards() EndSwitch If WinActive($Form1) then Local $a = GUIGetCursorInfo($Form1) $hoveringDice = False For $i = 1 to UBound($LastDices)-1 If ($a[0] > $LastDices[$i][1]) AND ($a[1] > $LastDices[$i][2]) AND ($a[0] < $LastDices[$i][3]) AND ($a[1] < $LastDices[$i][4]) Then If $a[2] = 1 Then If $MouseState <> 3 Then $MouseState = 3 $LastHoveredDice = 0 If $LastDices[$i][5] = False then If GUICtrlRead($PlaySounds) = $GUI_CHECKED then SoundPlay(@WindowsDir & "\media\Windows Navigation Start.wav") $LastDices[$i][5] = True Else If GUICtrlRead($PlaySounds) = $GUI_CHECKED then SoundPlay(@WindowsDir & "\media\Speech Misrecognition.wav") $LastDices[$i][5] = False EndIf EndIf else If $MouseState <> 1 Then $MouseState = 1 EndIf EndIf If $hoveringDice = False then $hoveringDice = True If $LastHoveredDice <> $i Then $LastHoveredDice = $i _GDIPlus_GraphicsFillRect($backbuffer, 6, 48, $width-13, 60+8, $BackgroundBrush) For $z = 1 to UBound($LastDices)-1 If $LastDices[$z][5] = True then _DrawDices($LastDices[$z][0], $LastDices[$z][1], $LastDices[$z][2], 60, 60, True) _DrawEdgeRoundDice($LastDices[$z][1], $LastDices[$z][2], 60, 60, $HotPen3, True, $HotBrush) Else _DrawDices($LastDices[$z][0], $LastDices[$z][1], $LastDices[$z][2], 60, 60, False) EndIf If $z = $i then _DrawEdgeRoundDice($LastDices[$z][1], $LastDices[$z][2], 60, 60, $HotPen2) EndIf Next _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height) EndIf EndIf Next If $hoveringDice = False Then If $LastHoveredDice <> 0 Then $LastHoveredDice = 0 _DrawOrDeleteEdgesDice($HotPen3, True, $HotBrush) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height) EndIf EndIf Local $hoveringCard = False For $i = 1 to UBound($LastCards)-1 If ($a[0] > $LastCards[$i][3]) AND ($a[1] > $LastCards[$i][4]) AND ($a[0] < $LastCards[$i][5]) AND ($a[1] < $LastCards[$i][6]) Then Local $card_dim = 80 If $a[2] = 1 Then If $MouseState <> 3 Then $MouseState = 3 $lasthoveredCard = 0 If $LastCards[$i][7] = False then If GUICtrlRead($PlaySounds) = $GUI_CHECKED then SoundPlay(@WindowsDir & "\media\Windows Navigation Start.wav") $LastCards[$i][7] = True Else If GUICtrlRead($PlaySounds) = $GUI_CHECKED then SoundPlay(@WindowsDir & "\media\Speech Misrecognition.wav") $LastCards[$i][7] = False EndIf EndIf Else If $MouseState <> 1 Then $MouseState = 1 EndIf EndIf If $hoveringCard = False then $hoveringCard = True If $lasthoveredCard <> $i Then $lasthoveredCard = $i _GDIPlus_GraphicsFillRect($backbuffer, 6, $CardSetHeight+78, $width-13, $card_dim+$card_dim/2+8, $BackgroundBrush) If $CardsOverLap = True then _GDIPlus_StringFormatSetAlign($hFormat, 0) For $z = 1 to UBound($Lastcards)-1 If $CardsOverLap = True Then If $z = UBound($Lastcards)-1 Then _GDIPlus_StringFormatSetAlign($hFormat, 1) EndIf EndIf _GDIPlus_GraphicsFillRect ($backbuffer, $LastCards[$z][3], $LastCards[$z][4], $card_dim, $card_dim+$card_dim/2, $BrushWhite) $layOut = _GDIPlus_RectFCreate ($LastCards[$z][3], $LastCards[$z][4], $card_dim, $card_dim+$card_dim/2) If $LastCards[$z][2] < 3 then _GDIPlus_GraphicsDrawStringEx ($backbuffer, $LastCards[$z][0] & @CRLF & $LastCards[$z][1], $hFont, $layOut, $hFormat, $BrushBlack) Else _GDIPlus_GraphicsDrawStringEx ($backbuffer, $LastCards[$z][0] & @CRLF & $LastCards[$z][1], $hFont, $layOut, $hFormat, $BrushRed) EndIf _GDIPlus_GraphicsDrawRect ($backbuffer, $LastCards[$z][3], $LastCards[$z][4], $card_dim, $card_dim+$card_dim/2) If $LastCards[$z][7] = True then _GDIPlus_GraphicsFillRect ($backbuffer, $LastCards[$z][3], $LastCards[$z][4], $card_dim, $card_dim+$card_dim/2, $HotBrush) _GDIPlus_GraphicsDrawRect ($backbuffer, $LastCards[$z][3], $LastCards[$z][4], $card_dim, $card_dim+$card_dim/2, $HotPen3) EndIf If $z = $i then _GDIPlus_GraphicsDrawRect ($backbuffer, $LastCards[$z][3], $LastCards[$z][4], $card_dim, $card_dim+$card_dim/2, $HotPen2) Next _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height) EndIf EndIf Next If $hoveringCard = False Then If $lasthoveredCard <> 0 Then $lasthoveredCard = 0 _DrawOrDeleteEdgesCards($HotPen3, True, $HotBrush) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height) EndIf EndIf EndIf Sleep(1) WEnd Func _DrawOrDeleteEdgesCards($pen = 0, $fill = False, $brush = 0) Local $card_dim = 80 _GDIPlus_GraphicsFillRect($backbuffer, 6, $CardSetHeight+78, $width-13, $card_dim+$card_dim/2+8, $BackgroundBrush) If $CardsOverLap = True then _GDIPlus_StringFormatSetAlign($hFormat, 0) For $z = 1 to UBound($Lastcards)-1 If $CardsOverLap = True Then If $z = UBound($Lastcards)-1 Then _GDIPlus_StringFormatSetAlign($hFormat, 1) EndIf EndIf _GDIPlus_GraphicsFillRect ($backbuffer, $LastCards[$z][3], $LastCards[$z][4], $card_dim, $card_dim+$card_dim/2, $BrushWhite) $layOut = _GDIPlus_RectFCreate ($LastCards[$z][3], $LastCards[$z][4], $card_dim, $card_dim+$card_dim/2) If $LastCards[$z][2] < 3 then _GDIPlus_GraphicsDrawStringEx ($backbuffer, $LastCards[$z][0] & @CRLF & $LastCards[$z][1], $hFont, $layOut, $hFormat, $BrushBlack) Else _GDIPlus_GraphicsDrawStringEx ($backbuffer, $LastCards[$z][0] & @CRLF & $LastCards[$z][1], $hFont, $layOut, $hFormat, $BrushRed) EndIf _GDIPlus_GraphicsDrawRect ($backbuffer, $LastCards[$z][3], $LastCards[$z][4], $card_dim, $card_dim+$card_dim/2) If $LastCards[$z][7] = True then If $fill = True then _GDIPlus_GraphicsFillRect ($backbuffer, $LastCards[$z][3], $LastCards[$z][4], $card_dim, $card_dim+$card_dim/2, $brush) _GDIPlus_GraphicsDrawRect ($backbuffer, $LastCards[$z][3], $LastCards[$z][4], $card_dim, $card_dim+$card_dim/2, $pen) EndIf Next EndFunc Func _DrawOrDeleteEdgesDice($pen = 0, $Fill = False, $brush = 0) _GDIPlus_GraphicsFillRect($backbuffer, 6, 48, $width-13, 60+8, $BackgroundBrush) For $i = 1 to UBound($LastDices)-1 If $LastDices[$i][5] = True then _DrawDices($LastDices[$i][0], $LastDices[$i][1], $LastDices[$i][2], 60, 60, True) _DrawEdgeRoundDice($LastDices[$i][1], $LastDices[$i][2], 60, 60, $pen, $fill, $brush) Else _DrawDices($LastDices[$i][0], $LastDices[$i][1], $LastDices[$i][2], 60, 60, False) EndIf Next EndFunc Func _DrawEdgeRoundDice($iX, $iY, $iWidth, $iHeight, $pen, $fill = False, $brush = 0) Local $aPoints[5][2] Local $reduction = 6 $aPoints[0][0] = 4 $aPoints[1][0] = $iX+$reduction $aPoints[1][1] = $iY+$reduction $aPoints[2][0] = $iX+$iWidth-$reduction $aPoints[2][1] = $iY+$reduction $aPoints[3][0] = $iX+$iWidth-$reduction $aPoints[3][1] = $iY+$iHeight-$reduction $aPoints[4][0] = $iX+$reduction $aPoints[4][1] = $iY+$iHeight-$reduction If $fill = True then _GDIPlus_GraphicsFillClosedCurve($backbuffer, $aPoints, $brush) _GDIPlus_GraphicsDrawClosedCurve($backbuffer, $aPoints, $pen) EndFunc Func _ThrowDices() If $DicesOn = True then Return 0 $DicesOn = True If GUICtrlRead($PlaySounds) = $GUI_CHECKED then SoundPlay(@WindowsDir & "\media\Windows Pop-up Blocked.wav") Local $number_of_dices = GUICtrlRead($DiceNumber) If $number_of_dices < 1 Then MsgBox(0, 'Error', 'Your dice number is invalid') $DicesOn = False Return 0 EndIf Local $Total = '' Local $space_between = 8 Local $dice_dim = 60 Local $total_width = $number_of_dices*$dice_dim+($number_of_dices-1)*$space_between If $total_width > $width-20 Then Do $space_between -= 1 $total_width = $number_of_dices*$dice_dim+($number_of_dices-1)*$space_between Until $total_width < $width-20 EndIf Local $layOut, $random_number _GDIPlus_GraphicsFillRect($backbuffer, 6, 48, $width-13, $dice_dim+8, $BackgroundBrush) If UBound($LastDices)-1 <> $number_of_dices then ReDim $LastDices[$number_of_dices+1][6] For $i = 1 to $number_of_dices $LastDices[$i][5] = False Next Else For $i = 1 to $number_of_dices If $LastDices[$i][5] = True then _DrawDices($LastDices[$i][0], $LastDices[$i][1], $LastDices[$i][2], $dice_dim, $dice_dim, $LastDices[$i][5]) If $LastDices[$i][5] = True then _DrawEdgeRoundDice($LastDices[$i][1], $LastDices[$i][2], $dice_dim, $dice_dim, $HotPen3, True, $HotBrush) Next EndIf If GUICtrlRead($AnimateElements) = $GUI_CHECKED Then _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height) For $i = 1 to $number_of_dices If $LastDices[$i][5] = True then $random_number = $LastDices[$i][0] Else $random_number = Random(1, 6, 1) $LastDices[$i][0] = $random_number EndIf $Total &= $random_number & ', ' If $LastDices[$i][5] = False then _DrawDices($random_number, $width/2-$total_width/2+($i-1)*($dice_dim+$space_between), 52, $dice_dim, $dice_dim, $LastDices[$i][5]) $LastDices[$i][1] = $width/2-$total_width/2+($i-1)*($dice_dim+$space_between) $LastDices[$i][2] = 52 $LastDices[$i][3] = $width/2-$total_width/2+($i-1)*($dice_dim+$space_between)+$dice_dim $LastDices[$i][4] = 52+$dice_dim If $LastDices[$i-1][3] > $LastDices[$i][1] then $LastDices[$i-1][3] = $LastDices[$i][1] If (GUICtrlRead($AnimateElements) = $GUI_CHECKED) AND ($LastDices[$i][5] = False) Then Local $step = -7 Local $Correction = 1 For $z = 52+$dice_dim+$step+$step to 52 Step $step _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hbitmap, $width/2-$total_width/2+($i-1)*($dice_dim+$space_between)-$Correction, 52-$Correction, $dice_dim+2*$Correction, _ $dice_dim+2*$Correction, $width/2-$total_width/2+($i-1)*($dice_dim+$space_between)-$Correction, $z-$Correction, $dice_dim+2*$Correction, (52+$dice_dim)-$z+2*$Correction) Sleep(1) Next _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height) EndIf Next _DrawOrDeleteEdgesDice($HotPen3, True, $HotBrush) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height) $Total = StringTrimRight($Total, 2) GUICtrlSetData($DicesThrownLabel, 'Thrown dice(s): ' & $Total) $DicesOn = False EndFunc Func _DrawDices($DiceNumb, $iX, $iY, $iWidth, $iHeight = $iWidth, $NoBlackCurve = False) Local $SpotSize = 10 Local $aPoints[5][2] Local $reduction = 6 $aPoints[0][0] = 4 $aPoints[1][0] = $iX+$reduction $aPoints[1][1] = $iY+$reduction $aPoints[2][0] = $iX+$iWidth-$reduction $aPoints[2][1] = $iY+$reduction $aPoints[3][0] = $iX+$iWidth-$reduction $aPoints[3][1] = $iY+$iHeight-$reduction $aPoints[4][0] = $iX+$reduction $aPoints[4][1] = $iY+$iHeight-$reduction _GDIPlus_GraphicsFillClosedCurve($backbuffer, $aPoints, $BrushWhite) If $NoBlackCurve = False then _GDIPlus_GraphicsDrawClosedCurve($backbuffer, $aPoints) Switch $DiceNumb Case 1 _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$iWidth/2-$SpotSize/2, $iY+$iHeight/2-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack) Case 2 Local $a_side = Round(Sqrt(((Sqrt($iWidth^2+$iHeight^2)/3)^2)/2)) _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$a_side-$SpotSize/2, $iY+$iHeight-$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack) _GDIPlus_GraphicsFillEllipse($backbuffer, $iX-$a_side+$iWidth-$SpotSize/2, $iY+$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack) Case 3 Local $a_side = Round(Sqrt(((Sqrt($iWidth^2+$iHeight^2)/4)^2)/2)) _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$iWidth/2-$SpotSize/2, $iY+$iHeight/2-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack) _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$a_side-$SpotSize/2, $iY+$iHeight-$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack) _GDIPlus_GraphicsFillEllipse($backbuffer, $iX-$a_side+$iWidth-$SpotSize/2, $iY+$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack) Case 4 Local $a_side = Round(Sqrt(((Sqrt($iWidth^2+$iHeight^2)/4)^2)/2)) _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$a_side-$SpotSize/2, $iY+$iHeight-$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack) _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$a_side-$SpotSize/2, $iY+$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack) _GDIPlus_GraphicsFillEllipse($backbuffer, $iX-$a_side+$iWidth-$SpotSize/2, $iY+$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack) _GDIPlus_GraphicsFillEllipse($backbuffer, $iX-$a_side+$iWidth-$SpotSize/2, $iY+$iHeight-$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack) Case 5 Local $a_side = Round(Sqrt(((Sqrt($iWidth^2+$iHeight^2)/4)^2)/2)) _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$iWidth/2-$SpotSize/2, $iY+$iHeight/2-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack) _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$a_side-$SpotSize/2, $iY+$iHeight-$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack) _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$a_side-$SpotSize/2, $iY+$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack) _GDIPlus_GraphicsFillEllipse($backbuffer, $iX-$a_side+$iWidth-$SpotSize/2, $iY+$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack) _GDIPlus_GraphicsFillEllipse($backbuffer, $iX-$a_side+$iWidth-$SpotSize/2, $iY+$iHeight-$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack) Case 6 Local $a_side = Round(Sqrt(((Sqrt($iWidth^2+$iHeight^2)/4)^2)/2)) _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$a_side-$SpotSize/2, $iY+$iHeight-$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack) _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$a_side-$SpotSize/2, $iY+$iHeight/2-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack) _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$a_side-$SpotSize/2, $iY+$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack) _GDIPlus_GraphicsFillEllipse($backbuffer, $iX-$a_side+$iWidth-$SpotSize/2, $iY+$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack) _GDIPlus_GraphicsFillEllipse($backbuffer, $iX+$iWidth-$a_side-$SpotSize/2, $iY+$iHeight/2-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack) _GDIPlus_GraphicsFillEllipse($backbuffer, $iX-$a_side+$iWidth-$SpotSize/2, $iY+$iHeight-$a_side-$SpotSize/2, $SpotSize, $SpotSize, $BrushBlack) EndSwitch EndFunc Func _DrawCards() If $CardsOn = True then Return 0 $CardsOn = True If GUICtrlRead($PlaySounds) = $GUI_CHECKED then SoundPlay(@WindowsDir & "\media\Windows Pop-up Blocked.wav") Local $number_of_cards = GUICtrlRead($CardsNumber) If $number_of_cards < 1 Then MsgBox(0, 'Error', 'Your number of cards is invalid') $CardsOn = False Return 0 EndIf If GUICtrlRead($DecksNumber) < 1 Then MsgBox(0, 'Error', 'Invalid number of card decks') $CardsOn = False Return 0 EndIf Local $Total = '' Local $space_between = 8 Local $card_dim = 80 Local $total_width = $number_of_cards*$card_dim+($number_of_cards-1)*$space_between If $total_width > $width-20 Then Do $space_between -= 1 $total_width = $number_of_cards*$card_dim+($number_of_cards-1)*$space_between Until $total_width < $width-20 _GDIPlus_StringFormatSetAlign($hFormat, 0) $CardsOverLap = True Else $CardsOverLap = False EndIf Local $layOut Dim $DrawnCard[3] Local $TotalBlacks = 0 _GDIPlus_GraphicsFillRect($backbuffer, 6, $CardSetHeight+78, $width-13, $card_dim+$card_dim/2+8, $BackgroundBrush) If UBound($LastCards)-1 <> $number_of_cards then ReDim $LastCards[$number_of_cards+1][8] For $i = 1 to $number_of_cards $LastCards[$i][7] = False Next Else For $i = 1 to $number_of_cards If $LastCards[$i][7] = True then If $CardsOverLap = True Then If $i = $number_of_cards Then _GDIPlus_StringFormatSetAlign($hFormat, 1) EndIf EndIf _GDIPlus_GraphicsFillRect ($backbuffer, $LastCards[$i][3], $LastCards[$i][4], $card_dim, $card_dim+$card_dim/2, $BrushWhite) $layOut = _GDIPlus_RectFCreate ($LastCards[$i][3], $LastCards[$i][4], $card_dim, $card_dim+$card_dim/2) If $LastCards[$i][2] < 3 then _GDIPlus_GraphicsDrawStringEx ($backbuffer, $LastCards[$i][0] & @CRLF & $LastCards[$i][1], $hFont, $layOut, $hFormat, $BrushBlack) $TotalBlacks += 1 Else _GDIPlus_GraphicsDrawStringEx ($backbuffer, $LastCards[$i][0] & @CRLF & $LastCards[$i][1], $hFont, $layOut, $hFormat, $BrushRed) EndIf _GDIPlus_GraphicsDrawRect ($backbuffer, $LastCards[$i][3], $LastCards[$i][4], $card_dim, $card_dim+$card_dim/2) _GDIPlus_GraphicsFillRect ($backbuffer, $LastCards[$i][3], $LastCards[$i][4], $card_dim, $card_dim+$card_dim/2, $HotBrush) _GDIPlus_GraphicsDrawRect ($backbuffer, $LastCards[$i][3], $LastCards[$i][4], $card_dim, $card_dim+$card_dim/2, $HotPen3) EndIf Next EndIf If $CardsOverLap = True then _GDIPlus_StringFormatSetAlign($hFormat, 0) For $i = 1 to $number_of_cards If $i = $number_of_cards then _GDIPlus_StringFormatSetAlign($hFormat, 1) If $LastCards[$i][7] = True then ReDim $DrawnCard[3] $DrawnCard[0] = $LastCards[$i][0] $DrawnCard[1] = $LastCards[$i][1] $DrawnCard[2] = $Lastcards[$i][2] Else $DrawnCard = _GetCard() $LastCards[$i][0] = $DrawnCard[0] $LastCards[$i][1] = $DrawnCard[1] $LastCards[$i][2] = $DrawnCard[2] EndIf $LastCards[$i][3] = $width/2-$total_width/2+($i-1)*($card_dim+$space_between) $LastCards[$i][4] = $CardSetHeight+82 $LastCards[$i][5] = $width/2-$total_width/2+($i-1)*($card_dim+$space_between)+$card_dim $LastCards[$i][6] = $CardSetHeight+82+$card_dim+$card_dim/2 If $LastCards[$i-1][5] > $LastCards[$i][3] then $LastCards[$i-1][5] = $LastCards[$i][3] $Total &= $DrawnCard[0] & $DrawnCard[1] & ', ' If (GUICtrlRead($AnimateElements) = $GUI_CHECKED) AND ($LastCards[$i][7] = False) then Local $step = -20 For $z = $CardSetHeight+82+$card_dim+$card_dim/2+$step to $CardSetHeight+82 step $step _GDIPlus_GraphicsFillRect ($backbuffer, $width/2-$total_width/2+($i-1)*($card_dim+$space_between), $z, $card_dim, ($CardSetHeight+82+$card_dim+$card_dim/2)-$z, $BrushWhite) $layOut = _GDIPlus_RectFCreate ($width/2-$total_width/2+($i-1)*($card_dim+$space_between), $z, $card_dim, ($CardSetHeight+82+$card_dim+$card_dim/2)-$z) If $DrawnCard[2] < 3 then _GDIPlus_GraphicsDrawStringEx ($backbuffer, $DrawnCard[0] & @CRLF & $DrawnCard[1], $hFont, $layOut, $hFormat, $BrushBlack) Else _GDIPlus_GraphicsDrawStringEx ($backbuffer, $DrawnCard[0] & @CRLF & $DrawnCard[1], $hFont, $layOut, $hFormat, $BrushRed) EndIf _GDIPlus_GraphicsDrawRect ($backbuffer, $width/2-$total_width/2+($i-1)*($card_dim+$space_between), $z, $card_dim, ($CardSetHeight+82+$card_dim+$card_dim/2)-$z) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height) Sleep(1) Next EndIf If $LastCards[$i][7] = False then _GDIPlus_GraphicsFillRect ($backbuffer, $width/2-$total_width/2+($i-1)*($card_dim+$space_between), $CardSetHeight+82, $card_dim, $card_dim+$card_dim/2, $BrushWhite) $layOut = _GDIPlus_RectFCreate ($width/2-$total_width/2+($i-1)*($card_dim+$space_between), $CardSetHeight+82, $card_dim, $card_dim+$card_dim/2) If $DrawnCard[2] < 3 then _GDIPlus_GraphicsDrawStringEx ($backbuffer, $DrawnCard[0] & @CRLF & $DrawnCard[1], $hFont, $layOut, $hFormat, $BrushBlack) $TotalBlacks += 1 Else _GDIPlus_GraphicsDrawStringEx ($backbuffer, $DrawnCard[0] & @CRLF & $DrawnCard[1], $hFont, $layOut, $hFormat, $BrushRed) EndIf _GDIPlus_GraphicsDrawRect ($backbuffer, $width/2-$total_width/2+($i-1)*($card_dim+$space_between), $CardSetHeight+82, $card_dim, $card_dim+$card_dim/2) EndIf Next _DrawOrDeleteEdgesCards($hotpen3, True, $HotBrush) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height) $Total = StringTrimRight($Total, 2) GUICtrlSetData($CardsDrawnLabel, 'Drawn card(s): ' & $Total) GUICtrlSetColor($CardsDrawnLabel, '0x' & Hex(Round(204-(204/$number_of_cards)*$TotalBlacks), 2) & '0000') $CardsOn = False EndFunc Func _GetCard() Local $CardChars[5] = ['', ChrW(9824), ChrW(9827), ChrW(9829), ChrW(9830)] Local $i_deckCount = GUICtrlRead($DecksNumber) Local $ret_Val[3] Local $resultet_Number, $resultet_sign Local $4Signs Local $Satisfied = False Do _AllCardsPickedCheck() $resultet_Number = _GenerateRandomNumbers(UBound($CardsArray)-1, UBound($CardsArray)-1, 1) If NOT @error then For $i = 0 to UBound($resultet_Number)-1 $4Signs = _GenerateRandomNumbers(4, 4, 1) If NOT @error then For $j = 0 to 3 If $CardsArray[$resultet_Number[$i]][$4Signs[$j]] < $i_deckCount Then $ret_Val[0] = $CardsArray[$resultet_Number[$i]][0] $ret_Val[1] = $CardChars[$4Signs[$j]] $ret_Val[2] = $4Signs[$j] $CardsArray[$resultet_Number[$i]][$4Signs[$j]] += 1 $Satisfied = True ExitLoop EndIf Next EndIf If $Satisfied = True then ExitLoop Next _AllCardsPickedCheck() EndIf Until $Satisfied = True Return $ret_Val EndFunc Func _GenerateRandomNumbers($iGenerateNums, $iMaxEachNum, $iMinEachNum = 0) If $iGenerateNums > ($iMaxEachNum - $iMinEachNum) + 1 Then Return SetError(1, 0, 0) Local $aRandom[$iGenerateNums] For $i = 0 To $iGenerateNums - 1 While True $aRandom[$i] = Random($iMinEachNum, $iMaxEachNum, 1) For $j = 0 To $iGenerateNums - 1 If $j <> $i Then If $aRandom[$j] = $aRandom[$i] Then ContinueLoop 2 EndIf Next ExitLoop WEnd Next Return $aRandom EndFunc ;==>_GenerateRandomNumbers Func _AllCardsPickedCheck() Local $Check4DrawnCards = False Local $Filled = True Local $i_deckCount = GUICtrlRead($DecksNumber) Local $TotalCardsDrawn If $Check4DrawnCards = True Then $TotalCardsDrawn = 'Card:' & @TAB & _ ChrW(9824) & @TAB & ChrW(9827) & @TAB & _ ChrW(9829) & @TAB & ChrW(9830) & @CRLF & _ '----------------------------------' & @CRLF For $i = 1 to UBound($CardsArray)-1 $TotalCardsDrawn &= $CardsArray[$i][0] For $j = 1 to 4 If $CardsArray[$i][$j] < $i_deckCount then $Filled = False If $Check4DrawnCards = False then ExitLoop EndIf If $Check4DrawnCards = True Then $TotalCardsDrawn &= @TAB & $CardsArray[$i][$j] Next If $Check4DrawnCards = True Then $TotalCardsDrawn &= @CRLF Next If $Check4DrawnCards = True Then ClipPut($TotalCardsDrawn) If $Filled = True then _ResetCards() EndFunc Func _ResetCards() For $i = 0 to UBound($CardsArray)-1 $CardsArray[$i][1] = 0 $CardsArray[$i][2] = 0 $CardsArray[$i][3] = 0 $CardsArray[$i][4] = 0 For $z = 1 to UBound($Lastcards)-1 If $Lastcards[$z][7] = True Then If $CardsArray[$i][0] = $Lastcards[$z][0] Then $CardsArray[$i][$Lastcards[$z][2]] += 1 EndIf EndIf Next Next EndFunc Func _Form_Cards_Array(ByRef $CardAr, $type) If $type = 0 Then Local $AllCards[14] = ['', 2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K', 'A'] ReDim $CardAr[14][5] ElseIf $type = 1 Then Local $AllCards[9] = ['', 7, 8, 9, 10, 'J', 'Q', 'K', 'A'] ReDim $CardAr[9][5] EndIf For $i = 0 to UBound($AllCards)-1 $CardAr[$i][0] = $AllCards[$i] $CardAr[$i][1] = 0 $CardAr[$i][2] = 0 $CardAr[$i][3] = 0 $CardAr[$i][4] = 0 Next EndFunc Func QuitApplication() _Save_All_Data() _WinAPI_DeleteObject($hbitmap) _GDIPlus_GraphicsDispose($backbuffer) _GDIPlus_BrushDispose($BrushBlack) _GDIPlus_BrushDispose($HotBrush) _GDIPlus_BrushDispose($BrushRed) _GDIPlus_BrushDispose($BrushWhite) _GDIPlus_BrushDispose($BackgroundBrush) _GDIPlus_PenDispose ($HotPen2) _GDIPlus_PenDispose ($HotPen3) _GDIPlus_FontDispose ($hFont) _GDIPlus_FontFamilyDispose ($hFamily) _GDIPlus_StringFormatDispose ($hFormat) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() EndFunc Func _MixCards() ReDim $LastCards[UBound($Lastcards)][8] For $i = 1 to UBound($Lastcards)-1 For $z = 0 to 6 $Lastcards[$i][$z] = -1 Next $Lastcards[$i][7] = False Next _ResetCards() Local $card_dim = 80 _GDIPlus_GraphicsFillRect($backbuffer, 6, $CardSetHeight+78, $width-13, $card_dim+$card_dim/2+8, $BackgroundBrush) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height) EndFunc Func _Save_All_Data() IniWrite($IniFile, 'Dices', 'Number', GUICtrlRead($DiceNumber)) IniWrite($IniFile, 'Cards', 'Number', GUICtrlRead($CardsNumber)) IniWrite($IniFile, 'Cards', 'Deck', _GUICtrlComboBox_GetCurSel($DeckType)) IniWrite($IniFile, 'Cards', 'DeckNumber', GUICtrlRead($DecksNumber)) IniWrite($IniFile, 'Options', 'Sound', GUICtrlRead($PlaySounds)) IniWrite($IniFile, 'Options', 'Animate', GUICtrlRead($AnimateElements)) EndFunc Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) Switch $iwParam Case $ThrowDices _ThrowDices() Case $DrawCards _DrawCards() Case $CloseBUtton Exit Case $clear_dice_button If GUICtrlRead($PlaySounds) = $GUI_CHECKED then SoundPlay(@WindowsDir & "\media\Speech Misrecognition.wav") For $i = 1 to UBound($LastDices)-1 $LastDices[$i][5] = False Next _DrawOrDeleteEdgesDice($HotPen3, True, $HotBrush) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height) Case $Clear_Cards_Button If GUICtrlRead($PlaySounds) = $GUI_CHECKED then SoundPlay(@WindowsDir & "\media\Speech Misrecognition.wav") For $i = 1 to UBound($Lastcards)-1 $Lastcards[$i][7] = False Next _DrawOrDeleteEdgesCards($HotPen3, True, $HotBrush) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height) Case $Mix_Cards_Button _MixCards() EndSwitch #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode, $hWndDecks If Not IsHWnd($DecksNumber) Then $hWndDecks = GUICtrlGetHandle($DecksNumber) $hWndFrom = $ilParam $iIDFrom = _WinAPI_LoWord($iwParam) $iCode = _WinAPI_HiWord($iwParam) Switch $hWndFrom Case $hWndDecks, $DecksNumber Switch $iCode Case 1024 _MixCards() EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Func MY_PAINT($hWnd, $Msg, $wParam, $lParam) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hbitmap, 0, 0, $width, $height) Return $GUI_RUNDEFMSG EndFunc
    1 point
×
×
  • Create New...