Sir, I have created a Check box using win32 API in visual studio 2015.
My check box has been created successfully without any errors.
But this does not performs the required task.
My dialog boxes contains two push buttons ok and cancel. I am willing to to add a function call when the dialog box is checked and when the OK button is pressed that function should also be executed in addition to the normal functions
INT_PTR CALLBACK StoreHere(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
if (IDOK == Optimizer(hDlg, message, wParam, lParam)) {
case 1008: { bool checked = IsDlgButtonChecked(hDlg, IDC_CHECK1);
if (checked) {
CheckDlgButton(hDlg, IDC_CHECK1, BST_UNCHECKED);
DeletePreviousOne();
}
else
{
CheckDlgButton(hDlg, IDC_CHECK1, BST_CHECKED);
return -1;
}
}
}
}
return (INT_PTR)FALSE;
}
Since my code has neither errors nor warnings the only way to solve this is debugging by setting break points so I did this by setting break points here
==>> DeletePreviousOne();
I found that my function gets never called.How to achieve my wish?
Is my code has not sufficient information?
Am I missing anything?
Kindly help me with this sir please
Thank you
UPDATE -2:
Sorry sir I tried this my code behaves differently:(It functions even when I press the cancel button.
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
case 1008: {
bool checked = IsDlgButtonChecked(hDlg, IDC_CHECK1);
if (checked) {
CheckDlgButton(hDlg, IDC_CHECK1, BST_UNCHECKED);
DeletePreviousOne();
}
else
{
CheckDlgButton(hDlg, IDC_CHECK1, BST_CHECKED);
return -1;
}
}
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
On setting the break points I came to know that my function gets called even I press the cancel button.
How to solve this problem sir?
Am I missing something or everything?
Kindly help me with this sir please
Thank you
UPDATE - 3:
INT_PTR CALLBACK Optimizer(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
if (IDOK == Optimizer(hDlg, message, wParam, lParam)) {
case IDC_CHECK1:
{
case BN_CLICKED:
if (SendDlgItemMessage(hDlg, IDC_CHECK1, BM_GETCHECK, 0, 0))
{
recycler();
}
break;
}
}
}
break;
}
return (INT_PTR)FALSE;
}
The problem now is function gets only when the check box is checked but it also executes when the user hits cancel button.
Kindly help me with this sir.