Código fuente del sistema de escritorio del hotel
# include & lttchar.h & gt
# include & ltassert.h & gttchar * SZ question = text("¿Qué es 1000 * 10? ? ");
TCHAR * SZ respuesta = TEXT(" 10000 ");
WNDPROC oldEditProc = NULL
WNDPROC oldButtonProc = NULL
HFONT hFont = NULL
HWND hTestDlgWnd=NULL, hEditWnd=NULL, hButtonWnd = NULL
Devolución de llamada LRESULT TestDlgProc(HWND hWnd, mensaje UINT, WPARAM wParam, LPARAM LPARAM);
Devolución de llamada LRESULT MyEditProc(HWND hWnd, mensaje UINT, WPARAM wParam, LPARAM LPARAM);
Devolución de llamada LRESULT MyButtonProc(HWND hWnd, mensaje UINT, WPARAM wParam, LPARAM LPARAM);
Reinicio del sistema BOOL(); int WINAPI WinMain(h instancia h instancia, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
wnd class wnd class = { 0 };
TCHAR * SZ nombre de clase = TEXT(" TestDlg ");
MSG MSG = { 0 }; >
HBRUSH HBRUSH = CreateSolidBrush(color);
assert(hBrush); hFont =(hFont)GetStockObject(DEFAULT _ GUI _ FONT);
log font log font = { 0 };
GetObject(hFont, sizeof(LOGFONT), & amplog fuente
eliminar objeto(hFont);
hFont = NULL
p> p>fuente de registro lf altura = 12;
_ tcscpy (logfont.
lffacename, text("Mi mundo"));
hFont = createfont indirect(& log font);
Assertion(hFont); wnd style = CS _ no close;
clase wnd. h instancia = h instancia;
clase wnd. Fondo HBR = HB rush;
clase wnd hcursor = cargar cursor (NULL,MAKEINTRESOURCE). (IDC_ARROW));
wndclass.hIcon=LoadIcon(NULL,MAKEINTRESOURCE(IDI_Application));
clase wnd cbwndextra = 0;
clase wnd. cbclsextra = 0;
clase wnd. lpfnwndproc = TestDlgProc;
wndclass.lpszMenuName = NULL
nombre de clase lpsz = nombre de clase SZ;
p>
If (!register class(& wndclass))
{
MessageBox(NULL, TEXT("¡Error en el registro de la ventana!") ), TEXT ("advertencia" ), MB _ OK);
Devolver S _ FALSE
} Estilo DWORD = WS _ ventana superpuesta & amp ~(WS _ maximizar cuadro | WS _ minimizar cuadro | WS _ marco grueso
int CX = getsystem metrics(SM _ CX pantalla completa
int cy = GetSystemMetrics(SM _ cy pantalla completa);
int iTestDlgWidth = 500
int iTestDlgHeight = 230
hTestDlgWnd = CreateWindowEx(WS_EX_tool ventana,
szClassName ,
Texto ("Por favor responda la pregunta:"),
Estilo,
cx/2-iTestDlgWidth/2,
cy /2-iTestDlgHeight/2,
iTestDlgWidth,
iTestDlgHeight,
Vacío,
Vacío,
hInstance,
NULL);
assert(hTestDlgWnd);
* SendMessage(hTestDlgWnd, WM_SETFONT, (WPARAM)hFont, 1); estilo = WS _ CHILD | ES _ MULTILINE | AUTOHSCROLL | ES _ AUTOVSCROLL;
hEditWnd=CreateWindow(
Texto("Editar"),
Texto(""),
Estilo,
10,
40,
iTestD
lgWidth-20,
100,
hTestDlgWnd,
Vacío,
hInstance,
);
assert(hEditWnd);
oldEditProc =(WNDPROC)SetWindowLong(hEditWnd, GWL_WNDPROC, (LONG)MyEditProc);
assert(oldEditProc);
* SendMessage(hedit wnd, WM_SETFONT, (WPARAM)hFont, 1); estilo = WS _ CHILD
hButtonWnd = crear ventana(TEXT(" Botón "),
Texto("OK"),
Estilo,
10,
150,
60,
20,
hTestDlgWnd,
Vacío,
hInstancia,
);
assert(hButtonWnd) ;
oldButtonProc =(WNDPROC)SetWindowLong(hButtonWnd, GWL_WNDPROC, (LONG)MyButtonProc
assert(oldButtonProc);
* SendMessage(hButtonWnd, WM_SETFONT); , (WPARAM)hFont, 1); ShowWindow (hTestDlgWnd, SW _ SHOW);
ShowWindow (hEditWnd, SW _ SHOW);
actualizar ventana(hTestDlgWnd); * SetFocus(hEditWnd);
mientras(GetMessage(& msg, NULL, 0, 0))
{ p>
Traducir mensaje (& amp msg);
mensaje de envío (amp; msg
}
IF (hBrush)
eliminar objeto(HB rush);
frecuencia media (alta frecuencia)
eliminar objeto(hFont);
devolver msg.wParam
p>}Devolución de llamada LRESULT TestDlgProc(HWND hWnd, mensaje UINT, WPARAM wParam, LPARAM lParam)
{
Conmutador (mensaje)
{
Caso WM_CLOSE:
{
Destruir ventana (hWnd);
}
Romper;
p>
Caso WM_DESTROY:
{
PostQuitMessage(0);
}
Romper;
Caso WM_PAINT:
{
estructura de pintura PS = { 0 };
HDC hDC = NULL
hDC = comenzar a pintar (hWnd & PS);
HFONT mantener fuente = (HFONT)seleccionar objeto (hDC, HFONT
int oldMode=SetBkMode(hDC, TRANSPAR);
ENT);
TextOut(hDC, 10, 5, szQuestion, _ TCS len(pregunta SZ));
SelectObject(hDC, mantener fuente);
SetBkMode(hDC, modo antiguo);
Acabado(hWnd & PS);
}
Romper;
} p>
Devuelve DefWindowProc(hWnd, mensaje, wParam, lParam);
}Devolución de llamada LRESULT MyEditProc(HWND hWnd, mensaje UINT, WPARAM wParam, LPARAM lParam)
{
return (*oldEditProc)(hWnd, mensaje, wParam, lParam);
}Devolución de llamada LRESULT MyButtonProc(HWND hWnd, mensaje UINT, WPARAM wParam, LPARAM lParam) p>
{
Cambiar (mensaje)
{
Caso WM_LBUTTONDOWN:
{
TCHAR buf[ 512]= { 0 };
GetWindowText(hEditWnd, buf, 512); if (!_tcscmp(buf, szAnswer))
{
MessageBox( hWnd, TEXT("¡Respondiste correctamente!"), TEXT ("prompt "), MB_OK);
* SendMessage(hTestDlgWnd, WM_CLOSE, 0, 0);
}
Otros
{
MessageBox(hWnd, TEXT)("¡Respondiste mal! ¡¡Por favor, prepárate para aceptar el castigo!!" ), TEXT ("mensaje "), MB_OK);
reinicio del sistema();
}
}
Interrupción;
}
return (*oldButtonProc)(hWnd, message, wParam, lParam);
}BOOL reinicio del sistema()
{
Procesando hToken
TOKEN _ PRIVILEGES tkp
Si (! OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRVILEGES|TOKEN_QUERY y amphToken))
{
Devolución (falso);
}
p >
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Permissions[0].luid);
tkp. PrivilegeCount = 1;
tkp. Permisos[0].
Atributos = SE_PRIVILEGES_ENABLED
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0); if (GetLastError()!=Error_Success)
{
Devolver FALSO
}if (!ExitWindowsEx(EWX_REBOOT, 0))
{
Devolver FALSO
}
Devuelve TRUE
} Antes de responder al programa de trucos de apagado, debes crear un programa WIN32 y pegarlo.