Click here to Skip to main content
15,914,943 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: 'HDEVINFO' and 'SP_DEVICE_INTERFACE_DATA' Pin
kitty516-Jun-06 5:02
kitty516-Jun-06 5:02 
GeneralRe: 'HDEVINFO' and 'SP_DEVICE_INTERFACE_DATA' Pin
Viorel.16-Jun-06 5:13
Viorel.16-Jun-06 5:13 
QuestionRe: 'HDEVINFO' and 'SP_DEVICE_INTERFACE_DATA' Pin
kitty516-Jun-06 5:18
kitty516-Jun-06 5:18 
AnswerRe: 'HDEVINFO' and 'SP_DEVICE_INTERFACE_DATA' Pin
Viorel.16-Jun-06 5:26
Viorel.16-Jun-06 5:26 
GeneralRe: 'HDEVINFO' and 'SP_DEVICE_INTERFACE_DATA' Pin
kitty516-Jun-06 5:48
kitty516-Jun-06 5:48 
GeneralRe: 'HDEVINFO' and 'SP_DEVICE_INTERFACE_DATA' [modified] Pin
Viorel.16-Jun-06 5:56
Viorel.16-Jun-06 5:56 
Questionhow to send unicode text in XlTable Pin
bassel_z16-Jun-06 4:45
bassel_z16-Jun-06 4:45 
QuestionDynamically allocating static variables Pin
capricious_00116-Jun-06 3:54
capricious_00116-Jun-06 3:54 
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 Smile | :)

Thanks,

Robbie
AnswerRe: Dynamically allocating static variables Pin
Laxman Auti16-Jun-06 4:07
Laxman Auti16-Jun-06 4:07 
GeneralRe: Dynamically allocating static variables Pin
capricious_00116-Jun-06 4:17
capricious_00116-Jun-06 4:17 
AnswerRe: Dynamically allocating static variables Pin
Viorel.16-Jun-06 4:28
Viorel.16-Jun-06 4:28 
GeneralRe: Dynamically allocating static variables Pin
capricious_00116-Jun-06 5:07
capricious_00116-Jun-06 5:07 
QuestionFinding Hex Pin
rajeevktripathi16-Jun-06 3:53
rajeevktripathi16-Jun-06 3:53 
AnswerRe: Finding Hex Pin
David Crow16-Jun-06 4:01
David Crow16-Jun-06 4:01 
GeneralRe: Finding Hex Pin
capricious_00116-Jun-06 4:08
capricious_00116-Jun-06 4:08 
AnswerRe: Finding Hex Pin
capricious_00116-Jun-06 4:06
capricious_00116-Jun-06 4:06 
AnswerRe: Finding Hex Pin
Viorel.16-Jun-06 4:11
Viorel.16-Jun-06 4:11 
QuestionCString's Format Fuction confusion Pin
kitty516-Jun-06 2:57
kitty516-Jun-06 2:57 
AnswerRe: CString's Format Fuction confusion Pin
toxcct16-Jun-06 3:00
toxcct16-Jun-06 3:00 
AnswerRe: CString's Format Fuction confusion [modified] Pin
Viorel.16-Jun-06 3:03
Viorel.16-Jun-06 3:03 
GeneralRe: CString's Format Fuction confusion Pin
kitty516-Jun-06 3:10
kitty516-Jun-06 3:10 
GeneralRe: CString's Format Fuction confusion Pin
toxcct16-Jun-06 3:13
toxcct16-Jun-06 3:13 
GeneralRe: CString's Format Fuction confusion [modified] Pin
kitty516-Jun-06 3:15
kitty516-Jun-06 3:15 
GeneralRe: CString's Format Fuction confusion [modified] Pin
kakan16-Jun-06 3:14
professionalkakan16-Jun-06 3:14 
QuestionPassing Arrays Of Structs Over Automation-Capable Interfaces... Pin
James R. Twine16-Jun-06 2:56
James R. Twine16-Jun-06 2:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.