Jump to content
Sign in to follow this  

Convert BitOR value

Recommended Posts

Hello community :D

If i have:


And i want to use it like a default parameter in a fuction, i think i need to set the "numeric" value like:

Func Test1($param, $param2, $style = 0x00000000) ; 0x00000000 = i need to set here BitOR($SS_CENTER, $SS_CENTERIMAGE)

How to convert the BitOR($variable1, $variable2) to his numeric value? Thanks

Edited by MyEarth

Share this post

Link to post
Share on other sites

Check this out

#include <StaticConstants.au3>


Func A( $iDefault = 513 )
;The Default value is hard-coded by reading the console.

Func B( $iDefault = -1 )
;Assign the Default value of the variable to anything that is obvious would not be passed by the user.
;Now Direct way
If $iDefault = -1 Then $iDefault = BitOR($SS_CENTER, $SS_CENTERIMAGE)
Regards :)

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post

Link to post
Share on other sites


Top Tip: Avoid "magic numbers" and use the full descriptive version of the constants as you have been advised above. You will be grateful when you look at the script after a few months (or even days)! ;)


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Share this post

Link to post
Share on other sites

Perhaps it's a personal thing, but I often find it easier to read the binary rather than constant names. I sometimes prefer to use separate numeric values and BitOR them together in the code, rather than using magic numbers. This way I can see exactly what value is being passed as a parameter. I'm not too keen on having multiple ways of expressing: 0, 1, 2, 4, 8 etc... This isn't always the case and I mix and match methods depending on the situation: trying to get the best of all worlds.

Edited by czardas

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By j0kky
      Hi guys,
      Bitwise operations in Autoit is possible only till 32 bit integers, but sometimes WinAPI requires to process 64 bit vectors... so?
      So you can use this little UDF to handle properly those integers!
      Func _BitAND64($iValue1, $iValue2) If Not ((VarGetType($iValue1) = "Int64") Or (VarGetType($iValue2) = "Int64")) Then Return BitAND($iValue1, $iValue2) $iValue1 = __DecToBin64($iValue1) $iValue2 = __DecToBin64($iValue2) Local $aValueANDed[64], $i For $i = 0 To 63 $aValueANDed[$i] = ($iValue1[$i] And $iValue2[$i]) ? 1 : 0 Next Return __BinToDec64($aValueANDed) EndFunc ;==>_BitAND64 Func _BitOR64($iValue1, $iValue2) If Not ((VarGetType($iValue1) = "Int64") Or (VarGetType($iValue2) = "Int64")) Then Return BitOR($iValue1, $iValue2) $iValue1 = __DecToBin64($iValue1) $iValue2 = __DecToBin64($iValue2) Local $aValueORed[64], $i For $i = 0 To 63 $aValueORed[$i] = ($iValue1[$i] Or $iValue2[$i]) ? 1 : 0 Next Return __BinToDec64($aValueORed) EndFunc ;==>_BitOR64 Func _BitXOR64($iValue1, $iValue2) If Not ((VarGetType($iValue1) = "Int64") Or (VarGetType($iValue2) = "Int64")) Then Return BitXOR($iValue1, $iValue2) $iValue1 = __DecToBin64($iValue1) $iValue2 = __DecToBin64($iValue2) Local $aValueXORed[64], $i For $i = 0 To 63 $aValueXORed[$i] = (($iValue1[$i] And (Not $iValue2[$i])) Or ((Not $iValue1[$i]) And $iValue2)) ? 1 : 0 Next Return __BinToDec64($aValueXORed) EndFunc ;==>_BitXOR64 Func _BitNOT64($iValue) If Not (VarGetType($iValue) = "Int64") Then Return BitNOT($iValue) $iValue = __DecToBin64($iValue) For $i = 0 To 63 $iValue[$i] = Not $iValue[$i] Next Return __BinToDec64($iValue) EndFunc ;==>_BitNOT64 Func __DecToBin64($iDec) Local $tDec = DllStructCreate("int64 num"), $aBin[64], $bBit, $i $tDec.num = $iDec For $i = 0 To 63 $bBit = (Mod($tDec.num, 2) ? 1 : 0) $aBin[63 - $i] = $bBit $tDec.num = Floor($tDec.num / 2) Next Return $aBin EndFunc ;==>__DecToBin64 Func __BinToDec64($aBin) Local $tDec = DllStructCreate("int64 num"), $i If $aBin[0] Then $tDec.num += 0x8000000000000000 ;2^63 = 9223372036854775808, but for Autoit the world ends at 9223372036854775807 (2^63 - 1) For $i = 1 To 63 If $aBin[$i] Then $tDec.num += 2 ^ (63 - $i) Next Return $tDec.num EndFunc ;==>__BinToDec64 If you are working with unsigned 64 bit integers and these functions return a negative value, don't worry, bitwise operations come out well, but Autoit manages all numbers as signed integers.
    • By poila
      I am referring to code being presented in this thread () that discusses about enabling windows to lock to relative positions when moving around. I am requesting help in these areas:
      1. Is it possible for the secondary window to not have both its relative X and Y positions set to the primary window's coordinates, when minimized?
      Example code:
      Func showBottomForm($userID, $hWindow) ; Bottom form $g_hBottomForm = GUICreate("Bottom Form", $CONST_NORMAL_WIDTH, $CONST_NORMAL_HEIGHT, -1, WinGetPos($hWindow)[1] + WinGetPos($hWindow)[3], -1, $WS_EX_TOOLWINDOW) $hButton_Form = GUICtrlCreateButton("Bottom Form Button", 80, 10, 120, 30) GUISetState() EndFunc ;==>showBottomForm What this means is that if I moved the secondary window around before minimizing the primary window and then re-maximize the primary window again, the secondary window's position could be set correctly.
      But if the secondary window is not moved and then the primary window is minimized/re-maximized immediately, the secondary window's position gets locked to the X/Y coordinates of the primary window.
      2. Is it possible for the secondary window to be shown together with the primary window when the primary window is re-maximized in the presence of other application windows?
      What happens now is that the secondary window (based on above code) could not be seen if there are other windows shown.
      But if every window is minimized (except my AutoIt app), then I can see the secondary window. What changes are needed?
      I tried the following:
      GUICreate("Bottom Form", $CONST_NORMAL_WIDTH, $CONST_NORMAL_HEIGHT, -1, WinGetPos($hWindow)[1] + WinGetPos($hWindow)[3], -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_CLIENTEDGE)) This didn't really cause much change, so I am kinda stumped now. All help appreciated.
    • By Kovacic
      I am taking some idea from here:
      '?do=embed' frameborder='0' data-embedContent>>
      But what I am looking to accomplish is simple, I want to have an input box with a hidden input box below it. I will also have a defined list of items. When the text box has any value in it that does not directly equal an item in the pre defined list, the edit box should show. and populate suggested items based on whats being typed which I will do that part later, should be easy.
      I am stuck on a simple portion which should be easy and i'm not sure why I am having trouble with it.  The way thr code below should work is, as long as there is a value in the Input box, the edit box will appear, if there is no value in the input box, the edit box should be hidden. 
      here is what I have so far:
      #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 615, 438, 192, 124) $Input1 = GUICtrlCreateInput("", 64, 72, 313, 21) $Edit1 = GUICtrlCreateEdit("", 64, 96, 313, 177) GUISetState(@SW_SHOW) GUICtrlSetState($Edit1, $GUI_HIDE) While 1 $words = GUICtrlRead($Input1) If $words NOT = "" then GUICtrlSetState($Edit1, $GUI_SHOW) else GUICtrlSetState($Edit1, $GUI_HIDE) endif $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd func flopdrop() If BitAnd($Edit1,2) AND $words = "" Then GUICtrlSetState($Edit1, $GUI_HIDE) Else GUICtrlSetState($Edit1, $GUI_SHOW) EndIf endfunc the problem with this is a nasty flicker when you move the mouse or do anything else. I will get rid of the scroll bars too, but thats once I solve this flicker issue. I know its happening because I have the check being performed within the While statement, but I can't think of any other way to do it.. I even tried using a timer to only check once every few seconds, but that didn't seem to work either:
      If $words NOT = "" AND (@SEC = 00 OR 10 OR 20 OR 30 OR 40 OR 50) AND (@MSEC < 20)) Then ; Blah blah blah endIf Does anyone have any thoughts or has anyone been able to do this?
      Thanks in advance!!
  • Create New...