What I am working on has sets of window controls. Controls are constantly being either destroyed, or created.
void ChangeControl() {
// remove all controls, existing, or not
hwnd = GetDlgItem(hWnd, IDC_BTN_FOOA);
DestroyWindow(hwnd);
hwnd = GetDlgItem(hWnd, IDC_BTN_FOOB);
DestroyWindow(hwnd);
hwnd = GetDlgItem(hWnd, IDC_BTN_FOOC);
// add the control wanted
hwndButton = CreateWindow("BUTTON", "Start", WS_VISIBLE|WS_CHILD|BS_OWNERDRAW|BS_PUSHBUTTON,
left, top, BUTTON_WIDTH, BUTTON_HEIGHT, hWnd, (HMENU)IDC_BTN_FOOB, GetModuleHandle(NULL), NULL);
}
Test case:
DWORD errorResult;
testHwnd = GetDlgItem(hWnd, IDC_BTN_START);
if (testHwnd) {
DestroyWindow(hwnd);
}
else {
errorResult = GetLastError();
}
I am wondering if this method is safe, or if I should be checking if a control exists before calling DestroyWindow()
.