array problem

when using setpixel (I know don't start criticizing me about it)
I cant do this

SetPixel(hdc, x[co], y[co], c);

it says expression must have pointer to object type I know I have posted this before twice but one forum I accidentally said was solved another people thaught I was trying to declare a array with a changing amount of places but no I want the co-th spot in the array
You haven't really given enough info here.

But this program works (I'm assuming the standard WinMain which creates a black window with a white background brush, etc.)

The interpolateColors() function comes from here:

4 Colors gradient logic needed
http://stackoverflow.com/questions/2977196/4-colors-gradient-logic-needed

I tweaked it to use a C array rather than a vector as I was being lazy with the toy program...)

Andy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    static const int w = 150;
    static const int h = 150;
    static COLORREF s_pixels[w * h] = {0};

    switch (uMsg)
    {
        case WM_CREATE: {
            COLORREF crefs[] = {
                RGB(255, 0, 0),
                RGB(0, 255, 0),
                RGB(0, 0, 255),
                RGB(0, 0,   0)
            };

            for(int i = 0; i < w; ++i) {
                for(int j = 0; j < h; ++j) {
                    s_pixels[i * w + j] = interpolateColors(crefs, w, h, i, j);
                }
            }
        }
        break;

        case WM_DESTROY: {
            PostQuitMessage(0);
        }
        break;

        case WM_PAINT: {
            PAINTSTRUCT ps = {0};
            HDC hdc = BeginPaint(hWnd, &ps);

            int x = 50;
            int y = 50;

            for(int i = 0; i < w; ++i) {
                for(int j = 0; j < h; ++j) {
                    COLORREF cref3 = s_pixels[i * w + j];
                    SetPixel(hdc, x + i, y + j, cref3);
                }
            }

            EndPaint(hWnd, &ps);
        }
        break;

        default:
            return DefWindowProc(hWnd, uMsg, wParam, lParam);
    }
    return 0;
}

Last edited on
please also guide in easy coding of array
please also guide in easy coding of array

Sorry, that's too vague a request.

If you have a specific problem, please post an illustrative code fragment.

Andy
Last edited on
Topic archived. No new replies allowed.