Receiving messages from child button

Hello. I am trying to make a level editor for a game me and a group of students are making. At the moment I am trying to create a level editor for the game. I have set up a new project that runs the game in a child window on my main window. That all works fine.
My problem is that I have buttons on another child window I have created that I cannot figure out how to recieve messages from them. Here is what i have so far:

1
2
3
4
5
6
7
8
#define ID_WALKON 201

_hSpawn = CreateWindowEx(WS_EX_WINDOWEDGE, WC_DIALOG, 0, WS_VISIBLE | WS_BORDER | WS_CHILD, 0, _height-(_height/3)-3, _width/3*2, _height/3-80, _hWnd, (HMENU)SPAWNWINDOW, _hInst, 0);
//Walk on Objects Button
	_hWalkOn = CreateWindow("BUTTON", "Walk On",
                                     BS_PUSHBUTTON | BS_NOTIFY | WS_CHILD | WS_VISIBLE, 5, 30, 100, 25, 
                                     _hSpawn, (HMENU)ID_WALKON, _hInst, NULL);

Thats the creation of my child window and button. If there is anyone out there who knows what to do or can link me to appropriate documentation I would be eternally greatful :D
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <windows.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK PanelProc(HWND, UINT, WPARAM, LPARAM);
void RegisterRedPanel(void);
void RegisterBluePanel(void);


int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
			LPSTR lpCmdLine, int nCmdShow )
{
  MSG  msg ;
  WNDCLASS wc = {0};
  wc.lpszClassName = TEXT( "Windows" );
  wc.hInstance     = hInstance ;
  wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  wc.lpfnWndProc   = WndProc ;
  wc.hCursor       = LoadCursor(0,IDC_ARROW);

  RegisterClass(&wc);
  CreateWindow( wc.lpszClassName, TEXT("Windows"),
                WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                100, 100, 250, 180, 0, 0, hInstance, 0);

  while( GetMessage(&msg, NULL, 0, 0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
  return (int) msg.wParam;
}

LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{


  switch(msg)
  {
    case WM_CREATE:
    {

	RegisterRedPanel();
	CreateWindow(TEXT("RedPanel"), NULL,
		WS_CHILD | WS_VISIBLE,
		20, 20, 80, 80,
		hwnd, (HMENU) 1, NULL, NULL);

	RegisterBluePanel();
	CreateWindow(TEXT("BluePanel"), NULL,
		WS_CHILD | WS_VISIBLE,
		120, 20, 80, 80,
		hwnd, (HMENU) 2, NULL, NULL);

	break;
    }

    case WM_DESTROY:
    {
        PostQuitMessage(0);
        break;
    }
  }
  return DefWindowProc(hwnd, msg, wParam, lParam);
}

LRESULT CALLBACK PanelProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{

  switch(msg)
  {
    case WM_LBUTTONUP:
    {
        Beep(50, 40);
        break;
    }
  }
  return DefWindowProc(hwnd, msg, wParam, lParam);
}


void RegisterRedPanel(void) {

  HBRUSH hbrush = CreateSolidBrush(RGB(255, 0, 0));

  WNDCLASS rwc = {0};
  rwc.lpszClassName = TEXT( "RedPanel" );
  rwc.hbrBackground = hbrush;
  rwc.lpfnWndProc   = PanelProc ;
  rwc.hCursor       = LoadCursor(0,IDC_ARROW);
  RegisterClass(&rwc);

}

void RegisterBluePanel(void) {

  HBRUSH hbrush = CreateSolidBrush(RGB(0, 0, 255));

  WNDCLASS rwc = {0};
  rwc.lpszClassName = TEXT( "BluePanel" );
  rwc.hbrBackground = hbrush;
  rwc.lpfnWndProc   = PanelProc ;
  rwc.hCursor       = LoadCursor(0,IDC_ARROW);
  RegisterClass(&rwc);

}


Source
http://www.zetcode.com/tutorials/winapi/firststeps/

Hope that's what you need :)
Topic archived. No new replies allowed.