Flags

Many functions have parameters, often called "flags", that can consists of several values (bits). To create flags from several values, use operator | (bitwise or). Examples:

 

int hwnd=win("Window" "" "" 1|8) 
SetWindowPos(hwnd HWND_TOPMOST 0 0 0 0 SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW)

 

Usually flag values are divisible by two (1, 2, 4, 8, 16, and so on). If so, the | operator is the same as the + operator. For example, to specify flags 1, 4 and 16, you can use 1|4|16, or you can use 21. Flags usually are easier to read when they are in hexadecimal format, so instead of 21 you can use 0x15. Another example: 5|0x10.

 

A flag takes 1 bit, therefore an int value can have 32 flags.

 

If flags is optional parameters of a function, its default value is 0.

 

How to compare flags

Usually you need to know whether one of flags is set. Use operator &. Example: if(flags&8).

 

Don't use operator = (for example, if(flags=3)), unless you need to know whether ALL flags are exactly as specified.