Hi there,
I am creating an application where one dialog box has a tab control with multiple tabs. I am having difficulties setting it up and would appreciate anyone who can shine some light on the issue. The program runs perfectly with the other controls but when one of my DialogProcs are called via a pushbutton control I get an unhandled exception error. Below is the code for your perusal:
<br />
<br />
BOOL CALLBACK OptionsDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)<br />
{<br />
HWND tab1_hwnd, tab2_hwnd, CurrentTabHwnd;<br />
int CurrentTabIndex;<br />
HWND hwndTab;<br />
<br />
switch(msg)<br />
{<br />
case WM_INITDIALOG:<br />
{<br />
<br />
LPSTR tab1_title = "General";<br />
LPSTR tab2_title = "Advanced";<br />
<br />
LPINITCOMMONCONTROLSEX tabctl;<br />
<br />
tabctl->dwSize = sizeof(tabctl);<br />
tabctl->dwICC = ICC_TAB_CLASSES;<br />
<br />
InitCommonControlsEx(tabctl);<br />
<br />
hwndTab = GetDlgItem(hwnd,IDC_TAB1);<br />
<br />
TCITEM* ItemStruct;<br />
<br />
ItemStruct->mask = TCIF_TEXT;<br />
ItemStruct->pszText = tab1_title;<br />
ItemStruct->cchTextMax = sizeof(tab1_title);<br />
ItemStruct->iImage = 0;<br />
ItemStruct->lParam = 0;<br />
<br />
SendMessage(hwndTab, TCM_INSERTITEM, 0, (LPARAM)ItemStruct);<br />
<br />
ItemStruct->pszText = tab2_title;<br />
ItemStruct->cchTextMax = sizeof(tab2_title);<br />
<br />
SendMessage(hwndTab, TCM_INSERTITEM, 1, (LPARAM)ItemStruct);<br />
<br />
tab1_hwnd = CreateDialogParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_OPTIONS_GENERAL), hwndTab, General_OptionsDialogProc, 0);<br />
tab2_hwnd = CreateDialogParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_OPTIONS_ADVANCED), hwndTab, Advanced_OptionsDialogProc, 0);<br />
<br />
CurrentTabIndex = 0;<br />
<br />
if(!ShowWindow(tab1_hwnd,SW_SHOWDEFAULT))<br />
MessageBox(hwnd, "Could not initiate InitCommonControlsEx command", "Error:", MB_OK | MB_ICONINFORMATION);<br />
<br />
<br />
<br />
}<br />
break;<br />
<br />
case WM_NOTIFY:<br />
{<br />
switch(LOWORD(wParam)){<br />
case TCN_SELCHANGE:<br />
{<br />
ShowWindow(CurrentTabHwnd, SW_HIDE);<br />
CurrentTabIndex = SendMessage(hwndTab, TCM_GETCURSEL, 0, 0);<br />
<br />
switch(CurrentTabIndex){<br />
case 0:<br />
ShowWindow(tab1_hwnd,SW_SHOWDEFAULT);<br />
CurrentTabHwnd = tab1_hwnd;<br />
break;<br />
case 1:<br />
ShowWindow(tab2_hwnd,SW_SHOWDEFAULT);<br />
CurrentTabHwnd = tab1_hwnd;<br />
break;<br />
}<br />
<br />
<br />
<br />
}<br />
break;<br />
default:<br />
return FALSE; <br />
}<br />
<br />
}<br />
break;<br />
<br />
case WM_COMMAND:<br />
{<br />
<br />
switch(LOWORD(wParam)){<br />
<br />
case IDOK:<br />
EndDialog(hwnd,0);<br />
break;<br />
case IDCANCEL:<br />
EndDialog(hwnd,0);<br />
break;<br />
}<br />
<br />
}<br />
break;<br />
case WM_CLOSE:<br />
EndDialog(hwnd, 0);<br />
break;<br />
<br />
default:<br />
return FALSE;<br />
}<br />
return 0;<br />
}<br />
<br />
<br />
Running it through my debugger it appears that the program experiences an error at this location:
<br />
tabctl->dwSize = sizeof(tabctl);<br />
tabctl->dwICC = ICC_TAB_CLASSES;<br />
I have also included the resources as well:
<br />
<br />
IDD_OPTIONS DIALOG DISCARDABLE 0, 0, 271, 166<br />
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU<br />
CAPTION "Options"<br />
FONT 8, "MS Sans Serif"<br />
BEGIN<br />
DEFPUSHBUTTON "OK",IDOK,7,145,50,14<br />
PUSHBUTTON "Cancel",IDCANCEL,214,145,50,14<br />
CONTROL "Tab1",IDC_TAB1,"SysTabControl32",0x0,7,7,257,124<br />
END<br />
<br />
IDD_OPTIONS_GENERAL DIALOG DISCARDABLE 20, 15, 150, 60<br />
STYLE WS_CHILD<br />
FONT 8, "MS Sans Serif"<br />
BEGIN<br />
GROUPBOX "",IDC_STATIC,15,11,118,38<br />
LTEXT "General Tab",IDC_STATIC,53,26,44,8<br />
END<br />
<br />
<br />
IDD_OPTIONS_ADVANCED DIALOG DISCARDABLE 20, 15, 150, 60<br />
STYLE WS_CHILD<br />
FONT 8, "MS Sans Serif"<br />
BEGIN<br />
GROUPBOX "",IDC_STATIC,15,11,118,38<br />
LTEXT "Advanced Tab",IDC_STATIC,53,26,44,8<br />
END<br />
<br />
Everything looks to be correct so I am not sure as to what could be causing the issue. If this is of any help I am getting these compiler warnings as well:
C:\Program Files\Microsoft Visual Studio\MyProjects\RS_Stats32\RS_Stats32.cpp(95) : warning C4700: local variable 'tabctl' used without having been initialized
C:\Program Files\Microsoft Visual Studio\MyProjects\RS_Stats32\RS_Stats32.cpp(106) : warning C4700: local variable 'ItemStruct' used without having been initialized
C:\Program Files\Microsoft Visual Studio\MyProjects\RS_Stats32\RS_Stats32.cpp(137) : warning C4700: local variable 'CurrentTabHwnd' used without having been initialized
C:\Program Files\Microsoft Visual Studio\MyProjects\RS_Stats32\RS_Stats32.cpp(138) : warning C4700: local variable 'hwndTab' used without having been initialized
C:\Program Files\Microsoft Visual Studio\MyProjects\RS_Stats32\RS_Stats32.cpp(142) : warning C4700: local variable 'tab1_hwnd' used without having been initialized
C:\Program Files\Microsoft Visual Studio\MyProjects\RS_Stats32\RS_Stats32.cpp(146) : warning C4700: local variable 'tab2_hwnd' used without having been initialized
If you need some more information just give me a shout. Just FYI I am running on VC++ 6.0 on a WinXP machine.
Thanks,
Robbie
|