Accueil > > > FERMER, REBOOT, LOGOFF. DIRECT OU PAR DECOMPTE
FERMER, REBOOT, LOGOFF. DIRECT OU PAR DECOMPTE
Information sur la source
Description
Et bien tous est écrit dans le titre.
Voici ce que cette source apporte comme aide:
- utilisation de token.
- API ExitWindows, ExitWindowsEx, SetTimer et KillTimer.
- DialogBox sans rc.
- utilisation de Timer.
Si vous avez des suggestions. N'hésitez pas
Source
- /*
- * Crée par : Deck_bsd
- * Date de création : 27/04/2006
- * Fonction : Redémarrer l'ordinateur, éteindre l'ordinateur ou fermer l'utilisateur courrant.
- */
-
- #include <windows.h>
- #include <stdio.h>
- #include <commctrl.h>
-
- #define IDM_QUIT 11
- #define IDM_HELP 22
- /* Declare Windows procedure */
- LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
- LRESULT CALLBACK PropoProc(HWND hwDlg, UINT message, WPARAM wParam, LPARAM lParam);
-
- unsigned int ConvertHourToMillisecond(HWND hwCountDown,unsigned int uiSize);
- void token();
-
- /* Make the class name into a global variable */
- char szClassName[ ] = "WindowsApp";
-
- HINSTANCE GlobalHInstance;
-
- int WINAPI WinMain (HINSTANCE hThisInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpszArgument,
- int nFunsterStil)
-
- {
- HWND hwnd; /* This is the handle for our window */
- MSG messages; /* Here messages to the application are saved */
- WNDCLASSEX wincl; /* Data structure for the windowclass */
- HMENU hmMain;
- HMENU hmHelp;
- HMENU hmQuit;
-
- /* The Window structure */
- wincl.hInstance = hThisInstance;
- wincl.lpszClassName = szClassName;
- wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
- wincl.style = CS_DBLCLKS; /* Catch double-clicks */
- wincl.cbSize = sizeof (WNDCLASSEX);
-
- /* Use default icon and mouse-pointer */
- wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
- wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
- wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
- wincl.lpszMenuName = NULL; /* No menu */
- wincl.cbClsExtra = 0; /* No extra bytes after the window class */
- wincl.cbWndExtra = 0; /* structure or the window instance */
- /* Use Windows's default color as the background of the window */
- wincl.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
-
-
- /* Création du menu */
-
- hmQuit = CreateMenu();
- AppendMenu(hmQuit,MF_STRING,IDM_QUIT,"Exit");
- hmMain = CreateMenu();
- AppendMenu(hmMain,MF_POPUP,(UINT)hmQuit,"&File");
-
- hmHelp = CreateMenu();
- AppendMenu(hmHelp,MF_STRING,IDM_HELP,"A propos de...");
- AppendMenu(hmMain,MF_POPUP,(UINT)hmHelp,"?");
-
- /* Register the window class, and if it fails quit the program */
- if (!RegisterClassEx (&wincl))
- return 0;
-
- /* The class is registered, let's create the program*/
- hwnd = CreateWindowEx (
- 0, /* Extended possibilites for variation */
- szClassName, /* Classname */
- "MyReboot", /* Title Text */
- WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX, /* default window */
- CW_USEDEFAULT, /* Windows decides the position */
- CW_USEDEFAULT, /* where the window ends up on the screen */
- 300, /* The programs width */
- 310, /* and height in pixels */
- HWND_DESKTOP, /* The window is a child-window to desktop */
- hmMain, /* No menu */
- hThisInstance, /* Program Instance handler */
- NULL /* No Window Creation data */
- );
-
- GlobalHInstance = hThisInstance;
- /* Make the window visible on the screen */
- ShowWindow (hwnd, nFunsterStil);
-
- /* Run the message loop. It will run until GetMessage() returns 0 */
- while (GetMessage (&messages, NULL, 0, 0))
- {
- if(messages.message == WM_KEYDOWN && messages.wParam == VK_ESCAPE) PostQuitMessage(0);
- /* Translate virtual-key messages into character messages */
- TranslateMessage(&messages);
- /* Send message to WindowProcedure */
- DispatchMessage(&messages);
- }
-
- /* The program return-value is 0 - The value that PostQuitMessage() gave */
- return messages.wParam;
- }
-
-
- /* This function is called by the Windows function DispatchMessage() */
-
- LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- HWND hwButtonLogOff,hwButtonReboot,hwButtonShutDown,hwButtonFormat,hwButtonStop;
- static HWND hwLabelUser;
- static HWND hwStatusBar;
- static HWND hwCountDown;
- HWND hwLabelCD;
- static unsigned short int usiChoice=0;
- unsigned int uiSize;
-
- char szBuffer[30];
- char szText[60]="Current user : ";
- DWORD dwWord = 30;
-
- switch (message) /* handle the messages */
- {
- case WM_CREATE :
- hwButtonLogOff = CreateWindow("button","Log off",WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
- 90,60,100,20,hwnd,(HMENU)1,GlobalHInstance,NULL);
- hwButtonReboot = CreateWindow("button","Reboot",WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
- 90,100,100,20,hwnd,(HMENU)2,GlobalHInstance,NULL);
- hwButtonShutDown = CreateWindow("button","Shutdown",WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
- 90,140,100,20,hwnd,(HMENU)3,GlobalHInstance,NULL);
- hwButtonFormat = CreateWindow("button","Format",WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
- 210,185,55,20,hwnd,(HMENU)4,GlobalHInstance,NULL);
- hwButtonStop = CreateWindow("button","Stop the countdown",WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
- 70,220,150,20,hwnd,(HMENU)5,GlobalHInstance,NULL);
- hwLabelUser = CreateWindow("static","",WS_CHILD | WS_VISIBLE | SS_SUNKEN | SS_CENTER,
- 18,25,260,20,hwnd,NULL,GlobalHInstance,NULL);
- hwCountDown = CreateWindow("edit","",WS_CHILD | WS_VISIBLE | WS_BORDER | ES_CENTER,
- 90,185,100,20,hwnd,NULL,GlobalHInstance,NULL);
- hwLabelCD = CreateWindow("static","Countdown ? : ",WS_CHILD | WS_VISIBLE,
- 5,185,85,20,hwnd,NULL,GlobalHInstance,NULL);
-
- hwStatusBar = CreateStatusWindow(WS_VISIBLE | WS_CHILD, "No action",hwnd,1);
-
- HFONT PoliceTahoma;
-
- PoliceTahoma = CreateFont(15,0,0,0,0,0,0,0,0,0,0,0,0,"tahoma");
- SendMessage(hwLabelUser,WM_SETFONT,(long)PoliceTahoma,0);
- SendMessage(hwCountDown,WM_SETFONT,(long)PoliceTahoma,0);
- SendMessage(hwLabelCD,WM_SETFONT,(long)PoliceTahoma,0);
- SendMessage(hwButtonFormat,WM_SETFONT,(long)PoliceTahoma,0);
- SendMessage(hwButtonStop,WM_SETFONT,(long)PoliceTahoma,0);
-
- GetUserName(szBuffer,&dwWord);
- lstrcat(szText,szBuffer);
- SetWindowText(hwLabelUser,szText);
-
- return 0;
-
- case WM_COMMAND :
- if(HIWORD(wParam) == BN_CLICKED){
- switch(LOWORD(wParam)){
- case 1 :
-
- uiSize = SendMessage(hwCountDown,WM_GETTEXTLENGTH,0,0);
- if(uiSize != 0){
-
- usiChoice = 1;
- SetTimer(hwnd,(UINT)1,ConvertHourToMillisecond(hwCountDown,uiSize),NULL);
- }else{
- ExitWindows(0,0);
- SetWindowText(hwStatusBar,"Log off of the current user...");
- }
- break;
- case 2 :
-
- uiSize = SendMessage(hwCountDown,WM_GETTEXTLENGTH,0,0);
- if(uiSize != 0){
-
- usiChoice = 2;
- SetTimer(hwnd,(UINT)1,ConvertHourToMillisecond(hwCountDown,uiSize),NULL);
- }else{
- token();
- ExitWindowsEx(EWX_REBOOT | EWX_FORCE,0);
- SetWindowText(hwStatusBar,"Reboot...");
- }
- break;
- case 3 :
-
- uiSize = SendMessage(hwCountDown,WM_GETTEXTLENGTH,0,0);
- if(uiSize != 0){
-
- usiChoice = 3;
- SetTimer(hwnd,(UINT)1,ConvertHourToMillisecond(hwCountDown,uiSize),NULL);
- }else{
- token();
- ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE,0);
- SetWindowText(hwStatusBar,"Windows is shutting down");
- }
- break;
- case 4 : MessageBox(hwnd,"Hour Format : 00:00:00","Format",MB_OK | MB_ICONINFORMATION);
- break;
- case 5 : KillTimer(hwnd,(UINT)1);break;
- case 11 : PostQuitMessage(0);
- break;
- case 22 :
- HGLOBAL hgMemory;
- LPDLGTEMPLATE dltDlgHelp;
- LPWORD lpWord;
- LPWSTR lpwsWindowNameUnicode;
-
- hgMemory = GlobalAlloc(GPTR,512);
- if(!hgMemory) break;
-
- dltDlgHelp = (LPDLGTEMPLATE) hgMemory;
-
- dltDlgHelp->style = WS_CAPTION | WS_POPUP | DS_MODALFRAME | WS_SYSMENU | WS_MINIMIZEBOX;
- dltDlgHelp->cx = 210;
- dltDlgHelp->cy = 100;
- dltDlgHelp->x = GetSystemMetrics(SM_CXSCREEN)/6;
- dltDlgHelp->y = GetSystemMetrics(SM_CYSCREEN)/6;
-
- lpWord = (LPWORD) (dltDlgHelp+1);
-
- lpwsWindowNameUnicode = (LPWSTR) (lpWord+2);
-
- MultiByteToWideChar(CP_ACP,0,"A propos de :",-1,lpwsWindowNameUnicode,128);
-
- DialogBoxIndirect(GlobalHInstance,dltDlgHelp,0,(DLGPROC)PropoProc);
-
- break;
- }
- }
-
- return 0;
- case WM_TIMER :
- switch(usiChoice){
- case 1 : ExitWindows(0,0);SetWindowText(hwStatusBar,"Log off of the current user...");break;
- case 2 : token();ExitWindowsEx(EWX_REBOOT | EWX_FORCE,0);SetWindowText(hwStatusBar,"Reboot...");break;
- case 3 : token();ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE,0);SetWindowText(hwStatusBar,"Windows is shutting down");break;
- }
- KillTimer(hwnd,(UINT)1);
- return 0;
- case WM_DESTROY :
- PostQuitMessage (0); /* send a WM_QUIT to the message queue */
- break;
- default: /* for messages that we don't deal with */
- return DefWindowProc (hwnd, message, wParam, lParam);
- }
-
- return 0;
- }
-
- void token(){
- HANDLE haToken;
- TOKEN_PRIVILEGES tpToken;
-
- /* Crée une nouvelle "file" de process qui va s'ajuster au autre */
- OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&haToken);
-
- /* On recherche la valeur du privilège */
- LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&tpToken.Privileges[0].Luid);
-
- /* Nombre d'entrées dans le tableau des privileges */
- tpToken.PrivilegeCount = 1;
-
- /* On défini l'attribut */
- tpToken.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
-
- AdjustTokenPrivileges(haToken,FALSE,&tpToken,sizeof(tpToken),NULL,NULL);
- }
-
-
- LRESULT CALLBACK PropoProc(HWND hwDlg, UINT message, WPARAM wParam, LPARAM lParam){
- HWND hwGroup,hwButtonOk,hwLabelInfo;
- HWND hwButtonSite,hwButtonMail;
-
- switch(message){
- case WM_INITDIALOG :
- hwGroup = CreateWindow("button","MyReboot",WS_CHILD | WS_VISIBLE | BS_GROUPBOX,
- 10,10,400,160,hwDlg,NULL,GlobalHInstance,NULL);
- hwButtonOk = CreateWindow("button","OK",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
- 16,146,30,20,hwDlg,(HMENU)111,GlobalHInstance,NULL);
- hwLabelInfo = CreateWindow("static","Créer par : Deck_bsd \n\nVersion : 3.0 \n\nLicense : Freeware",WS_CHILD | WS_VISIBLE,
- 120,30,150,90,hwDlg,NULL,GlobalHInstance,NULL);
- hwButtonSite = CreateWindow("button","http://deck-bsd.eurower.net",WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
- 120,115,200,20,hwDlg,(HMENU)1111,GlobalHInstance,NULL);
- hwButtonMail = CreateWindow("button","deck_bsd01@yahoo.fr",WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
- 120,140,200,20,hwDlg,(HMENU)11111,GlobalHInstance,NULL);
- HFONT PoliceComic;
- HFONT PoliceVerdana;
-
- PoliceComic = CreateFont(15,0,0,0,0,0,0,0,0,0,0,0,0,"comic sans MS");
- PoliceVerdana = CreateFont(15,0,0,0,0,0,0,0,0,0,0,0,0,"verdana");
- SendMessage(hwGroup,WM_SETFONT,(long)PoliceComic,0);
- SendMessage(hwButtonOk,WM_SETFONT,(long)PoliceComic,0);
- SendMessage(hwLabelInfo,WM_SETFONT,(long)PoliceVerdana,0);
- SendMessage(hwButtonSite,WM_SETFONT,(long)PoliceVerdana,0);
- SendMessage(hwButtonMail,WM_SETFONT,(long)PoliceVerdana,0);
-
-
- break;
- case WM_COMMAND :
- if(HIWORD(wParam) == BN_CLICKED){
- switch(LOWORD(wParam)){
- case 111 :
- EndDialog(hwDlg,0);
- break;
- case 1111 : ShellExecute(NULL,"open","http://deck-bsd.eurower.net",0,NULL,SW_MAXIMIZE);
- break;
- case 11111 : ShellExecute(NULL,"open","mailto:deck_bsd01@yahoo.fr",0,NULL,SW_MAXIMIZE);
- break;
- }
- }
- break;
- case WM_CLOSE :
- EndDialog(hwDlg,0);
- break;
- }
- return 0;
- }
-
- unsigned int ConvertHourToMillisecond(HWND hwCountDown,unsigned int uiSize){
- char *ptTime;
- unsigned int uiHour,uiMin,uiSec,uiTotal;
-
- ptTime = (char*)malloc(sizeof(char)*uiSize+1);
- GetWindowText(hwCountDown,ptTime,uiSize+1);
- sscanf(ptTime,"%d:%d:%d",&uiHour,&uiMin,&uiSec);
- free(ptTime);
- uiTotal = (uiHour*60)*60 + uiMin*60 + uiSec;
- uiTotal *= 1000;
-
- return uiTotal;
- }
/*
* Crée par : Deck_bsd
* Date de création : 27/04/2006
* Fonction : Redémarrer l'ordinateur, éteindre l'ordinateur ou fermer l'utilisateur courrant.
*/
#include <windows.h>
#include <stdio.h>
#include <commctrl.h>
#define IDM_QUIT 11
#define IDM_HELP 22
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK PropoProc(HWND hwDlg, UINT message, WPARAM wParam, LPARAM lParam);
unsigned int ConvertHourToMillisecond(HWND hwCountDown,unsigned int uiSize);
void token();
/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";
HINSTANCE GlobalHInstance;
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
HMENU hmMain;
HMENU hmHelp;
HMENU hmQuit;
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
/* Création du menu */
hmQuit = CreateMenu();
AppendMenu(hmQuit,MF_STRING,IDM_QUIT,"Exit");
hmMain = CreateMenu();
AppendMenu(hmMain,MF_POPUP,(UINT)hmQuit,"&File");
hmHelp = CreateMenu();
AppendMenu(hmHelp,MF_STRING,IDM_HELP,"A propos de...");
AppendMenu(hmMain,MF_POPUP,(UINT)hmHelp,"?");
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"MyReboot", /* Title Text */
WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
300, /* The programs width */
310, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
hmMain, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
GlobalHInstance = hThisInstance;
/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
if(messages.message == WM_KEYDOWN && messages.wParam == VK_ESCAPE) PostQuitMessage(0);
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND hwButtonLogOff,hwButtonReboot,hwButtonShutDown,hwButtonFormat,hwButtonStop;
static HWND hwLabelUser;
static HWND hwStatusBar;
static HWND hwCountDown;
HWND hwLabelCD;
static unsigned short int usiChoice=0;
unsigned int uiSize;
char szBuffer[30];
char szText[60]="Current user : ";
DWORD dwWord = 30;
switch (message) /* handle the messages */
{
case WM_CREATE :
hwButtonLogOff = CreateWindow("button","Log off",WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
90,60,100,20,hwnd,(HMENU)1,GlobalHInstance,NULL);
hwButtonReboot = CreateWindow("button","Reboot",WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
90,100,100,20,hwnd,(HMENU)2,GlobalHInstance,NULL);
hwButtonShutDown = CreateWindow("button","Shutdown",WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
90,140,100,20,hwnd,(HMENU)3,GlobalHInstance,NULL);
hwButtonFormat = CreateWindow("button","Format",WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
210,185,55,20,hwnd,(HMENU)4,GlobalHInstance,NULL);
hwButtonStop = CreateWindow("button","Stop the countdown",WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
70,220,150,20,hwnd,(HMENU)5,GlobalHInstance,NULL);
hwLabelUser = CreateWindow("static","",WS_CHILD | WS_VISIBLE | SS_SUNKEN | SS_CENTER,
18,25,260,20,hwnd,NULL,GlobalHInstance,NULL);
hwCountDown = CreateWindow("edit","",WS_CHILD | WS_VISIBLE | WS_BORDER | ES_CENTER,
90,185,100,20,hwnd,NULL,GlobalHInstance,NULL);
hwLabelCD = CreateWindow("static","Countdown ? : ",WS_CHILD | WS_VISIBLE,
5,185,85,20,hwnd,NULL,GlobalHInstance,NULL);
hwStatusBar = CreateStatusWindow(WS_VISIBLE | WS_CHILD, "No action",hwnd,1);
HFONT PoliceTahoma;
PoliceTahoma = CreateFont(15,0,0,0,0,0,0,0,0,0,0,0,0,"tahoma");
SendMessage(hwLabelUser,WM_SETFONT,(long)PoliceTahoma,0);
SendMessage(hwCountDown,WM_SETFONT,(long)PoliceTahoma,0);
SendMessage(hwLabelCD,WM_SETFONT,(long)PoliceTahoma,0);
SendMessage(hwButtonFormat,WM_SETFONT,(long)PoliceTahoma,0);
SendMessage(hwButtonStop,WM_SETFONT,(long)PoliceTahoma,0);
GetUserName(szBuffer,&dwWord);
lstrcat(szText,szBuffer);
SetWindowText(hwLabelUser,szText);
return 0;
case WM_COMMAND :
if(HIWORD(wParam) == BN_CLICKED){
switch(LOWORD(wParam)){
case 1 :
uiSize = SendMessage(hwCountDown,WM_GETTEXTLENGTH,0,0);
if(uiSize != 0){
usiChoice = 1;
SetTimer(hwnd,(UINT)1,ConvertHourToMillisecond(hwCountDown,uiSize),NULL);
}else{
ExitWindows(0,0);
SetWindowText(hwStatusBar,"Log off of the current user...");
}
break;
case 2 :
uiSize = SendMessage(hwCountDown,WM_GETTEXTLENGTH,0,0);
if(uiSize != 0){
usiChoice = 2;
SetTimer(hwnd,(UINT)1,ConvertHourToMillisecond(hwCountDown,uiSize),NULL);
}else{
token();
ExitWindowsEx(EWX_REBOOT | EWX_FORCE,0);
SetWindowText(hwStatusBar,"Reboot...");
}
break;
case 3 :
uiSize = SendMessage(hwCountDown,WM_GETTEXTLENGTH,0,0);
if(uiSize != 0){
usiChoice = 3;
SetTimer(hwnd,(UINT)1,ConvertHourToMillisecond(hwCountDown,uiSize),NULL);
}else{
token();
ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE,0);
SetWindowText(hwStatusBar,"Windows is shutting down");
}
break;
case 4 : MessageBox(hwnd,"Hour Format : 00:00:00","Format",MB_OK | MB_ICONINFORMATION);
break;
case 5 : KillTimer(hwnd,(UINT)1);break;
case 11 : PostQuitMessage(0);
break;
case 22 :
HGLOBAL hgMemory;
LPDLGTEMPLATE dltDlgHelp;
LPWORD lpWord;
LPWSTR lpwsWindowNameUnicode;
hgMemory = GlobalAlloc(GPTR,512);
if(!hgMemory) break;
dltDlgHelp = (LPDLGTEMPLATE) hgMemory;
dltDlgHelp->style = WS_CAPTION | WS_POPUP | DS_MODALFRAME | WS_SYSMENU | WS_MINIMIZEBOX;
dltDlgHelp->cx = 210;
dltDlgHelp->cy = 100;
dltDlgHelp->x = GetSystemMetrics(SM_CXSCREEN)/6;
dltDlgHelp->y = GetSystemMetrics(SM_CYSCREEN)/6;
lpWord = (LPWORD) (dltDlgHelp+1);
lpwsWindowNameUnicode = (LPWSTR) (lpWord+2);
MultiByteToWideChar(CP_ACP,0,"A propos de :",-1,lpwsWindowNameUnicode,128);
DialogBoxIndirect(GlobalHInstance,dltDlgHelp,0,(DLGPROC)PropoProc);
break;
}
}
return 0;
case WM_TIMER :
switch(usiChoice){
case 1 : ExitWindows(0,0);SetWindowText(hwStatusBar,"Log off of the current user...");break;
case 2 : token();ExitWindowsEx(EWX_REBOOT | EWX_FORCE,0);SetWindowText(hwStatusBar,"Reboot...");break;
case 3 : token();ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE,0);SetWindowText(hwStatusBar,"Windows is shutting down");break;
}
KillTimer(hwnd,(UINT)1);
return 0;
case WM_DESTROY :
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
void token(){
HANDLE haToken;
TOKEN_PRIVILEGES tpToken;
/* Crée une nouvelle "file" de process qui va s'ajuster au autre */
OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&haToken);
/* On recherche la valeur du privilège */
LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&tpToken.Privileges[0].Luid);
/* Nombre d'entrées dans le tableau des privileges */
tpToken.PrivilegeCount = 1;
/* On défini l'attribut */
tpToken.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(haToken,FALSE,&tpToken,sizeof(tpToken),NULL,NULL);
}
LRESULT CALLBACK PropoProc(HWND hwDlg, UINT message, WPARAM wParam, LPARAM lParam){
HWND hwGroup,hwButtonOk,hwLabelInfo;
HWND hwButtonSite,hwButtonMail;
switch(message){
case WM_INITDIALOG :
hwGroup = CreateWindow("button","MyReboot",WS_CHILD | WS_VISIBLE | BS_GROUPBOX,
10,10,400,160,hwDlg,NULL,GlobalHInstance,NULL);
hwButtonOk = CreateWindow("button","OK",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
16,146,30,20,hwDlg,(HMENU)111,GlobalHInstance,NULL);
hwLabelInfo = CreateWindow("static","Créer par : Deck_bsd \n\nVersion : 3.0 \n\nLicense : Freeware",WS_CHILD | WS_VISIBLE,
120,30,150,90,hwDlg,NULL,GlobalHInstance,NULL);
hwButtonSite = CreateWindow("button","http://deck-bsd.eurower.net",WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
120,115,200,20,hwDlg,(HMENU)1111,GlobalHInstance,NULL);
hwButtonMail = CreateWindow("button","deck_bsd01@yahoo.fr",WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
120,140,200,20,hwDlg,(HMENU)11111,GlobalHInstance,NULL);
HFONT PoliceComic;
HFONT PoliceVerdana;
PoliceComic = CreateFont(15,0,0,0,0,0,0,0,0,0,0,0,0,"comic sans MS");
PoliceVerdana = CreateFont(15,0,0,0,0,0,0,0,0,0,0,0,0,"verdana");
SendMessage(hwGroup,WM_SETFONT,(long)PoliceComic,0);
SendMessage(hwButtonOk,WM_SETFONT,(long)PoliceComic,0);
SendMessage(hwLabelInfo,WM_SETFONT,(long)PoliceVerdana,0);
SendMessage(hwButtonSite,WM_SETFONT,(long)PoliceVerdana,0);
SendMessage(hwButtonMail,WM_SETFONT,(long)PoliceVerdana,0);
break;
case WM_COMMAND :
if(HIWORD(wParam) == BN_CLICKED){
switch(LOWORD(wParam)){
case 111 :
EndDialog(hwDlg,0);
break;
case 1111 : ShellExecute(NULL,"open","http://deck-bsd.eurower.net",0,NULL,SW_MAXIMIZE);
break;
case 11111 : ShellExecute(NULL,"open","mailto:deck_bsd01@yahoo.fr",0,NULL,SW_MAXIMIZE);
break;
}
}
break;
case WM_CLOSE :
EndDialog(hwDlg,0);
break;
}
return 0;
}
unsigned int ConvertHourToMillisecond(HWND hwCountDown,unsigned int uiSize){
char *ptTime;
unsigned int uiHour,uiMin,uiSec,uiTotal;
ptTime = (char*)malloc(sizeof(char)*uiSize+1);
GetWindowText(hwCountDown,ptTime,uiSize+1);
sscanf(ptTime,"%d:%d:%d",&uiHour,&uiMin,&uiSec);
free(ptTime);
uiTotal = (uiHour*60)*60 + uiMin*60 + uiSec;
uiTotal *= 1000;
return uiTotal;
}
Historique
- 28 avril 2006 16:31:28 :
- - ortho
- 28 avril 2006 19:38:16 :
- - image
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Reboot/Shutdown ordinateur distant [ par Troie ]
Bonjour, j'aimerais savoir comment redémarrer et arrêter un ordinateur distant (en indiquant le nom de l'ordinateur par exemple) en utilisant VC++ ?Me
ShutDown ou Reboot : WM_QUERYENDSESSION ou WM_ENDSESSION [ par mfrai02 ]
Salut,lorsque je veux traiter le message WM_QUERYENDSESSION ou WM_ENDSESSION, je peux déterminer grace au lParam si l'utilisateur à réaliser un logoff
Comment on peut utiliser les timer avec Windows? [ par electroonn ]
Bonjour,je me demande comment on peut armer un timer en C++, je sais qu'il ya des fonctions comme SetTimer et KillTimer, mais je ne sais pas trop comm
Unicode et fichiers .RC ... [ par orbb ]
Bonjour,J'ai un programme unicode qui traite des données en arabe, et son interface decrite dans un fichier .rc (ressources) est en francais.Mon probl
SetTimer() [ par niou42 ]
Bonjourvoila j'aimerais mettre en place un timer ( et donc aussi un kill timer ) en c++j'ai un bouton dans une mfc qui contient ce code :while(true){
Timer Dll [ par wxccxw ]
Salut, j'ai une dll injecter et j'aimerai faire l'equivalent d'un sleep dedans pour attendre une seconde avant de lancer un truc quel method je doit u
Visual C++ 6 : error LNK2001: unresolved external symbol [ par gros_landais ]
Lorsque je link ce server TCP/IP avec Visual C++ 6.0 j'ai les erreurs de link suivante :--------------------Configuration: all - Win32 Debug----------
timer generer automatiquement [ par mars527 ]
Bonjour a tousvoila je vous expose mon probleme:je dois rendre un projet d'informatique la semaine prochaine, projet qui doit simuler un carrefour.la
INSERT dans une base de données access [ par hitle ]
Salut,Je suis actuellement en train de réaliser une application intranet. Pour ce projet j'ai besoin de faire des INSERT dans une base de données de t
Pb avec la fonction system ("shutdown....") [ par heresia83 ]
Bonjour ! Je débute en C.. et je n'arrive pas à faire fonctionner la fonction "system".J'ai fait de nombreuses recherches, notamment sur ce forum, j'a
|
Derniers Blogs
CSS CONTENT STATE SELECTORS (PERSONNAL DRAFT)CSS CONTENT STATE SELECTORS (PERSONNAL DRAFT) par FREMYCOMPANY
Bonjour à tous, Je viens de publier une proposition comprenant 5 pseudo-classes pour le CSS Working Group ayant trait à l'état de chargement d'un élément (ex: IMG,VIDEO,AUDIO,OBJECT pour l'HTML.). Si le c½ur vous en dit, vous pouvez retrouver cette p...
Cliquez pour lire la suite de l'article par FREMYCOMPANY MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ?MBA : POURQUOI FAIRE ET COMMENT LE CHOISIR ? par ROMELARD Fabrice
Formation initiale Durant la formation, le découpage classique est le suivant (je donnerai les équivalences Suisse lorsque je les connaîtrais) : Ecole primaire jusqu'au Collège : Formation générale permettant d'obtenir les méthodes...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice Y'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENTY'A DES ERREURS QUI PEUVENT RENDRE LE DéVELOPPEUR VIOLENT par Aleks
Quand on a ce genre d'erreur sans log :
Et bas on a juste envie de choper le gas de Microsoft qu'a développé ça et lui foutre des baffes de Coboye ! ...
Cliquez pour lire la suite de l'article par Aleks [HYPER-V 3] PRéSENTATION DES COMMANDLETS POWERSHELL[HYPER-V 3] PRéSENTATION DES COMMANDLETS POWERSHELL par Pierrick CATRO-BROUILLET
Avec la sortie prochaine de la Beta Consumer Preview de Windows 8, j'avais envie de revenir sur une des fonctionnalités que j'attends le plus et que, en bon geek que je suis, j'utilise déjà : Hyper-V 3 ainsi son module PowerShell.
Il y a déjà pléthor...
Cliquez pour lire la suite de l'article par Pierrick CATRO-BROUILLET IIS7 - COMPRESSION GZIPIIS7 - COMPRESSION GZIP par cyril
La compression GZIP permet d'améliorer les performances de navigation en compressant ce qu'envoie le serveur à un client. Pour comprendre comment cela fonctionne, regardons ce qu'il se passe au niveau HTTP lorsqu'un client tente d'accéder à une ress...
Cliquez pour lire la suite de l'article par cyril
Forum
ARBRE BINAIREARBRE BINAIRE par pacotheking
Cliquez pour lire la suite par pacotheking
Logiciels
Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning Academy System (17.1.3.0)ACADEMY SYSTEM (17.1.3.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|