ReactOS  0.4.13-dev-249-gcba1a2f
gradient.c
Go to the documentation of this file.
1 #include <windows.h>
2 #include <stdio.h>
3 #include <string.h>
4 
5 BOOL WINAPI GdiGradientFill( HDC hdc, TRIVERTEX *vert_array, ULONG nvert,
6  void * grad_array, ULONG ngrad, ULONG mode );
7 
9 
10 int WINAPI
12  HINSTANCE hPrevInstance,
13  LPSTR lpszCmdLine,
14  int nCmdShow)
15 {
16  WNDCLASS wc;
17  MSG msg;
18  HWND hWnd;
19 
20  wc.lpszClassName = "GradientClass";
23  wc.hInstance = hInstance;
27  wc.lpszMenuName = NULL;
28  wc.cbClsExtra = 0;
29  wc.cbWndExtra = 0;
30  if (RegisterClass(&wc) == 0)
31  {
32  fprintf(stderr, "RegisterClass failed (last error 0x%lX)\n",
33  GetLastError());
34  return(1);
35  }
36 
37  hWnd = CreateWindow("GradientClass",
38  "GradientFill Test",
40  0,
41  0,
44  NULL,
45  NULL,
46  hInstance,
47  NULL);
48  if (hWnd == NULL)
49  {
50  fprintf(stderr, "CreateWindow failed (last error 0x%lX)\n",
51  GetLastError());
52  return(1);
53  }
54 
55  //tf = CreateFontA(14, 0, 0, TA_BASELINE, FW_NORMAL, FALSE, FALSE, FALSE,
56  // ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
57  // DEFAULT_QUALITY, FIXED_PITCH|FF_DONTCARE, "Timmons");
58 
59  ShowWindow(hWnd, nCmdShow);
60 
61  while(GetMessage(&msg, NULL, 0, 0))
62  {
65  }
66 
67  //DeleteObject(tf);
68 
69  return msg.wParam;
70 }
72 {
73  HDC hDC;
74 
75  switch(msg)
76  {
77  case WM_PAINT:
78  {
79  PAINTSTRUCT ps;
80  TRIVERTEX vert [5] ;
81  GRADIENT_TRIANGLE gTRi[3];
82  GRADIENT_RECT gRect[2];
83  hDC = BeginPaint(hWnd, &ps);
84 
85  vert [0] .x = 0;
86  vert [0] .y = 0;
87  vert [0] .Red = 0xff00;
88  vert [0] .Green = 0xff00;
89  vert [0] .Blue = 0xff00;
90  vert [0] .Alpha = 0x0000;
91 
92  vert [1] .x = 300;
93  vert [1] .y = 20;
94  vert [1] .Red = 0x0000;
95  vert [1] .Green = 0x0000;
96  vert [1] .Blue = 0xff00;
97  vert [1] .Alpha = 0x0000;
98 
99  vert [2] .x = 100;
100  vert [2] .y = 200;
101  vert [2] .Red = 0xff00;
102  vert [2] .Green = 0x0000;
103  vert [2] .Blue = 0x0000;
104  vert [2] .Alpha = 0x0000;
105 
106  vert [3] .x = 250;
107  vert [3] .y = 300;
108  vert [3] .Red = 0x8000;
109  vert [3] .Green = 0x8000;
110  vert [3] .Blue = 0x0000;
111  vert [3] .Alpha = 0x0000;
112 
113  vert [4] .x = 325;
114  vert [4] .y = 300;
115  vert [4] .Red = 0x0000;
116  vert [4] .Green = 0xff00;
117  vert [4] .Blue = 0x0000;
118  vert [4] .Alpha = 0x0000;
119 
120  gTRi[0].Vertex1 = 0;
121  gTRi[0].Vertex2 = 1;
122  gTRi[0].Vertex3 = 2;
123 
124  gTRi[1].Vertex1 = 1;
125  gTRi[1].Vertex2 = 2;
126  gTRi[1].Vertex3 = 3;
127 
128  gTRi[2].Vertex1 = 1;
129  gTRi[2].Vertex2 = 3;
130  gTRi[2].Vertex3 = 4;
131 
132  GdiGradientFill(hDC,vert,5,&gTRi,3,GRADIENT_FILL_TRIANGLE);
133 
134 
135  vert [0] .x = 5;
136  vert [0] .y = 200;
137  vert [0] .Red = 0x0000;
138  vert [0] .Green = 0x0000;
139  vert [0] .Blue = 0x0000;
140  vert [0] .Alpha = 0x0000;
141 
142  vert [1] .x = 90;
143  vert [1] .y = 240;
144  vert [1] .Red = 0x0000;
145  vert [1] .Green = 0x0000;
146  vert [1] .Blue = 0xff00;
147  vert [1] .Alpha = 0x0000;
148 
149  vert [2] .x = 5;
150  vert [2] .y = 245;
151  vert [2] .Red = 0x0000;
152  vert [2] .Green = 0x0000;
153  vert [2] .Blue = 0x0000;
154  vert [2] .Alpha = 0x0000;
155 
156  vert [3] .x = 90;
157  vert [3] .y = 300;
158  vert [3] .Red = 0x0000;
159  vert [3] .Green = 0x0000;
160  vert [3] .Blue = 0xff00;
161  vert [3] .Alpha = 0x0000;
162 
163  gRect[0].UpperLeft = 0;
164  gRect[0].LowerRight = 1;
165 
166  gRect[1].UpperLeft = 2;
167  gRect[1].LowerRight = 3;
168 
169  GdiGradientFill(hDC,vert,4,&gRect[0],1,GRADIENT_FILL_RECT_H);
170  GdiGradientFill(hDC,vert,4,&gRect[1],1,GRADIENT_FILL_RECT_V);
171 
172  EndPaint(hWnd, &ps);
173  break;
174  }
175 
176  case WM_DESTROY:
177  PostQuitMessage(0);
178  break;
179 
180  default:
181  return DefWindowProc(hWnd, msg, wParam, lParam);
182  }
183  return 0;
184 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
ULONG UpperLeft
Definition: wingdi.h:2783
ULONG LowerRight
Definition: wingdi.h:2784
#define DispatchMessage
Definition: winuser.h:5631
BOOL WINAPI TranslateMessage(_In_ const MSG *)
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define CreateWindow
Definition: winuser.h:5620
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
static HDC
Definition: imagelist.c:92
#define CALLBACK
Definition: compat.h:27
HWND hWnd
Definition: settings.c:17
int cbClsExtra
Definition: winuser.h:3118
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define CS_HREDRAW
Definition: winuser.h:648
LPCSTR lpszMenuName
Definition: winuser.h:3124
#define IDI_APPLICATION
Definition: winuser.h:699
UINT_PTR WPARAM
Definition: windef.h:207
HBRUSH hbrBackground
Definition: winuser.h:3123
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
char * LPSTR
Definition: xmlstorage.h:182
WPARAM wParam
Definition: combotst.c:138
LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM)
Definition: gradient.c:71
int cbWndExtra
Definition: winuser.h:3119
HINSTANCE hInstance
Definition: charmap.c:20
LONG y
Definition: wingdi.h:2763
unsigned int BOOL
Definition: ntddk_ex.h:94
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
HCURSOR hCursor
Definition: winuser.h:3122
#define CW_USEDEFAULT
Definition: winuser.h:225
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
#define GRAY_BRUSH
Definition: wingdi.h:897
#define DefWindowProc
Definition: ros2win.h:31
#define WM_DESTROY
Definition: winuser.h:1591
#define CS_VREDRAW
Definition: winuser.h:653
LONG x
Definition: wingdi.h:2762
#define WINAPI
Definition: msvc.h:8
#define WS_HSCROLL
Definition: pedump.c:628
#define WM_PAINT
Definition: winuser.h:1602
HDC hdc
Definition: main.c:9
LPCSTR lpszClassName
Definition: winuser.h:3125
GLenum mode
Definition: glext.h:6217
#define LoadCursor
Definition: winuser.h:5678
UINT style
Definition: winuser.h:3116
static HDC hDC
Definition: 3dtext.c:33
COLOR16 Alpha
Definition: wingdi.h:2767
HINSTANCE hInstance
Definition: winuser.h:3120
BOOL WINAPI GdiGradientFill(HDC hdc, TRIVERTEX *vert_array, ULONG nvert, void *grad_array, ULONG ngrad, ULONG mode)
unsigned int UINT
Definition: ndis.h:50
#define WS_VSCROLL
Definition: pedump.c:627
#define GetMessage
Definition: winuser.h:5656
WNDPROC lpfnWndProc
Definition: winuser.h:3117
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
COLOR16 Red
Definition: wingdi.h:2764
COLOR16 Blue
Definition: wingdi.h:2766
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
unsigned int ULONG
Definition: retypes.h:1
FILE * stderr
COLOR16 Green
Definition: wingdi.h:2765
#define RegisterClass
Definition: winuser.h:5702
#define LoadIcon
Definition: winuser.h:5679
LONG_PTR LRESULT
Definition: windef.h:209
LPARAM lParam
Definition: combotst.c:139
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
HICON hIcon
Definition: winuser.h:3121
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
Definition: gradient.c:11