2d char array in win32?

hello, I'm trying to create a simple game in win32, but the problem I have is don't know how to convert or initialize 2d char array the right way, I have already done this on console, but not in win32:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
char Map1[10][10] = {"#########",
                     "#@      #",
                     "#       #",
                     "#       #",
                     "#       #",
                     "#       #",
                     "#       #",
                     "#       #",
                     "#       #",
                     "#########" };
HWND Map[10][10];
... //WinProc
case WM_CREATE:
   for (int i=0; i<10; i++)
   {
      for (int j=0; j<10; j++)
      {
         Map[i][j]=CreateWindow("STATIC", Map1[i][j], WS_VISIBLE | WS_CHILD, 
                                i*8,j*16,8,16, hwnd, NULL, NULL, NULL);
      }
   }
break;
Not sure if this has any effect on it, but you do realize that your 2d array is actually filled in for 9x10 right?

You have 9 chars wide
10 chars for height

Just throwing that out there
Last edited on
@Pindrought
Actually, it is 10x10. I'll show you the first row to show you why:
1
2
3
"#########";
// is the same thing as the following (null terminator implicitly added):
{'#', '#', #', '#', '#', '#', '#', '#', '#', '/0'}; 


@Waras
I can see that you are making a game in Win32, and thats good - you've learned that the console is bad for games. However, Win32 is similarly convulted, but there are other options you can use over simply creating your map the same as you might with the console.

If you wish to make a game, the easiest option would be to use something like SDL, SFML, or if you're feeling particularly low-level, OpenGL or DirectX. Modifying controls at runtime is fairly inefficient, and not suitable for a game (unless its particularly simple).
Last edited on
@NT3
thanks for reply, but I really want to learn win32 first so I could create some programs for later use.

ok after searching around so far I have got this:
1
2
3
4
5
6
7
8
9
10
case WM_PAINT:
   hdc = BeginPaint(hwnd, &ps);
   hFont = (HFONT)GetStockObject(SYSTEM_FIXED_FONT);
   SelectObject(hdc, hFont);
   for (int j=0; j<10; j++)
   {
      TextOut(hdc, 0, j*16, Map1[j], 10);
   }
   EndPaint(hwnd, &ps);
break;

it just dispays the char array, but what I wanted is convert char array to Objects and use them later(eg. moving things around).
here I HAD to change font so it could display correctly and fonts can only be used in WM_PAINT, which means I will have to refresh the whole window, so is there any other way around, so I could use WM_CREATE, like in the first post?
Topic archived. No new replies allowed.