DestroyWindow haunting me
I am trying to create a program that will put a white static box or a black static box on the window according to a value in an array and it will do this multiple times in the program but every time i do it the previous sqaures show up and then the new ones. my code is here:
Code:
for(i=0;i<30;i++)
{
for(k=0;k<30;k++)
{
DestroyWindow(GetDlgItem(hwnd,1000+stickCounter));
stickCounter++;
}
}
stickCounter=0;
for(i=0;i<30;i++)
{
for(k=0;k<30;k++)
{
if(stickTemplate[i][k]==0)
{
hWndStaticBlack[i][k] = CreateWindowEx(0,"STATIC","",WS_CHILD | WS_VISIBLE | SS_BLACKRECT,
10+(k*5), 100+(i*5),5, 5,hwnd,(HMENU)1000+stickCounter,hInstance,0);
} else if(stickTemplate[i][k]==255)
{
hWndStaticBlack[i][k] = CreateWindowEx(0,"STATIC","",WS_CHILD | WS_VISIBLE | SS_WHITERECT,
10+(k*5), 100+(i*5),5, 5,hwnd,(HMENU)1000+stickCounter,hInstance,0);
}
stickCounter++;
}
}
when i generate the data in the array and then call this activity, the first time it till create the array of static boxes just fine and in a quick manner
when i do it a second time, it will remove the existing static boxes and the proceed to paint the new ones up there but before it gets them painted on the screen, the first ones show up and then the new ones like it is painting over them even though they are supposed to be destroyed
when i do it a third time, the old boxes (from the second time) go away like they should then the first set of boxes flash up there then comes the second set flashing up there and the the third set finally get painted up there
.
.
.
when i do it an nth time, the previous boxes disappear and then the 1st, 2nd, 3rd, ... nth-1 boxes flash up there and then the nth boxes get painted up there
i thought that DestroyWindow would get rid of these old static windows and allow the memory allocated for them to be occupied by the new data that is going to be set in it yet i watch the amount of memory that the program is taking and it just keeps growing
any suggestions or other questions?
any help would be appreciated. thanks in advanced.
Re: DestroyWindow haunting me
Quote:
Originally posted by AtomRiot
(HMENU)1000+stickCounter
HMENU is a handle, which is a pointer to void. You are typecasting 1000 to a pointer to void, and then adding stickCounter to it. Normally, when you add a number to a pointer, it adds the number multiplied by the size of the type that it points to, so you needn't worry about its size. I honestly have no idea what happens when you do pointer arithmetic with a void pointer. I would use brackets around the integer to ensure you have the proper value before the type cast, to ensure that the WM_CLOSE message you are sending has the same child id as the one you want to be destroyed.