01/10/2018, 11:21
Hỏi về closereason cho form sử dụng C++
Ở C#, khi đóng 1 form thì mình có thể sử dụng như bên dưới
void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
switch (e.CloseReason)
{
case CloseReason.ApplicationExitCall:
break;
case CloseReason.FormOwnerClosing:
break;
case CloseReason.MdiFormClosing:
break;
case CloseReason.None:
break;
case CloseReason.TaskManagerClosing:
break;
case CloseReason.UserClosing:
if (UserClosing)
{
//what should happen if the user hitted the button?
}
else
{
//what should happen if the user hitted the x in the upper right corner?
}
break;
case CloseReason.WindowsShutDown:
break;
default:
break;
}
}
Cho mình hỏi nếu mình sử dụng C++ MFC thì muốn đóng form mà có sử dụng closereason tương tự như ở C# thì có cách nào không?
Bài liên quan
Không chắc chắn nhưng nó có send message wm_close thì phải, lúc close thì tạo thêm 1 event rồi dùng hàm catch để lấy event close, tiếp theo lấy reason
Cám ơn bạn. Nhưng mà dùng event OnSysCommand thì chỉ catch được trường hợp user click button X hoặc nhấn Atl + F4.
Trường hợp user sử dụng TaskManager hoặc Shutdown thì sẽ không catch được.
Hóng cao nhân giúp
How to handle "End Task" from Windows Task Manager on a background process?
Hoặc Google thử: