ReactOS 0.4.15-dev-5664-g3bf4ef6
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;
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,
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);
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
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
150printf("nearest = 0x%x\n", GetNearestColor(hCompDC, RGB(120,100,110)));
151#endif
152
153}
static HDC hDC
Definition: 3dtext.c:33
FORCEINLINE PALETTEENTRY PALENTRY(BYTE r, BYTE g, BYTE b)
#define START_TEST(x)
Definition: atltest.h:75
HWND hWnd
Definition: settings.c:17
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define SetLastError(x)
Definition: compat.h:752
#define BI_RGB
Definition: precomp.h:47
#define RGB(r, g, b)
Definition: precomp.h:62
ULONG RGBQUAD
Definition: precomp.h:50
#define printf
Definition: freeldr.h:94
pKey DeleteObject()
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
Definition: glext.h:10929
GLboolean GLboolean g
Definition: glext.h:6204
uint32_t entry
Definition: isohybrid.c:63
#define b
Definition: ke_i.h:79
#define ASSERT(a)
Definition: mode.c:44
#define TEST(x)
Definition: precomp.h:20
static HBITMAP
Definition: button.c:44
static HINSTANCE hinst
Definition: edit.c:551
static HDC
Definition: imagelist.c:92
__kernel_entry W32KAPI HBITMAP APIENTRY NtGdiSelectBitmap(_In_ HDC hdc, _In_ HBITMAP hbm)
#define L(x)
Definition: ntvdm.h:50
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define WS_VISIBLE
Definition: pedump.c:620
& rect
Definition: startmenu.cpp:1413
int ret
#define FORCEINLINE
Definition: wdftypes.h:67
HPALETTE WINAPI NtUserSelectPalette(HDC hDC, HPALETTE hpal, BOOL ForceBackground)
Definition: windc.c:1034
#define ZeroMemory
Definition: winbase.h:1670
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
#define GetModuleHandle
Definition: winbase.h:3698
#define DIB_RGB_COLORS
Definition: wingdi.h:367
HGDIOBJ WINAPI GetStockObject(_In_ int)
UINT WINAPI RealizePalette(_In_ HDC)
Definition: palette.c:138
#define DEFAULT_PALETTE
Definition: wingdi.h:913
HPALETTE WINAPI CreatePalette(_In_reads_(_Inexpressible_(2 *sizeof(WORD)+plpal->palNumEntries *sizeof(PALETTEENTRY))) const LOGPALETTE *)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
COLORREF WINAPI GetNearestColor(_In_ HDC, _In_ COLORREF)
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
#define CBM_INIT
Definition: wingdi.h:365
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 WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
HBRUSH WINAPI GetSysColorBrush(_In_ int)
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
HDC WINAPI GetDC(_In_opt_ HWND)
#define CreateWindowW(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4306
#define COLOR_BTNSHADOW
Definition: winuser.h:924
#define CW_USEDEFAULT
Definition: winuser.h:225
BOOL WINAPI DestroyWindow(_In_ HWND)
unsigned char BYTE
Definition: xxhash.c:193