www.oyunyapimi.org :: Başlığı Görüntüle - ExitWindowsEx() Calismiyo!
Önceki başlık :: Sonraki başlık
Yazar
Mesaj
AhmedHan Kayıt: Jun 01, 2005 Mesajlar: 7
Tarih: Tue Sep 27, 2005 2:27 pm Mesaj konusu: ExitWindowsEx() Calismiyo!
Acizane program kodum :
Kod:
#define _WIN32_IE 0x0601
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <shellapi.h> //for system tray and balloon tool-tips
#include <stdlib.h> //for atoi() and _itoa()
#include <string.h>
HWND hbSetTimer, hbReset;
HWND hsT, hsHM, hsMS;
HWND heH, heM, heS;
HWND hbShutdown, hbRestart, hbLogOff, hbForce;
HWND hWnd;
const UINT NID_ICOID = 500; //Randomly choosen
const UINT NID_CBMSG = 600; //Randomly choosen
NOTIFYICONDATA nid;
BOOLEAN bShutdown=FALSE, bRestart=FALSE, bForce=FALSE;
BOOLEAN bAutoRun = FALSE;
char cWindowState;
DWORD dwEditStyle;
INT iSecond, iMinute, iHour;
char szHour[3]="00", szMinute[3]="00", szSecond[3]="00";
UINT_PTR IDT_TIMER;
LONG Height = 125;
LONG Width = 225;
char szClassName[] = "WindowsApp";
LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM);
VOID CALLBACK TimerProcedure (HWND, UINT, UINT, DWORD);
int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{
if (strlen(lpszArgument) == 9)
{
szHour[0] = lpszArgument[3];
szHour[1] = lpszArgument[4];
szMinute[0] = lpszArgument[5];
szMinute[1] = lpszArgument[6];
szSecond[0] = lpszArgument[7];
szSecond[1] = lpszArgument[8];
bAutoRun = TRUE;
}
MSG messages;
IDT_TIMER=100; //A randomly choosen number. Actually I don't know how to use timers :)
dwEditStyle = (DWORD) (GWL_EXSTYLE, WS_VISIBLE | WS_CHILD | ES_LEFT | ES_NUMBER | WS_TABSTOP);
WNDCLASSEX WindowClass;
WindowClass.cbSize = sizeof (WNDCLASSEX);
WindowClass.style = CS_DBLCLKS;
WindowClass.lpfnWndProc = WindowProcedure;
WindowClass.cbClsExtra = 0;
WindowClass.cbWndExtra = 0;
WindowClass.hInstance = hThisInstance;
WindowClass.hIcon = (HICON) LoadImage(NULL, "Icon.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
WindowClass.hCursor = LoadCursor (NULL, IDC_ARROW);
WindowClass.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
WindowClass.lpszMenuName = NULL;
WindowClass.lpszClassName = szClassName;
WindowClass.hIconSm = (HICON) LoadImage(NULL, "SmIcon.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
if (!RegisterClassEx (&WindowClass)) return 0;
hWnd = CreateWindowEx (
0,
szClassName,
"Shutdown v1.0",
WS_MINIMIZEBOX | WS_SYSMENU,
CW_USEDEFAULT,
CW_USEDEFAULT,
Width,
Height,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL);
ShowWindow(hWnd, nFunsterStil);
LONG tLeft=5;
LONG tTop=5;
LONG tWidth=135;
LONG tHeight=16;
hsT = CreateWindowEx(
0,
"STATIC",
"Remaining Time =",
WS_VISIBLE | WS_CHILD | SS_LEFT | WS_TABSTOP,
tLeft,
tTop,
tWidth,
tHeight,
hWnd,
NULL,
(HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE),
NULL);
LONG hLeft = tLeft + tWidth;
LONG hTop=tTop;
LONG hWidth=20;
heH = CreateWindowEx(
0,
"EDIT",
szHour,
dwEditStyle,
hLeft,
hTop,
hWidth,
tHeight,
hWnd,
NULL,
(HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE),
NULL);
LONG hmLeft = hLeft + hWidth;
LONG hmTop=tTop;
LONG hmWidth=5;
hsHM = CreateWindowEx(
0,
"STATIC",
":",
WS_VISIBLE | WS_CHILD | SS_LEFT | WS_TABSTOP,
hmLeft,
hmTop,
hmWidth,
tHeight,
hWnd,
NULL,
(HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE),
NULL);
LONG mLeft = hmLeft + hmWidth;
LONG mTop=tTop;
LONG mWidth=20;
heM = CreateWindowEx(
0,
"EDIT",
szMinute,
dwEditStyle,
mLeft,
mTop,
mWidth,
tHeight,
hWnd,
NULL,
(HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE),
NULL);
LONG msLeft = mLeft + mWidth;
LONG msTop=tTop;
LONG msWidth=5;
hsMS = CreateWindowEx(
0,
"STATIC",
":",
WS_VISIBLE | WS_CHILD | SS_LEFT | WS_TABSTOP,
msLeft,
msTop,
msWidth,
tHeight,
hWnd,
NULL,
(HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE),
NULL);
LONG sLeft = msLeft + msWidth;
LONG sTop=tTop;
LONG sWidth=20;
heS = CreateWindowEx(
0,
"EDIT",
szSecond,
dwEditStyle,
sLeft,
sTop,
sWidth,
tHeight,
hWnd,
NULL,
(HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE),
NULL);
LONG rsLeft=tLeft-7;
LONG rsTop = tTop + tHeight + 5;
LONG rsWidth=81;
LONG rsHeight=16;
hbShutdown = CreateWindowEx(
0,
"BUTTON",
"Shutdown",
WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP,
rsLeft,
rsTop,
rsWidth,
rsHeight,
hWnd,
NULL,
(HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE),
NULL);
if (!bAutoRun) SendMessage(hbShutdown, BM_SETCHECK, BST_CHECKED, (LPARAM) NULL);
LONG rrLeft = tLeft + rsWidth;
LONG rrTop = rsTop;
LONG rrWidth=66;
LONG rrHeight=rsHeight;
hbRestart = CreateWindowEx(
0,
"BUTTON",
"Restart",
WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP,
rrLeft,
rrTop,
rrWidth,
rrHeight,
hWnd,
NULL,
(HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE),
NULL);
LONG rlLeft = rrLeft + rrWidth;
LONG rlTop = rsTop;
LONG rlWidth=75;
LONG rlHeight=rsHeight;
hbLogOff = CreateWindowEx(
0,
"BUTTON",
"Log-Off",
WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON | WS_TABSTOP,
rlLeft,
rlTop,
rlWidth,
rlHeight,
hWnd,
NULL,
(HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE),
NULL);
LONG cfLeft=tLeft;
LONG cfTop = rrTop + rrHeight + 5;
LONG cfWidth=200;
LONG cfHeight=rsHeight;
hbForce = CreateWindowEx(
0,
"BUTTON",
"Force (Not recommended!)",
WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX | WS_TABSTOP,
cfLeft,
cfTop,
cfWidth,
cfHeight,
hWnd,
NULL,
(HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE),
NULL);
LONG stLeft=tLeft;
LONG stTop = cfTop + cfHeight + 5;
LONG stWidth=100;
LONG stHeight=25;
hbSetTimer = CreateWindowEx(
0,
"BUTTON",
"Set Timer",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON | WS_TABSTOP,
stLeft,
stTop,
stWidth,
stHeight,
hWnd,
NULL,
(HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE),
NULL);
LONG brLeft = stLeft + stWidth + 5;
LONG brTop=stTop;
LONG brWidth=100;
LONG brHeight=25;
hbReset = CreateWindowEx(
0,
"BUTTON",
"Reset",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON | WS_TABSTOP,
brLeft,
brTop,
brWidth,
brHeight,
hWnd,
NULL,
(HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE),
NULL);
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.hWnd = hWnd;
nid.uID = NID_ICOID;
nid.uFlags = NIF_MESSAGE | NIF_TIP | NIF_INFO | NIF_ICON;
nid.uCallbackMessage = NID_CBMSG;
nid.hIcon = (HICON) LoadImage(NULL, "TrayIcon.ico", IMAGE_ICON, 0, 0, LR_LOADFROMFILE);
lstrcpy(nid.szTip, "Double-Click To Maximize.");
nid.dwState = NIS_SHAREDICON;
nid.dwStateMask = NIS_SHAREDICON;
lstrcpy(nid.szInfo, "Doublelick to maximize...");
nid.uTimeout = 10;
lstrcpy(nid.szInfoTitle,"Shutdown v1.0");
nid.dwInfoFlags = NIF_INFO;
//nid.guidItem = NULL;
if (bAutoRun)
{
char cRequest = lpszArgument[0];
char cForce = lpszArgument[1];
cWindowState = lpszArgument[2];
switch (cRequest)
{
case 'S':
lstrcpy(nid.szInfo, "Shutdown will proceed after the countdown.");
lstrcpy(nid.szInfoTitle,"Shutdown in progress!");
bShutdown = TRUE;
SendMessage(hbShutdown, BM_SETCHECK, BST_CHECKED, (LPARAM) NULL);
break;
case 'R':
lstrcpy(nid.szInfo, "Restart will proceed after the countdown.");
lstrcpy(nid.szInfoTitle,"Restart in progress!");
bRestart = TRUE;
SendMessage(hbRestart, BM_SETCHECK, BST_CHECKED, (LPARAM) NULL);
break;
default:
lstrcpy(nid.szInfo, "Log-Off will proceed after the countdown.");
lstrcpy(nid.szInfoTitle,"Log-Off in progress!");
SendMessage(hbLogOff, BM_SETCHECK, BST_CHECKED, (LPARAM) NULL);
break;
}
switch (cWindowState)
{
case 'N':
//Do nothing
break;
case 'M':
ShowWindow(hWnd, SW_MINIMIZE);
break;
case 'S':
Shell_NotifyIcon(NIM_ADD, &nid);
ShowWindow(hWnd, SW_HIDE);
break;
}
if (cForce == 'F')
{
bForce=TRUE;
SendMessage(hbForce, BM_SETCHECK, BST_CHECKED, (LPARAM) NULL);
}
SendMessage(heH, WM_GETTEXT, (WPARAM) 3, (LPARAM) szHour);
SendMessage(heM, WM_GETTEXT, (WPARAM) 3, (LPARAM) szMinute);
SendMessage(heS, WM_GETTEXT, (WPARAM) 3, (LPARAM) szSecond);
iHour =atoi(szHour);
iMinute=atoi(szMinute);
iSecond=atoi(szSecond);
SetTimer(hWnd, IDT_TIMER, 1000, (TIMERPROC) TimerProcedure);
EnableWindow(hbSetTimer, FALSE);
}
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
LRESULT CALLBACK WindowProcedure (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_COMMAND:
if (HIWORD(wParam) == BN_CLICKED)
{
if ((HANDLE) lParam == (HANDLE) hbSetTimer)
{
SendMessage(heH, WM_GETTEXT, (WPARAM) 3, (LPARAM) szHour);
SendMessage(heM, WM_GETTEXT, (WPARAM) 3, (LPARAM) szMinute);
SendMessage(heS, WM_GETTEXT, (WPARAM) 3, (LPARAM) szSecond);
iHour =atoi(szHour);
iMinute=atoi(szMinute);
iSecond=atoi(szSecond);
SetTimer(hWnd, IDT_TIMER, 1000, (TIMERPROC) TimerProcedure);
EnableWindow(hbSetTimer, FALSE);
}
else if ((HANDLE) lParam == (HANDLE) hbReset)
{
KillTimer(hWnd, IDT_TIMER);
EnableWindow(hbSetTimer, TRUE);
}
}
break;
case WM_SYSCOMMAND:
DefWindowProc (hWnd, message, wParam, lParam);
if (wParam == SC_MINIMIZE)
{
Shell_NotifyIcon(NIM_ADD, &nid);
ShowWindow(hWnd, SW_HIDE); //Wild goose chase!
ShowWindow(hWnd, SW_SHOWNORMAL); //Sorry! Couldn't find a better way...
ShowWindow(hWnd, SW_HIDE);
}
break;
case WM_DESTROY:
KillTimer(hWnd, IDT_TIMER);
Shell_NotifyIcon(NIM_DELETE, &nid);
PostQuitMessage (0);
break;
case NID_CBMSG:
if ((wParam == NID_ICOID) && (lParam == WM_LBUTTONDBLCLK))
{
ShowWindow(hWnd, SW_RESTORE);
Shell_NotifyIcon(NIM_DELETE, &nid);
}
break;
default:
return DefWindowProc (hWnd, message, wParam, lParam);
}
return 0;
}
VOID CALLBACK TimerProcedure(HWND hWnd, UINT message, UINT idTimer, DWORD dwTime)
{
if ((iHour==0) && (iMinute==0) && (iSecond==0))
{
KillTimer(hWnd, IDT_TIMER);
if (!bAutoRun)
{
LRESULT lResult;
lResult = SendMessage(hbShutdown, BM_GETCHECK, (WPARAM) NULL, (LPARAM) NULL);
if (lResult == BST_CHECKED) bShutdown=TRUE; else bShutdown=FALSE;
lResult = SendMessage(hbRestart, BM_GETCHECK, (WPARAM) NULL, (LPARAM) NULL);
if (lResult == BST_CHECKED) bRestart=TRUE; else bRestart=FALSE;
lResult = SendMessage(hbForce, BM_GETCHECK, (WPARAM) NULL, (LPARAM) NULL);
if (lResult == BST_CHECKED) bForce=TRUE; else bForce=FALSE;
}
UINT uFlags;
DWORD dwReason = 0;
if (bShutdown)
{
if (bForce)
{
uFlags = EWX_POWEROFF | EWX_FORCE;
}
else
{
uFlags = EWX_POWEROFF;
}
}
else if (bRestart)
{
if (bForce)
{
uFlags = EWX_REBOOT | EWX_FORCE;
}
else
{
uFlags = EWX_REBOOT;
}
}
else
{
if (bForce)
{
uFlags = EWX_LOGOFF | EWX_FORCE;
}
else
{
uFlags = EWX_LOGOFF;
}
}
ExitWindowsEx((UINT) uFlags, (DWORD) dwReason);
return;
}
iSecond--;
if (iSecond<0)
{
iSecond=59;
iMinute--;
}
if (iMinute<0)
{
iMinute=59;
if (iHour>0) iHour--;
}
_itoa(iHour, szHour, 10);
_itoa(iMinute, szMinute, 10);
_itoa(iSecond, szSecond, 10);
if (strlen(szHour) == 1)
{
szHour[1] = szHour[0];
szHour[0] = '0';
szHour[2] = (char) NULL;
}
if (strlen(szMinute) == 1)
{
szMinute[1] = szMinute[0];
szMinute[0] = '0';
szMinute[2] = (char) NULL;
}
if (strlen(szSecond) == 1)
{
szSecond[1] = szSecond[0];
szSecond[0] = '0';
szSecond[2] = (char) NULL;
}
SendMessage(heH, WM_SETTEXT, (WPARAM) NULL, (LPARAM) szHour);
SendMessage(heM, WM_SETTEXT, (WPARAM) NULL, (LPARAM) szMinute);
SendMessage(heS, WM_SETTEXT, (WPARAM) NULL, (LPARAM) szSecond);
}
Program Windows XP'de hic bisey yapmiyor. Windows 2000'de ise sadece log-off yapabiliyor.
Bu benim yazdigim ilk Win32 programi ve calismamasi cok moral bozucu birsey!!!
API'nin duzgun calismamasinin sebebi ne olabilir?
Başa dön
MD-C Kayıt: Feb 26, 2003 Mesajlar: 1258 Nereden: Dünya.Türkiye(54)
Tarih: Tue Sep 27, 2005 7:45 pm Mesaj konusu:
Doğru yapsam bile: Oturum kapanacaktır, PC değil! Bunun için farklı bir yol denemen gerek: Bu konuda MSDN'de bir yazı görmüştüm! (restart için)
Başa dön
AhmedHan Kayıt: Jun 01, 2005 Mesajlar: 7
Tarih: Wed Sep 28, 2005 1:20 pm Mesaj konusu:
Hayır, MSND'de fonksiyon tanıtılırken açıkça "PC kapanacaktır" deniyo.
Başa dön
3ddreams Kayıt: Nov 28, 2003 Mesajlar: 352 Nereden: İstanbul
Tarih: Wed Sep 28, 2005 7:12 pm Mesaj konusu:
senin koda bakmadım ama işler win2000 de ve xp de değişiyor. win 98 de sorunsuz çalışacaktır senin kod. Xp veya win2000 için aşağıdaki kodu kullan.
Kod:
// Wkapan.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
printf("kapan susam kapan");
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken);
// Get the LUID for the shutdown privilege.
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get the shutdown privilege for this process.
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
// Shut down the system and force all applications to close.
ExitWindowsEx(EWX_POWEROFF, 0) ;
return 0;
}
Başa dön
MD-C Kayıt: Feb 26, 2003 Mesajlar: 1258 Nereden: Dünya.Türkiye(54)
Tarih: Wed Sep 28, 2005 7:33 pm Mesaj konusu:
3ddreams demiş ki:
senin koda bakmadım ama işler win2000 de ve xp de değişiyor....
Evet bende bunu anlatmaya çalıştım farklı bir dilde
Başa dön
Bu forumda yeni konular açamazsınız Bu forumdaki mesajlara cevap veremezsiniz Bu forumdaki mesajlarınızı değiştiremezsiniz Bu forumdaki mesajlarınızı silemezsiniz Bu forumdaki anketlerde oy kullanamazsınız
Powered by phpBB 2.x.x © 200x phpBB Group Türkçe Çeviri : Onur Turgay & Erdem Çorapçıoğlu Türkçe Düzenleme: Alexis Canver
Version 2.x.x of PHP-Nuke Port by Tom Nitzschner © 200x www.toms-home.com