|
플그램 님이 쓰신 글 :
: 빌더5에서 간단하게 트레이를 구현하려고 합니다.
: 트레이에 생성은 되는데 폼을 없애려고 하는데 방법을 잘 몰라서 고수님들에게 부탁드립니다.
: 1. 트레이에서 폼 없애기
: 2. 시간을 콤보박스에서 선택후 그 시간이 되면 시스템 종료--소스가 있으시면 알려주시면 감사^^
: 3. 응용 프로그램 등록
:
: 위 세가지를 할 예정입니다.
: 간단하게라도 알려주시면 고맙겠습니다.
1. 폼 없애기
// 폼 없애기
void __fastcall TForm1::btnHideClick(TObject *Sender)
{
Form1->Hide();
TrayIcon1->Visible = true;
ShowWindow(Application->Handle, SW_HIDE);
}
// 폼 다시 불러내기
void __fastcall TForm1::TrayIcon1Click(TObject *Sender)
{
TrayIcon1->Visible = false;
Form1->Show();
ShowWindow(Application->Handle, SW_RESTORE);
}
2. 시스템 종료 루틴
HANDLE hToken;
TOKEN_PRIVILEGES tp;
LUID luid;
OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hToken);
LookupPrivilegeValue(NULL, "SeShutdownPrivilege", &luid);
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, false, &tp, 0, NULL, NULL);
ExitWindowsEx(EWX_SHUTDOWN, 0);
=-=-=-=-=-=-=
ExitWindowsEx() 함수를 쓰시면 됩니다. 함수원형은 다음과 같습니다.
BOOL ExitWindowsEx(
UINT uFlags, // shutdown operation
DWORD dwReserved // reserved
);
그리고 uFlag를 상황에 따라 골라쓰시면 되겠네요..
EWX_FORCE
Forces processes to terminate. When this flag is set, Windows does not send the messages WM_QUERYENDSESSION and WM_ENDSESSION to the applications currently running in the system. This can cause the applications to lose data. Therefore, you should only use this flag in an emergency.
EWX_LOGOFF
Shuts down all processes running in the security context of the process that called the ExitWindowsEx function. Then it logs the user off.
EWX_POWEROFF
Shuts down the system and turns off the power. The system must support the power-off feature.Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section. Windows 95: Security privileges are not supported or required.
EWX_REBOOT
Shuts down the system and then restarts the system. Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section. Windows 95: Security privileges are not supported or required.
EWX_SHUTDOWN
Shuts down the system to a point at which it is safe to turn off the power. All file buffers have been flushed to disk, and all running processes have stopped. Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section. Windows 95: Security privileges are not supported or required.
=-=-=-=-=-=-=
그리고... 3번째는 정확히 어떤것을 말씀하시는지 모르겠네요.. ^^;
|