Code:
LRESULT CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HWND cboShutdown_After;
HWND cboTimer;
cboShutdown_After = GetDlgItem(hwndDlg, IDD_Shutdown_After_CBO);
cboTimer = GetDlgItem(hwndDlg, IDD_Timer_CBO);
const char *Shutdown_After[3] = { "(Choose your process)","Shutdown After","Restart After" };
const char *Timer[6]={"(Select the time to process)" ,"Now", "5 mins", "15 mins", "30 mins", "1 hour"};
int Sel1 = SendMessage(cboShutdown_After, CB_GETCURSEL, 0, 0);
int Sel2 = SendMessage(cboTimer, CB_GETCURSEL, 0, 0);
switch(uMsg)
{
case WM_INITDIALOG:
cboShutdown_After = GetDlgItem(hwndDlg, IDD_Shutdown_After_CBO);
for(int Count = 0; Count < 3; Count++)
{
SendMessage(cboShutdown_After,
CB_ADDSTRING,
0,
reinterpret_cast<LPARAM>((LPCTSTR)Shutdown_After[Count]));
}
cboTimer = GetDlgItem(hwndDlg, IDD_Timer_CBO);
for(int Count2 = 0; Count2 < 6; Count2++)
{
SendMessage(cboTimer,
CB_ADDSTRING,
0,
reinterpret_cast<LPARAM>((LPCTSTR)Timer[Count2]));
}
SendMessage(cboShutdown_After, CB_SETCURSEL, 0, 0);
SendMessage(cboTimer, CB_SETCURSEL, 0, 0);
break;
case WM_CLOSE:
EndDialog(hwndDlg, 0);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDD_Shutdown_After_CBO: // If the combo box sent the message,
switch (HIWORD(wParam))
{
case 1:
switch(Sel1)
{
case 0:
MessageBox(NULL,"Please select an action.","Error",MB_ICONWARNING);
break;
case 1:
if(MessageBox(NULL,"You have choose Shutdown.\nConfirm?","Information",MB_ICONQUESTION | MB_OKCANCEL)==IDOK)
{
//Do shutdown here
MessageBox(NULL,"You have confirm for Shutdown.","Information",MB_ICONINFORMATION);
}
else
{
return 0;
}
break;
case 2:
if(MessageBox(NULL,"You have choose Restart.\nConfirm?","Information",MB_ICONQUESTION | MB_OKCANCEL)==IDOK)
{
//Do shutdown here
MessageBox(NULL,"You have confirm for Restart.","Information",MB_ICONINFORMATION);
}
else
{
return 0;
}
break;
}
break;
}
break;
case IDD_Timer_CBO:
switch (HIWORD(wParam))
{
case 1:
switch(Sel2)
{
case 0:
MessageBox(NULL,"Please select a time.","Error",MB_ICONWARNING);
break;
case 1:
MessageBox(NULL,"Press apply to perform the action immediately.","Information",MB_ICONINFORMATION);
break;
case 2:
MessageBox(NULL,"Press apply to perform the action after 5 minutes.","Information",MB_ICONINFORMATION);
break;
case 3:
MessageBox(NULL,"Press apply to perform the action after 15 minutes.","Information",MB_ICONINFORMATION);
break;
case 4:
MessageBox(NULL,"Press apply to perform the action 30 minutes.","Information",MB_ICONINFORMATION);
break;
case 5:
MessageBox(NULL,"Press apply to perform the action 1 hour.","Information",MB_ICONINFORMATION);
break;
}
break;
}
break;
case IDC_BTN_QUIT:
EndDialog(hwndDlg, 0);
return TRUE;
case IDC_BTN_APPLY:
MessageBox(hwndDlg, "Thanks for using!", "Information", MB_ICONINFORMATION);
return TRUE;
}
break;
}
return FALSE;
}
This is a part of code that i try to make a shutdown with timer. I have 2 combo box, one is for shutdown/restart selection, one is for time selection. What should I code to make user press the apply button to process the selected process with the timer in that two combo box? And what is the code for shutdown and restart? system("shutdown") is unusable.