Buttons work but don't show up until clicked on.

I'm currently making a Flash Card Program and just got to making the GUI. Most of the windows have been set up and once done I will be adding the functionality of the program. My study window worked as a wrote it originality but something changed between then and now and I can't pinpoint it. There are two buttons and one static field that are no longer appearing when i switch to that window. The two buttons only appear once I have clicked on their location, they still work. The static field no longer appears though. How can I fix this?

P.S. There is a lot of code so if you don't want to be bothered turn back now!

Note - I won't include the card and deck cpp/h files. I hopefully commented out or removed everything relevant to those files.

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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#include <windows.h>
#include <fstream>
#include <iostream>

using namespace std;
WNDCLASSEX wc;
//Windows 
HWND hwndMain, hwndEdit, hwndEditMenu, hwndStudy, hwndEditAddCards, hwndEditRemoveCards, hwndEditDeckInfo, // windows 
	g_TextBox, g_CardMaker, g_Load, g_Save, g_Study, // hwndMain
	g_AddCard, g_RemoveCard, g_ChangeDeckInfo, g_ReturnToMainE, //hwndEditMenu
	g_CardNameField, g_CardDefField, g_CardExtraField, g_ReturnToMainS, g_CardNextButton, g_CardCounter, //hwndStudy
	g_AddCardsInfo; //hwndEditAddCards


MSG Msg;

void LoadDeck();
void SaveDeck();
void Update();

const char g_szClassName[] = "myWindowClass";

// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
	    case WM_COMMAND: 
			{
				if (LOWORD(wParam) == 1) {
					ShowWindow(hwndMain, SW_HIDE);
					ShowWindow(hwndEditMenu, SW_SHOW);
					return 0;
					//edditing the deck
				}
				if (LOWORD(wParam) == 2) {
					ShowWindow(hwndMain, SW_HIDE);
					ShowWindow(hwndStudy, SW_SHOW);
					ShowWindow(g_CardNextButton, SW_SHOW);
					return 0;
					//Study
				}
				if (LOWORD(wParam) == 3) {
					SaveDeck();
					return 0;
					//Save Current Deck
				}
				if (LOWORD(wParam) == 4) {
					//LoadDeck();
					Update();
					string str;
					//SetDlgItemInt(hwnd, 5,str, FALSE);
					return 0;
				}
				if (LOWORD(wParam) == 6) {
					ShowWindow(hwndEditMenu, SW_HIDE);
					ShowWindow(hwndEditAddCards, SW_SHOW);
				}
				if (LOWORD(wParam) == 10) {
					ShowWindow(hwndMain, SW_SHOW);
					ShowWindow(hwndEditMenu, SW_HIDE);
					//Update();
					return 0;
				}
				if (LOWORD(wParam) == 14) {
					//return from hwndStudy to hwndMain
					ShowWindow(hwndStudy, SW_HIDE);
					ShowWindow(hwndMain, SW_SHOW);
				}
				
			}
		break;
        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
        case WM_DESTROY:
            PostQuitMessage(0);
        break;
        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{

    //Step 1: Registering the Window Class
    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = 0;
    wc.lpfnWndProc   = WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+5);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = g_szClassName;
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, "Window Registration Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    // Step 2: Creating the Window
    hwndMain = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        g_szClassName,
        "FlashCards",
        WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU,
        CW_USEDEFAULT, CW_USEDEFAULT, 320,200,
        NULL, NULL, hInstance, NULL);

	hwndEditMenu = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        g_szClassName,
        "EditDeck",
        WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU,
        CW_USEDEFAULT, CW_USEDEFAULT, 170,242,
        hwndMain , NULL, hInstance, NULL);

	hwndStudy = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        g_szClassName,
        "Study",
        WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU,
        CW_USEDEFAULT, CW_USEDEFAULT, 420,300,
        hwndMain , NULL, hInstance, NULL);

	hwndEditAddCards = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        g_szClassName,
        "Add Cards",
        WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU,
        CW_USEDEFAULT, CW_USEDEFAULT, 420,300,
        hwndMain , NULL, hInstance, NULL);

	hwndEditRemoveCards = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        g_szClassName,
        "Remove Cards",
        WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU,
        CW_USEDEFAULT, CW_USEDEFAULT, 420,300,
        hwndMain , NULL, hInstance, NULL);

	hwndEditDeckInfo = CreateWindowEx(
        WS_EX_CLIENTEDGE,
        g_szClassName,
        "Change Deck Info",
        WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU,
        CW_USEDEFAULT, CW_USEDEFAULT, 420,300,
        hwndMain , NULL, hInstance, NULL);

	//Main Window (hwnd)
	g_CardMaker = CreateWindowEx(0, "BUTTON", "Edit Deck", 
        WS_CHILD | WS_VISIBLE, 0,0, 150, 50, hwndMain, 
        (HMENU) 1, hInstance, NULL);

	g_Study = CreateWindowEx(0, "BUTTON", "Start Studying!", 
        WS_CHILD | WS_VISIBLE, 150, 0, 150, 50, hwndMain, 
        (HMENU) 2, hInstance, NULL);

	g_Save = CreateWindowEx(0, "BUTTON", "Save Deck", 
        WS_CHILD | WS_VISIBLE, 0, 50, 150, 50, hwndMain, 
        (HMENU) 3, hInstance, NULL);

	g_Load = CreateWindowEx(0, "BUTTON", "Load Deck", 
        WS_CHILD | WS_VISIBLE, 150, 50, 150, 50, hwndMain, 
        (HMENU) 4, hInstance, NULL);

	g_TextBox = CreateWindowEx(0, "STATIC" , "",
         WS_CHILD | WS_VISIBLE, 0, 100, 300, 100, hwndMain,
		 (HMENU) 5, hInstance, NULL); // Changed (HMENU) 1 from Null

	//EditDeckWindow (hwndEdit)

	g_AddCard = CreateWindowEx(0, "BUTTON", "Add Cards", 
        WS_CHILD | WS_VISIBLE, 0,0, 150, 50, hwndEditMenu, 
        (HMENU) 6, hInstance, NULL);

	g_RemoveCard = CreateWindowEx(0, "BUTTON", "Remove Cards", 
        WS_CHILD | WS_VISIBLE, 0, 50, 150, 50, hwndEditMenu, 
        (HMENU) 7, hInstance, NULL);

	g_ChangeDeckInfo = CreateWindowEx(0, "BUTTON", "Change Name/Desc", 
        WS_CHILD | WS_VISIBLE, 0,100, 150, 50, hwndEditMenu, 
        (HMENU) 8, hInstance, NULL);
	
	g_ReturnToMainE = CreateWindowEx(0, "BUTTON", "Return to Main", 
        WS_CHILD | WS_VISIBLE, 0,150, 150, 50, hwndEditMenu, 
        (HMENU) 9, hInstance, NULL);

	//StudyDeckWindow (hwndStudy)
	g_CardNextButton = CreateWindowEx(0, "BUTTON", "Next Card", 
        WS_CHILD | WS_VISIBLE, 150, 225, 100, 30, hwndStudy, 
        (HMENU) 13, hInstance, NULL);
	//ShowWindow(g_CardNextButton, SW_SHOW);

	g_ReturnToMainS = CreateWindowEx(0, "BUTTON", "Return to Main", 
        WS_CHILD | WS_VISIBLE, 270, 225, 100, 30, hwndStudy, 
        (HMENU) 14, hInstance, NULL);

	g_CardCounter = CreateWindowEx(0, "STATIC" , "4/6",
         WS_CHILD | WS_VISIBLE, 50, 232, 60, 40, hwndStudy,
		 (HMENU) 15, hInstance, NULL);

	g_CardNameField = g_TextBox = CreateWindowEx(0, "STATIC" , "name",
         WS_CHILD | WS_VISIBLE, 0, 0, 400, 20, hwndStudy,
		 (HMENU) 10, hInstance, NULL);

	g_CardDefField = g_TextBox = CreateWindowEx(0, "STATIC" , "def",
         WS_CHILD | WS_VISIBLE, 0, 21, 400, 200, hwndStudy,
		 (HMENU) 11, hInstance, NULL);

	g_CardExtraField = g_TextBox = CreateWindowEx(0, "STATIC" , "",
         WS_CHILD | WS_VISIBLE, 0, 222, 400, 40, hwndStudy,
		 (HMENU) 12, hInstance, NULL);

	//EditMenuAddCardsWindow (hwndEditAddCards)

	g_AddCardsInfo = CreateWindowEx(0, "STATIC" , "",
         WS_CHILD | WS_VISIBLE, 0, 222, 400, 40, hwndStudy,
		 (HMENU) 16, hInstance, NULL);



    if(hwndMain == NULL)
    {
        MessageBox(NULL, "Window Creation Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

    ShowWindow(hwndMain, nCmdShow);
    UpdateWindow(hwndMain);

    // Step 3: The Message Loop
    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
    return Msg.wParam;
}
You should, after creation (CreateWindow), by order:

1. Show all the little windows (Buttons and so on)
2. Show the window itself.

It will look like:

1
2
3
4
5
6
// All your CreateWindowEx...
ShowWindow(g_CardMaker,SW_SHOW);
ShowWindow(g_Study,SW_SHOW);
//... and so on. Do NOT use nCmdShow for these windows.
ShowWindow(hwndMain,nCmdShow); // But do for this window.
UpdateWindow(hwndMain);
Like this right?

1
2
ShowWindow(g_ReturnToMainS, SW_SHOW);
ShowWindow(g_CardNextButton, SW_SHOW);


Still a no go. It worked before, I just have no idea what I changed.
Last edited on
OK I feel like an idiot, a dumb mother trucker.

1
2
3
4
5
6
7
8
9
	g_CardExtraField = g_TextBox = CreateWindowEx(0, "STATIC" , "",
         WS_CHILD | WS_VISIBLE, 0, 222, 400, 40, hwndStudy,
		 (HMENU) 12, hInstance, NULL);

	//EditMenuAddCardsWindow (hwndEditAddCards)

	g_AddCardsInfo = CreateWindowEx(0, "STATIC" , "",
         WS_CHILD | WS_VISIBLE, 0, 222, 400, 40, hwndStudy,
		 (HMENU) 16, hInstance, NULL);


I have TWO static fields doing the same thing. After I fixed that I replaced the buttons after it and it overlapped fine. I had it that why originality but I copied the top static field so I didn't have to write it again for the next window. Thanks anyway man.
Topic archived. No new replies allowed.