C And Windows API: Using Tab Control And Detecting Tab Change
I am working on a small program in C and Windows API. I have made a tab control and two tabs in it. My questions are:
- Is my code fine? I have added some static controls bu开发者_高级运维t they do not hide when I change tab. I tried making tab control their parent but no help. For now, the main window is their parent(also the parent for tab control)
- If my approach is fine, how can I hide the controls when tab is switched?
- I read somewhere that a good approach is to make a dialog window that is parent for all other controls and hide it when needed? If I need to use that, can you please tell me how or direct me to a tutorial?
Code:
// Tab Control Declaration
hTab = CreateWindow(WC_TABCONTROL, NULL, WS_CHILD | WS_VISIBLE,
10, 10, 765, 545, hwndq, (HMENU) 1, h_hinst, NULL);
// Tab 1 : See Student Info
tie.mask = TCIF_TEXT;
tie.pszText = TEXT("Student Info");
count = SendMessage(hTab, TCM_GETITEMCOUNT, 0, 0);
SendMessage(hTab, TCM_INSERTITEM, count, (LPARAM) (LPTCITEM) &tie);
// Tab 2 : Make A Question File
tie.mask = TCIF_TEXT;
tie.pszText = TEXT("Question Maker");
count = SendMessage(hTab, TCM_GETITEMCOUNT, 0, 0);
SendMessage(hTab, TCM_INSERTITEM, count, (LPARAM) (LPTCITEM) &tie);
// STATIC CONTROLS
// These will not change at runtime
CreateWindow(TEXT("STATIC"), TEXT("Enter Student Id:"),
WS_CHILD | WS_VISIBLE | WS_GROUP | SS_LEFT,
110, 65, 200, 20,
hwndq, (HMENU) 0, NULL, NULL);
CreateWindow(TEXT("STATIC"), TEXT("Student Name:"),
WS_CHILD | WS_VISIBLE | SS_LEFT,
110, 135, 200, 20,
hwndq, (HMENU) 0, NULL, NULL);
CreateWindow(TEXT("STATIC"), TEXT("Tests Taken:"),
WS_CHILD | WS_VISIBLE | SS_LEFT,
110, 175, 200, 20,
hwndq, (HMENU) 0, NULL, NULL);
CreateWindow(TEXT("STATIC"), TEXT("Question Answered:"),
WS_CHILD | WS_VISIBLE | SS_LEFT,
110, 215, 200, 20,
hwndq, (HMENU) 0, NULL, NULL);
CreateWindow(TEXT("STATIC"), TEXT("Correct Answers:"),
WS_CHILD | WS_VISIBLE | SS_LEFT,
110, 255, 200, 20,
hwndq, (HMENU) 0, NULL, NULL);
CreateWindow(TEXT("STATIC"), TEXT("Incorrect Answers:"),
WS_CHILD | WS_VISIBLE | SS_LEFT,
110, 295, 200, 20,
hwndq, (HMENU) 0, NULL, NULL);
CreateWindow(TEXT("STATIC"), TEXT("Score In Last Test:"),
WS_CHILD | WS_VISIBLE | SS_LEFT,
110, 335, 200, 20,
hwndq, (HMENU) 0, NULL, NULL);
CreateWindow(TEXT("STATIC"), TEXT("Overall Score:"),
WS_CHILD | WS_VISIBLE | SS_LEFT,
110, 375, 200, 20,
hwndq, (HMENU) 0, NULL, NULL);
// DYNAMIC CONTROLS
// They change at runtime to display/accept data
st[0].name = "Demo";
st[0].tests_taken = "0";
st[0].q_ans = "0";
st[0].q_cor = "0";
st[0].q_inc = "0";
st[0].r_score = "0";
st[0].t_score = "0";
CreateWindow(TEXT("STATIC"), st[0].name,
WS_CHILD | WS_VISIBLE | WS_GROUP | SS_LEFT,
475, 135, 200, 20,
hwndq, (HMENU) 0, NULL, NULL);
CreateWindow(TEXT("STATIC"), st[0].tests_taken,
WS_CHILD | WS_VISIBLE | SS_LEFT,
475, 175, 200, 20,
hwndq, (HMENU) 0, NULL, NULL);
CreateWindow(TEXT("STATIC"), st[0].q_ans,
WS_CHILD | WS_VISIBLE | SS_LEFT,
475, 215, 200, 20,
hwndq, (HMENU) 0, NULL, NULL);
CreateWindow(TEXT("STATIC"), st[0].q_cor,
WS_CHILD | WS_VISIBLE | SS_LEFT,
475, 255, 200, 20,
hwndq, (HMENU) 0, NULL, NULL);
CreateWindow(TEXT("STATIC"), st[0].q_inc,
WS_CHILD | WS_VISIBLE | SS_LEFT,
475, 295, 200, 20,
hwndq, (HMENU) 0, NULL, NULL);
CreateWindow(TEXT("STATIC"), st[0].r_score,
WS_CHILD | WS_VISIBLE | SS_LEFT,
475, 335, 200, 20,
hwndq, (HMENU) 0, NULL, NULL);
CreateWindow(TEXT("STATIC"), st[0].t_score,
WS_CHILD | WS_VISIBLE | SS_LEFT,
475, 375, 200, 20,
hwndq, (HMENU) 0, NULL, NULL);
break;
精彩评论