Parent/child focus button in WM_COMMAND

Having this code, the button "G" in WM_COMMAND associated with 10001 does not work anymore, because the parent/child focus does not resemble I think. Button "G" is a child of hwndscroll, not of hwnd. How to get this button working again?

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
case WM_VSCROLL: {
		       auto action = LOWORD(wParam);
		       HWND hScroll = (HWND)lParam;
		       int pos = -1;
		       if (action == SB_THUMBPOSITION || action == SB_THUMBTRACK) {
		           pos = HIWORD(wParam);
		       } else if (action == SB_LINEDOWN) {
		           pos = g_scrollY + 30;
		       } else if (action == SB_LINEUP) {
		           pos = g_scrollY - 30;
		       }
		       if (pos == -1)
		           break;
		       WCHAR buf[20];
		       SCROLLINFO si = { 0 };
		       si.cbSize = sizeof(SCROLLINFO);
		       si.fMask = SIF_POS;
		       si.nPos = pos;
		       si.nTrackPos = 0;
		       SetScrollInfo(hwnd, SB_VERT, &si, true);
		       GetScrollInfo(hwndscroll, SB_VERT, &si);
		       pos = si.nPos;
		       POINT pt;
		       pt.x = 0;
		       pt.y = pos - g_scrollY;
		       auto hdc = GetDC(hwndscroll);
		       LPtoDP(hdc, &pt, 1);
		       ReleaseDC(hwndscroll, hdc);
		       ScrollWindow(hwndscroll, 0, -pt.y, NULL, NULL);
		       g_scrollY = pos;
		       myredraw = true;
		       RedrawWindow(hwnd, &lprcUpdate, hrgnUpdate, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW);
		       break;
		   }

case WM_CREATE:


				hwndscroll = CreateWindow(
	        	        "static",  
	        	        "",  
						WS_CHILD | WS_VISIBLE | IDC_VSCROLLBAR,
	        	        0, 
	        	        120, 
	        	        180,
	        	        500, 
	        	        hwnd, 
	        	        (HMENU) 1002,
						((LPCREATESTRUCT) lParam ->hInstance, 
	        	        (PVOID) NULL 
	        	    );
				    RECT rc = { 0 };
				    GetClientRect(hwndscroll, &rc);
				    SCROLLINFO si = { 0 };
				    si.cbSize = sizeof(SCROLLINFO);
				    si.fMask = SIF_ALL;
				    si.nMin = 0;
				    si.nMax = 30 * 99 + 21;
				    si.nPage = (rc.bottom - rc.top);
				    si.nPos = 0;
				    si.nTrackPos = 0;
				    SetScrollInfo(hwnd, SB_VERT, &si, true);


case WM_COMMAND:
				if(LOWORD(wParam) == 1000){//"+"
					myhwnd = CreateWindow (
					"button",
					"G",
					WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
					25,
					25+(mypage-1)*175,
					20,
					20,
					hwndscroll,
					(HMENU) 10001,
					NULL,
					NULL
					);
				}
				if(LOWORD(wParam) == 10001){
Last edited on
https://en.wikipedia.org/wiki/Comparison_of_version-control_software
Once you're past the "homework" stage, where your programs are taking weeks of effort to work on, you NEED to invest time in understanding and using some kind of version control s/w.

Regular commits mean you can always get back to a known working state, and the ability to 'diff' between commits (or a commit and your work) allows you to see what edits causes the breakage.


General comments.
1. Don't mix spaces and tabs. It might look fine in your editor, but it can soon look a mess when you share it anywhere.

2. Your cases are WAY too long.
1
2
3
4
5
6
7
8
9
case WM_VSCROLL:
    doScroll();
    break;
case WM_CREATE:
    doCreate();
    break;
case WM_COMMAND:
    doCommandl();
    break;

Your create is missing a break statement, unless that's just part of your creative minimal code post.


Topic archived. No new replies allowed.