ReactOS  0.4.15-dev-492-ga1108f6
NtUserSelectPalette.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS api tests
3  * LICENSE: GPL - See COPYING in the top level directory
4  * PURPOSE: Test for NtUserSelectPalette
5  * PROGRAMMERS:
6  */
7 
8 #include <win32nt.h>
9 
13 {
15 
16  ret.peRed = r;
17  ret.peGreen = g;
18  ret.peBlue = b;
19  ret.peFlags = 0;
20  return ret;
21 }
22 
24 {
26  HPALETTE hPal, hOldPal;
27  HWND hWnd;
28  HDC hDC, hCompDC;
29  struct
30  {
31  LOGPALETTE logpal;
32  PALETTEENTRY entry[20];
33  } pal;
34 
35  ZeroMemory(&pal, sizeof(pal));
36 
37  pal.logpal.palVersion = 0x300;
38  pal.logpal.palNumEntries = 6;
39  pal.entry[0] = PALENTRY(0,0,0);
40  pal.entry[1] = PALENTRY(255,255,255);
41  pal.entry[2] = PALENTRY(128,128,128);
42  pal.entry[3] = PALENTRY(128,0,0);
43  pal.entry[4] = PALENTRY(0,128,0);
44  pal.entry[5] = PALENTRY(0,0,128);
45 
46  hPal = CreatePalette(&pal.logpal);
47  ASSERT(hPal);
48  TEST(DeleteObject(hPal) == 1);
49  hPal = CreatePalette(&pal.logpal);
50  ASSERT(hPal);
51 
52  /* Create a window */
53  hWnd = CreateWindowW(L"BUTTON", L"TestWindow", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
54  CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
55  NULL, NULL, hinst, 0);
56  hDC = GetDC(hWnd);
57  ASSERT(hDC);
58  hCompDC = CreateCompatibleDC(hDC);
59  ASSERT(hCompDC);
60 
61  /* Test NULL DC */
63  hOldPal = NtUserSelectPalette(NULL, hPal, 0);
64  TEST(hOldPal == 0);
66 
67  /* Test invalid DC */
69  hOldPal = NtUserSelectPalette((HDC)-1, hPal, 0);
70  TEST(hOldPal == 0);
72 
73  /* Test NULL palette */
75  hOldPal = NtUserSelectPalette(hDC, NULL, 0);
76  TEST(hOldPal == 0);
78 
79  /* Test invalid palette */
81  hOldPal = NtUserSelectPalette(hDC, (HPALETTE)-1, 0);
82  TEST(hOldPal == 0);
84 
85  /* Test valid palette */
86  hOldPal = NtUserSelectPalette(hDC, hPal, 0);
87  TEST(hOldPal != 0);
88  TEST(hOldPal == GetStockObject(DEFAULT_PALETTE));
89 
90  /* We cannot Delete the palette */
91  TEST(DeleteObject(hPal) == 0);
92 
93  /* We can still select the Palette into a compatible DC */
94  hOldPal = NtUserSelectPalette(hCompDC, hPal, 0);
95  TEST(hOldPal != 0);
96 
97 
98 
99 #if 0
101 
104 
105  TEST(GetNearestColor(hDC, RGB(0,0,0)) == RGB(0,0,0));
106  TEST(GetNearestColor(hDC, RGB(0,0,1)) == RGB(0,0,1));
107 
108  ReleaseDC(hWnd, hDC);
110  RECT rect;
111  HBITMAP hBmp;
112 
113 
114  BITMAPINFOHEADER bmih = {sizeof(BITMAPINFOHEADER), // biSize
115  3, // biWidth
116  3, // biHeight
117  1, // biPlanes
118  8, // biBitCount
119  BI_RGB, // biCompression
120  0, // biSizeImage
121  92, // biXPelsPerMeter
122  92, // biYPelsPerMeter
123  6, // biClrUsed
124  6}; // biClrImportant
125  BYTE bits[3][3] = {{0,1,2},{3,4,5},{6,1,2}};
126 
127  struct
128  {
129  BITMAPINFOHEADER bmih;
130  RGBQUAD colors[6];
131  } bmi = {{sizeof(BITMAPINFOHEADER),3,3,1,8,BI_RGB,0,92,92,6,6},
132  {{0,0,0,0},{255,255,255,0},{255,0,0,0},
133  {0,255,0,0},{0,0,255,0},{128,128,128,0}}};
134 
135  hBmp = CreateDIBitmap(hCompDC, &bmih, CBM_INIT, &bits, (BITMAPINFO*)&bmi, DIB_RGB_COLORS);
136  ASSERT(hBmp);
137 
138  SetLastError(0);
139  TEST(NtGdiSelectBitmap(hCompDC, hBmp));
140  hOldPal = NtUserSelectPalette(hCompDC, hPal, 0);
141  TEST(hOldPal != NULL);
142  RealizePalette(hCompDC);
143 
144  TEST(GetNearestColor(hCompDC, RGB(0,0,0)) == RGB(0,0,0));
145  TEST(GetNearestColor(hCompDC, RGB(0,0,1)) == RGB(0,0,0));
146  TEST(GetNearestColor(hCompDC, RGB(100,0,0)) == RGB(0,0,0));
147  TEST(GetNearestColor(hCompDC, RGB(250,250,250)) == RGB(255,255,255));
148  TEST(GetNearestColor(hCompDC, RGB(120,100,110)) == RGB(128,128,128));
149 
150 printf("nearest = 0x%x\n", GetNearestColor(hCompDC, RGB(120,100,110)));
151 #endif
152 
153 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define ERROR_SUCCESS
Definition: deptool.c:10
#define RGB(r, g, b)
Definition: precomp.h:62
HDC WINAPI GetDC(_In_opt_ HWND)
COLORREF WINAPI GetNearestColor(_In_ HDC, _In_ COLORREF)
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
HPALETTE WINAPI NtUserSelectPalette(HDC hDC, HPALETTE hpal, BOOL ForceBackground)
Definition: windc.c:1033
static HDC
Definition: imagelist.c:92
HWND hWnd
Definition: settings.c:17
__kernel_entry W32KAPI HBITMAP APIENTRY NtGdiSelectBitmap(_In_ HDC hdc, _In_ HBITMAP hbm)
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1648
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
BOOL WINAPI DestroyWindow(_In_ HWND)
#define CreateWindowW(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4291
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
Definition: glext.h:10929
& rect
Definition: startmenu.cpp:1413
#define CBM_INIT
Definition: wingdi.h:364
FORCEINLINE PALETTEENTRY PALENTRY(BYTE r, BYTE g, BYTE b)
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
#define CW_USEDEFAULT
Definition: winuser.h:225
smooth NULL
Definition: ftsmooth.c:416
START_TEST(NtUserSelectPalette)
#define FORCEINLINE
Definition: ntbasedef.h:221
#define b
Definition: ke_i.h:79
GLboolean GLboolean g
Definition: glext.h:6204
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define DEFAULT_PALETTE
Definition: wingdi.h:912
ULONG RGBQUAD
Definition: precomp.h:50
#define TEST(x)
Definition: precomp.h:20
HPALETTE WINAPI CreatePalette(_In_reads_(_Inexpressible_(2 *sizeof(WORD)+plpal->palNumEntries *sizeof(PALETTEENTRY))) const LOGPALETTE *)
#define SetLastError(x)
Definition: compat.h:418
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
HBITMAP WINAPI CreateDIBitmap(_In_ HDC hdc, _In_opt_ const BITMAPINFOHEADER *pbmih, _In_ DWORD fdwInit, _In_opt_ const VOID *pvInit, _In_opt_ const BITMAPINFO *pbmi, _In_ UINT uUsage)
int ret
static const WCHAR L[]
Definition: oid.c:1250
uint32_t entry
Definition: isohybrid.c:63
unsigned char BYTE
Definition: xxhash.c:193
static HDC hDC
Definition: 3dtext.c:33
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define GetModuleHandle
Definition: winbase.h:3667
#define COLOR_BTNSHADOW
Definition: winuser.h:920
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
static HINSTANCE hinst
Definition: edit.c:551
static HBITMAP
Definition: button.c:44
#define DIB_RGB_COLORS
Definition: wingdi.h:366
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
#define WS_VISIBLE
Definition: pedump.c:620
HBRUSH WINAPI GetSysColorBrush(_In_ int)
#define BI_RGB
Definition: precomp.h:47
UINT WINAPI RealizePalette(_In_ HDC)
Definition: palette.c:138
#define printf
Definition: config.h:203