Hey there,
I'm building a gui that has multiple tabs, and what I had done was set the hwnd variables as static variables such as below:
<br />
BOOL CALLBACK OptionsDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)<br />
{<br />
<br />
static HWND* tab1_hwnd = new HWND;<br />
static HWND* tab2_hwnd = new HWND;<br />
static HWND* tab3_hwnd = new HWND;<br />
static HWND* tab4_hwnd = new HWND;<br />
static HWND* tab5_hwnd = new HWND;<br />
static HWND* tab6_hwnd = new HWND;<br />
static HWND* CurrentTabHwnd = new HWND;<br />
static int* CurrentTabIndex = new int;<br />
static HWND* hwndTab = new HWND;<br />
<br />
switch(msg)<br />
{<br />
case WM_INITDIALOG:<br />
{<br />
<br />
LPSTR tab1_title = "General";<br />
LPSTR tab2_title = "Player Edit";<br />
LPSTR tab3_title = "Stats Attributes";<br />
LPSTR tab4_title = "Stats Format";<br />
LPSTR tab5_title = "File Upload";<br />
LPSTR tab6_title = "Advanced";<br />
<br />
<br />
INITCOMMONCONTROLSEX 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 />
ItemStruct.pszText = tab3_title;<br />
ItemStruct.cchTextMax = sizeof(tab2_title);<br />
<br />
SendMessage(*hwndTab, TCM_INSERTITEM, 2, (LPARAM)&ItemStruct);<br />
<br />
ItemStruct.pszText = tab4_title;<br />
ItemStruct.cchTextMax = sizeof(tab2_title);<br />
<br />
SendMessage(*hwndTab, TCM_INSERTITEM, 3, (LPARAM)&ItemStruct);<br />
<br />
ItemStruct.pszText = tab5_title;<br />
ItemStruct.cchTextMax = sizeof(tab2_title);<br />
<br />
SendMessage(*hwndTab, TCM_INSERTITEM, 4, (LPARAM)&ItemStruct);<br />
<br />
ItemStruct.pszText = tab6_title;<br />
ItemStruct.cchTextMax = sizeof(tab2_title);<br />
<br />
SendMessage(*hwndTab, TCM_INSERTITEM, 5, (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_PLAYEREDIT), *hwndTab, PlayerEdit_OptionsDialogProc, 0);<br />
*tab3_hwnd = CreateDialogParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_OPTIONS_STATSATTR), *hwndTab, StatsAttr_OptionsDialogProc, 0);<br />
*tab4_hwnd = CreateDialogParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_OPTIONS_STATSFORMAT), *hwndTab, StatsFormat_OptionsDialogProc, 0);<br />
*tab5_hwnd = CreateDialogParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_OPTIONS_FILEUPLOAD), *hwndTab, FileUpload_OptionsDialogProc, 0);<br />
*tab6_hwnd = CreateDialogParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_OPTIONS_ADVANCED), *hwndTab, Advanced_OptionsDialogProc, 0);<br />
<br />
*CurrentTabIndex = 0;<br />
*CurrentTabHwnd = *tab1_hwnd;<br />
<br />
ShowWindow(*tab1_hwnd,SW_SHOWDEFAULT);<br />
<br />
<br />
}<br />
break;<br />
<br />
case WM_NOTIFY:<br />
{<br />
<br />
LPNMHDR lpnmhdr = (LPNMHDR) lParam; <br />
<br />
switch(lpnmhdr->code){<br />
case TCN_SELCHANGE:<br />
{<br />
ShowWindow(*CurrentTabHwnd, SW_HIDE);<br />
<br />
switch(TabCtrl_GetCurSel(*hwndTab)){<br />
case 0:<br />
ShowWindow(*tab1_hwnd,SW_SHOWDEFAULT);<br />
*CurrentTabHwnd = *tab1_hwnd;<br />
*CurrentTabIndex = 0;<br />
break;<br />
case 1:<br />
ShowWindow(*tab2_hwnd,SW_SHOWDEFAULT);<br />
*CurrentTabHwnd = *tab2_hwnd;<br />
*CurrentTabIndex = 1;<br />
break;<br />
case 2:<br />
ShowWindow(*tab3_hwnd,SW_SHOWDEFAULT);<br />
*CurrentTabHwnd = *tab3_hwnd;<br />
*CurrentTabIndex = 2;<br />
break;<br />
case 3:<br />
ShowWindow(*tab4_hwnd,SW_SHOWDEFAULT);<br />
*CurrentTabHwnd = *tab4_hwnd;<br />
*CurrentTabIndex = 3;<br />
break;<br />
case 4:<br />
ShowWindow(*tab5_hwnd,SW_SHOWDEFAULT);<br />
*CurrentTabHwnd = *tab5_hwnd;<br />
*CurrentTabIndex = 4;<br />
break;<br />
case 5:<br />
ShowWindow(*tab6_hwnd,SW_SHOWDEFAULT);<br />
*CurrentTabHwnd = *tab6_hwnd;<br />
*CurrentTabIndex = 5;<br />
break;<br />
<br />
}<br />
}<br />
break;<br />
default:<br />
return FALSE; <br />
}<br />
<br />
}<br />
break;<br />
case WM_COMMAND:<br />
{<br />
<br />
switch(LOWORD(wParam)){<br />
<br />
case IDOK:<br />
SendMessage(hwnd, WM_CLOSE, 0, 0);<br />
break;<br />
case IDCANCEL:<br />
SendMessage(hwnd, WM_CLOSE, 0, 0);<br />
break;<br />
}<br />
<br />
}<br />
break;<br />
case WM_CLOSE:<br />
{<br />
<br />
EndDialog(hwnd, 0);<br />
delete tab1_hwnd;<br />
delete tab2_hwnd;<br />
delete tab3_hwnd;<br />
delete tab4_hwnd;<br />
delete tab5_hwnd;<br />
delete tab6_hwnd;<br />
delete CurrentTabHwnd;<br />
delete CurrentTabIndex;<br />
delete hwndTab;<br />
<br />
}<br />
<br />
break;<br />
<br />
default:<br />
return FALSE;<br />
}<br />
return 0;<br />
}<br />
As you can also see I have dynamically allocated them as well. The reason for doing this is because I dont want to make sure that the dialog boxes dont hog a lot of memory. The problem I am receiving is that once this dialog box is called that contains the multiple tabs, I get an error once I close, reopen and close once again this specific dialog box. The error is as follows:
Debug Assertion Failed!
Program: C:/.../RS_Stats32.exe
File: dbgdel.cpp
Line: 47
Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
I looked on MSDN but it doesnt offer any helpful advice on how I fix this error. I know its an issue with dynamically allocating those variables because I did not receive this error when the variables were just static and not dynamically allocated. My questions basically are:
1) Is it possible to dynamically allocate static variables, and allow the variables to dynamically allocated and destroyed once a routine has been completed? If so how?
2) Is making the hwnd variables dynamically allocated worth it? Does it actually save a considerable amount of memory?
Any help would be appreciated
Thanks,
Robbie
|