Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma comment(linker,"/MERGE:.rdata=.text")
- #pragma comment(linker,"/MERGE:.data=.text")
- #pragma comment(linker,"/SECTION:.text,ERW,512")
- #pragma comment(linker,"/Od")
- #pragma comment(linker,"/NODEFAULTLIB")
- #pragma comment(linker,"/CLRUNMANAGEDCODECHECK:NO")
- #pragma comment(linker,"/MANIFEST:NO")
- #pragma comment(linker,"/MANIFESTUAC:NO")
- #pragma comment(linker,"/GS-")
- #pragma comment(linker,"/PDBPATH:NONE")
- #pragma comment(linker,"/DYNAMICBASE:NO")
- #pragma comment(linker,"/ENTRY:WinMain")
- #include "windows.h"
- #define Interval 60000
- #define MsgCaption "Информация о батарее"
- #define MsgText "Батарея полностью заряжена. Питание можно отключить.\r\nПродолжить работу программы?"
- #define AutorunValue "BatteryStatusInformer"
- #define AutorunKeyName "Software\\Microsoft\\Windows\\CurrentVersion\\Run"
- #define MutexStr "{4406ED85-5FE6-4346-BEF0-88C49FE7A2A2}"
- UINT hTimer;
- HANDLE Mutex;
- bool AlreadyRunned();
- void InToAutorun();
- bool ShowMessage();
- void __stdcall TimerProc(HWND hWnd, UINT nMsg, UINT nIDEvent, DWORD dwTime)
- {
- _SYSTEM_POWER_STATUS sps;
- GetSystemPowerStatus((LPSYSTEM_POWER_STATUS)&sps);
- if ((sps.ACLineStatus == 1) && (sps.BatteryLifePercent = 100))
- {
- KillTimer(NULL, hTimer);
- if (ShowMessage())
- ExitProcess(0);
- hTimer = SetTimer(NULL, 0, Interval, (TIMERPROC)&TimerProc);
- }
- }
- int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
- {
- if (AlreadyRunned())
- ExitProcess(0);
- InToAutorun();
- hTimer = SetTimer(NULL, 0, Interval, (TIMERPROC)&TimerProc);
- MSG msg;
- while (GetMessageA(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessageA(&msg);
- }
- KillTimer(NULL, hTimer);
- ExitProcess(0);
- return 0;
- }
- bool AlreadyRunned()
- {
- Mutex = OpenMutexA(MUTEX_ALL_ACCESS, false, MutexStr);
- if (Mutex != 0)
- return true;
- Mutex = CreateMutexA(NULL, false, MutexStr);
- return false;
- }
- void InToAutorun()
- {
- DWORD D;
- HKEY hKey;
- char Value[2048];
- GetModuleFileNameA(GetModuleHandleA(NULL), (LPSTR)Value, 2048);
- if (RegCreateKeyExA(HKEY_CURRENT_USER, AutorunKeyName, 0, NULL,
- REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, (PHKEY)&hKey, (LPDWORD)&D) == ERROR_SUCCESS)
- {
- RegSetValueExA(hKey, AutorunValue, 0, REG_SZ, (LPBYTE)Value, sizeof(Value));
- RegCloseKey(hKey);
- }
- }
- bool ShowMessage()
- {
- tagMSGBOXPARAMSA params;
- params.cbSize = sizeof(params);
- params.hwndOwner = NULL;
- params.hInstance = GetModuleHandleA(NULL);
- params.lpszText = MsgText;
- params.lpszCaption = MsgCaption;
- params.dwStyle = MB_YESNO | MB_USERICON | MB_TOPMOST;
- params.lpszIcon = MAKEINTRESOURCEA(101);
- params.dwContextHelpId = 0;
- params.lpfnMsgBoxCallback = NULL;
- params.dwLanguageId = LANG_NEUTRAL;
- MessageBeep(MB_ICONINFORMATION);
- return (MessageBoxIndirectA(¶ms) == IDNO);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement