0
내 노트북의 전원이 켜지는 시간을 결정하는 C 응용 프로그램이 있습니다. 이 .exe 파일을 열 때만 작동합니다.앱을 커널 모드 실행 코드로 바꾸는 방법은 무엇입니까?
커널 모드에서 작동하게 할 수있는 방법이 있습니까? 의미는 .exe를 실행하고 싶지 않고 랩톱을 켜고 전력이 적을 때 전원에 관한 메시지를받는 것입니다. ... 당신은 커널 모드에서이 코드를 실행하려는 이유
#include <windows.h>
const char g_szClassName[] = "myWindowClass";
// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
short x ;
SYSTEM_POWER_STATUS status;
switch(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_POWERBROADCAST:
switch (wParam)
{
case PBT_APMPOWERSTATUSCHANGE :
x = GetSystemPowerStatus(&status);
if (x > 0) // function succeeded
{
if (status.ACLineStatus == 1)
{
printf("power is off");
MessageBox(NULL, "power is on" , "NOTICE" ,MB_OK);
}
else if (status.ACLineStatus == 0)
{
printf("power is on");
MessageBox(NULL, "power is off" , "NOTICE" ,MB_OK);
}
else
{
printf("unknown");
MessageBox(NULL, "unknown status" , "ERROR" ,MB_OK);
}
}
else
{
LPSTR str = "function failed in providing information";
MessageBox(NULL , str, "ERROR", MB_OK);
}
break;
case PBT_POWERSETTINGCHANGE:
x = GetSystemPowerStatus(&status);
if (x > 0) // function succeeded
{
if (status.ACLineStatus == 1)
{
printf("power is off");
MessageBox(NULL, "power is on" , "NOTICE" ,MB_OK);
}
else if (status.ACLineStatus == 0)
{
printf("power is on");
MessageBox(NULL, "power is off" , "NOTICE" ,MB_OK);
}
else
{
printf("unknown");
MessageBox(NULL, "unknown status" , "ERROR" ,MB_OK);
}
}
break;
default:
MessageBox (NULL , "nothing" , "------" , MB_OK);
}
break;
case WM_MOUSEMOVE:
if (wParam == MK_LBUTTON)
MessageBox(NULL, "mouse was clicked", "check", MB_OK);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
HPOWERNOTIFY notification_1;
//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc; //signing to the updating service of the operating system
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
// Step 2: Creating the Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"The title of my window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
NULL, NULL, hInstance, NULL);
if(!hwnd)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
notification_1 = RegisterPowerSettingNotification(hwnd, &GUID_ACDC_POWER_SOURCE, DEVICE_NOTIFY_WINDOW_HANDLE);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
// Step 3: The Message Loop
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
어떻게하면됩니까? 숙제의 일부입니다. – user1386966
이 자습서를 보시기 바랍니다 : http://www.devx.com/cplus/Article/9857 – aleroot
감사합니다! – user1386966