Identify multiple generated buttons

I am creating static fields 'Page' and buttons 'G' on click of a button '+'. So the fields 'Page' and buttons 'G' are generated at runtime onclick of button '+'. Now that I have multiple buttons 'G' which are clickable, how to identify on which button 'G' is clicked? They have each their own behavior. Thanks in advance.

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
case WM_CREATE: {
				CreateWindow (
	          		"button",
	          		"+",
	          		WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
	          		20,
	          		50,
	          		30,
	          		30,
	          		hwnd,
	          		(HMENU) 1000,
	          		((LPCREATESTRUCT) lParam)->hInstance,
	          		NULL
	        	);
break;
}
case WM_COMMAND: {
	        	wmId    = LOWORD(wParam);
	        	wmEvent = HIWORD(wParam);
				if(LOWORD(wParam) == 1000){
					std::string s = std::to_string(mypage+1);
					char const *pchar = s.c_str();
				CreateWindow (
					"static",
					"Page",
					WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
					20,
					100+mypage*175,
					130,
					170,
					hwnd,
					(HMENU) 1001,
					NULL,
					NULL
					);
				if(LOWORD(wParam) == 1000){
					CreateWindow (
					"button",
					"G",
					WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
					25,
					120+(mypage-1)*175,
					20,
					20,
					hwnd,
					(HMENU) 10001,
					NULL,
					NULL
					);
				}

				if(LOWORD(wParam) == 10001){
					if(mystack < 4){
						std::string gtr = " GTR";
						std::string mystrgtr = std::to_string(mynum+1);
						instrument = (mystrgtr.append(gtr)).c_str();
					CreateWindow (
					"button",
					instrument,
					WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
					25,
					145+30*mystack,
					95,
					30,
					hwnd,
					(HMENU) 10005,
					NULL,
					NULL
					);
					}
					mystack += 1;
				}
There’s a Windows Programming section on this forum.
@bchinfosieeuw, your question is basically why everyone will tell you to switch to C++.

Why, in the 21st century, anyone would write to the Windows API in C is quite a mystery. There really are no valid reasons anymore. All reasons are based on irrelevant objections or observations. Issues of efficiency and size are completely obliterated by the complexity of the work and modern computers this side of a 133 Mhz Pentium CPU.

One of the few exceptions to this attitude is when someone is writing a C++ library, like Qt or WxWidgets, or the older (and questionable choice) MFC or ATL. If this is really a study to merely understand the API as a path toward being able to work on such libraries, then I can understand.

As to your inquiry more specifically, the general notion is that if a window is created for the button, then a window received the input for the mouse clicks, which includes within that the notion of that window's ID, which is then forwarded to your code in the command parameters from which you identify the particular button.

Just saying that tells me an object should be made to wrap all of that into an identity that is much clearer, and it pains me to repeat that message but really, you're proving to yourself why it is true.

Imagine the joy you would experience if the button object merely called a function object or delegate for you as the result of being clicked. You'd be done.
Last edited on
Topic archived. No new replies allowed.