Ticket #1155: _WinAPI_CreateSolidBitmap.au3

File _WinAPI_CreateSolidBitmap.au3, 2.3 KB (added by Yashied, 15 years ago)
Line 
1; #FUNCTION# ====================================================================================================================
2; Name...........: _WinAPI_CreateSolidBitmap
3; Description....: Creates a solid color bitmap
4; Syntax.........: _WinAPI_CreateSolidBitmap($hWnd, $iColor, $iWidth, $iHeight, $fRGB)
5; Parameters.....: $hWnd        - Handle to the window where the bitmap will be displayed
6;                  $iColor      - The color of the bitmap, depends on the $fRGB value
7;                  $iWidth      - The width of the bitmap
8;                  $iHeight     - The height of the bitmap
9;                  $fRGB        - Type of $iColor passed in, valid values:
10;                  |0 - BGR
11;                  |1 - RGB (Default)
12; Return values..: Success      - Handle to the bitmap
13;                  Failure      - 0 and sets the @error flag to non-zero
14; Author.........: Paul Campbell (PaulIA)
15; Modified.......: Yashied
16; Remarks........: When you no longer need the bitmap, call the _WinAPI_DeleteObject() function to delete it.
17; Related........: _WinAPI_CreateCompatibleBitmap
18; Link...........:
19; Example........:
20; ===============================================================================================================================
21
22Func _WinAPI_CreateSolidBitmap($hWnd, $iColor, $iWidth, $iHeight, $fRGB = 1)
23
24        Local $tRect, $hBitmap, $hBrush, $hOld, $hDC, $hDestDC, $hDestSv
25
26        $hDC = _WinAPI_GetDC($hWnd)
27        $hDestDC = _WinAPI_CreateCompatibleDC($hDC)
28        $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
29        $hOld = _WinAPI_SelectObject($hDestDC, $hBitmap)
30        $tRect = DllStructCreate($tagRECT)
31        DllStructSetData($tRect, 1, 0)
32        DllStructSetData($tRect, 2, 0)
33        DllStructSetData($tRect, 3, $iWidth)
34        DllStructSetData($tRect, 4, $iHeight)
35        If $fRGB Then
36                $iColor = BitOR(BitAND($iColor, 0x00FF00), BitShift(BitAND($iColor, 0x0000FF), -16), BitShift(BitAND($iColor, 0xFF0000), 16))
37        EndIf
38        $hBrush = _WinAPI_CreateSolidBrush($iColor)
39        _WinAPI_FillRect($hDestDC, DllStructGetPtr($tRect), $hBrush)
40        If @error Then
41                _WinAPI_DeleteObject($hBitmap)
42                $hBitmap = 0
43        EndIf
44        _WinAPI_DeleteObject($hBrush)
45        _WinAPI_ReleaseDC($hWnd, $hDC)
46        _WinAPI_SelectObject($hDestDC, $hOld)
47        _WinAPI_DeleteDC($hDestDC)
48        Return SetError(($hBitmap = 0), 0, $hBitmap)
49EndFunc   ;==>_WinAPI_CreateSolidBitmap