MSG msg;
while(1)
{
GetMessage(&msg, NULL, 0, 0)
if(msg.wParam==WM_QUERYENDSESSION)
//Codigo a ejecutar cuando se apaga el pc
}
Mi SO es windows xp
EI: juntando mensajes.
Ahora estoy utilizando este codigo, pero no me funciona porque al apagar el pc no me sale ninguna ventana ni se me borra el archivo que tengo en c:\apagar.txt
Código:
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK YourWindowProc(HWND hWnd, UINT uMsgId, WPARAM wParam, LPARAM lParam)
{
switch(uMsgId) {
case WM_QUERYENDSESSION:
{
remove("C:\\apagar.txt ");
MessageBoxA(0, "adios", "dw", 0);
return 0;
break;
}
}
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
MSG msg;
wc.lpfnWndProc = YourWindowProc;
BOOL bRet;
while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
{
if (bRet == -1)
{
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}