Do i need to use delete for these arrays when i use destroy window?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
	GetClientRect(hwnd, &rect);

	gtKey.X = rect.right;
	gtKey.Y = rect.bottom;

	for (int i=0; i < FirstNUM; ++i)
	{
		DestroyWindow (hwndFirstLineS [i]);
	}
	for (int i=0; i < SecondNUM; ++i)
	{
		DestroyWindow (hwndSecondLineS [i]);
	}
	for (int i=0; i < ThirdNUM; ++i)
	{
		DestroyWindow (hwndThirdLineS [i]);
	}
	for (int i=0; i < FourthNUM; ++i)
	{
		DestroyWindow (hwndFourthLineS [i]);
	}
	CreateBigCaseKeyboard(gtKey, hwnd, lParam);

	return 0;

Declaration of the arrays
1
2
3
4
5
6
7
8
9
HWND hwndFirstLineS [FirstNUM],
	 hwndSecondLineS [SecondNUM],
	 hwndThirdLineS [ThirdNUM],
	 hwndFourthLineS [FourthNUM],
	 hwndBottomLineS [BottomNUM],
	 hwndFirstLineB [BigFirstNUM],
	 hwndSecondLineB [BigSecondNUM],
	 hwndThirdLineB [BigThirdNUM],
	 hwndFourthLineB [BigFourthNUM],


I am asking this because my program has a bug that is not constant, happens on and off.
I have tried using delete [] hwndxxxxx; but warning was given in compiler and fatal error when running my program.

More info:
My program is creating an on screen keyboard, when capslock is click all original buttons will be destroy and new ones created. However, when recreating new buttons sometime it shows and sometime nothing is shown.
You should only delete an array if it is no longer used. Your arrays, however, are not created with the new operator, so you must not use the delete operator to get rid of them.

TIP: Your approach is highly inefficient. Creating all new buttons just to show uppercase letters and symbols is not the way to go. It is best if you use a user-defined windows message to notify the buttons that the case changed, and then just have them redraw their contents accordingly.

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
//Check MSDN online to see if + 1 is appropriate.
#define WM_CASECHANGED WM_USER + 1

...

//In the main window procedure notify child windows that the case changed.
for (int i = 0; i < __countof(hwndFirstLineS); i++)
{
    //Third parameter would be true if uppercase, or false if lowercase.
    SendMessage(hwndFirstLineS[i], WM_CASECHANGED, true, NULL);
}
//Do the other lines.

...

//Define for each window a lower symbol and upper symbol

//Example of symbols to be defined for the child window that handles the number 1.
const LPTSTR LOWER_SYMBOL = TEXT("1");
const LPTSTR UPPER_SYMBOL = TEXT("!"); //For US English keyboard (and some others).
...
//In the Windows Procedure of your child windows, you process the message.
case WM_CASECHANGED:
    m_textToShow = wParam ? UPPER_SYMBOL : LOWER_SYMBOL;
    InvalidateRect(myHwnd, &myDimensions, TRUE /* or FALSE, up to you */);
    break;
...


What is left there is just to make sure that each child window draws m_textToShow whenever the WM_PAINT message arrives.
Thanks, that gave me the idea to use SetWindowText to just change the text in the button.

so now it reads
1
2
3
case K_Capslock:
			SendMessage (hwndKeyboard, WM_USER_KBCASE, BigCase, 0);
			return 0;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
	case WM_USER_KBCASE:
		switch (wParam)
		{
		case BigCase:
			for (int i = 0; i < FirstNUM; ++i)
			{
				SetWindowText (hwndFirstLineS [i], BigFirstLine[i].szKeyName); 
			}

			MessageBox(hwnd, TEXT ("big case change"), TEXT ("Gaze Tracker Mouse v2"), 0);
//the rest of code
			return 0;

		case SmallCase:
//rest of code
			MessageBox(hwnd, TEXT ("small case change"), TEXT ("Gaze Tracker Mouse v2"), 0);
			return 0;
		}


Thanks alot again
Last edited on
Topic archived. No new replies allowed.