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 8 LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM); 9 10 int WINAPI 11 WinMain(HINSTANCE hInstance, 12 HINSTANCE hPrevInstance, 13 LPSTR lpszCmdLine, 14 int nCmdShow) 15 { 16 WNDCLASS wc; 17 MSG msg; 18 HWND hWnd; 19 20 wc.lpszClassName = "GradientClass"; 21 wc.lpfnWndProc = MainWndProc; 22 wc.style = CS_VREDRAW | CS_HREDRAW; 23 wc.hInstance = hInstance; 24 wc.hIcon = LoadIcon(NULL, (LPCTSTR)IDI_APPLICATION); 25 wc.hCursor = LoadCursor(NULL, (LPCTSTR)IDC_ARROW); 26 wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH); 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", 39 WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL, 40 0, 41 0, 42 CW_USEDEFAULT, 43 CW_USEDEFAULT, 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 { 63 TranslateMessage(&msg); 64 DispatchMessage(&msg); 65 } 66 67 //DeleteObject(tf); 68 69 return msg.wParam; 70 } 71 LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) 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 } 185