|
Hi,
I have a program and somewhere in the program, I need to shutdown the computer. The following code works fine on my machine (W2K) however, it does not work on some other machines ( on Win98 and NT ). It does not shutdown the computer, instead it logs off or reboots the computer.
Please help. Is there any way to shutdown the computer without any problems (not only shutdown but also power off!)?
Best Regards
-----------------------
int CTaskStep::ExecuteShutDown ( CTaskObject *pTask , bool bReboot)
{
HANDLE hProcess = GetCurrentProcess(); // Is pseudohandle, no close needed
HANDLE hToken = NULL;
OpenProcessToken(hProcess,TOKEN_ADJUST_PRIVILEGES,&hToken);
if ( hToken )
{
TOKEN_PRIVILEGES priv_struct;
LUID_AND_ATTRIBUTES priv;
LUID priv_luid;
BOOL bRet;
bRet = LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &priv_luid);
priv.Attributes = SE_PRIVILEGE_ENABLED;
priv.Luid = priv_luid;
priv_struct.PrivilegeCount = 1;
priv_struct.Privileges->Attributes = SE_PRIVILEGE_ENABLED;
priv_struct.Privileges->Luid = priv_luid;
bRet = AdjustTokenPrivileges(hToken, FALSE, &priv_struct,NULL,NULL, NULL);
CloseHandle( hToken );
}
// Restart and give message to restart if failed
if ( bReboot )
{
if(!ExitWindowsEx (EWX_REBOOT | EWX_FORCE,0) )
{
CString str;
str.LoadString( IDS_MBOX_FAILED_RESTART );
AfxMessageBox(str,MB_ICONERROR);
m_bFailed = true;
}
}
else
{
if(!ExitWindowsEx(EWX_POWEROFF | EWX_FORCE,0))
{
CString str;
str.LoadString( IDS_MBOX_FAILED_SHUTDOWN );
AfxMessageBox(str,MB_ICONERROR);
m_bFailed = true;
}
}
return EX_CONTINUE;
}
Mustafa Demirhan
|
|
|
|
|
Hi
Does anybody know of an ActiveX, or something else, which I could use to display PDF files in the View of an SDI application I have written?
Thanks in advance
Dave
|
|
|
|
|
No, but you can use IE as a control and pass it a pdf.
Christian
The content of this post is not necessarily the opinion of my yadda yadda yadda.
To understand recursion, we must first understand recursion.
|
|
|
|
|
Not really true. You can actually do it. However, it is a bit of a hack.
Available methods:
1. Official
Buy the Acrobat program and use the SDK.
2. Hacking!
Acrobat reader actually installs two types of ocx. The real stuff with name
as pdf41.ocx or pdf42.ocx depending on your machine AND a crippling version pdf.ocx
as the so-called main. In some installations the pdf41.ocx/pdf42.ocx in never installed, I have still not taken the time to find the circumstances.
Now, the pdf.ocx will not allow you to use the reader in your view or dialog.
However, pdf41.ocx/pfd42.ocx will.
The trick is to unregister the pdf.ocx and manually register the pdf41.ocx/pdf42.ocx
and you can generate the C++ wrapper classes with the Visual C++ gallery or classwiz.
I did this for a TeX/LaTeX IDE I was working on--an open source effort and we could
not use the paid version!!!
Regards,
Paul.
Paul Selormey, Bsc (Elect Eng), MSc (Mobile Communication) is currently Windows open source developer in Japan, and open for day job or programming contract anywhere!
|
|
|
|
|
Sorry, I should be careful how I word things - I meant no, I don't know.
Christian
The early bird may get the worm, but it's the second mouse that gets the cheese.
|
|
|
|
|
I have an MDI application implemented using third-party controls. I have implemented the basic OLE drag and drop. I am stuck trying to get a tree node to expand when I hover over it. My code implements the OnDragOver, OnDrop, OnDragLeave, OnDragEnter, OnBeginDrag. The sample code uses the old style drag and drop. When I add OnMouseMove and OnTimer methods, they never get control. I have debug tracing in the various methods. I have looked at Jeff Prosise's book but have found nothing that seems similar to my situation. I have tried moving the code from OnMouseMove to OnDragOver. Then the OnTimer method does not get invoked. I have tried calling SetFocus, but that does not help either. I am a MFC novice. Can anyone point me in the right direction?
|
|
|
|
|
I was able to implement this feature for OLE drag'n'drop in CTreeCtrl. I had to derive the class from COleDropTarget and override OnDragScroll method. This way I was able to handle the scrolling and expanding during the DnD.
I'm including the code here, surely it will be formatted incorrectly, but may be helpful.
DROPEFFECT CNavigationTree::DropTarget::OnDragScroll(CWnd *pWnd, DWORD dwKeyState, CPoint point)
{
DROPEFFECT dropEffect = DropEffectFromKeyState(dwKeyState);
DWORD currentTicks = ::GetTickCount();
CTreeCtrl &tree = *static_cast<ctreectrl *="">(pWnd);
UINT flags;
HTREEITEM hti = tree.HitTest(point, &flags);
if (hti != m_htiLastItem)
{
m_htiLastItem = hti;
m_lastItemTicks = currentTicks;
}
if (currentTicks - m_lastTicks < DD_DEFSCROLLDELAY)
{
return dropEffect;
}
m_lastTicks = currentTicks;
if (NULL != hti)
{
if (point.y < DD_DEFSCROLLINSET)
{
tree.SendMessage(WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), NULL);
return dropEffect | DROPEFFECT_SCROLL;
}
CRect rcClient;
tree.GetClientRect(rcClient);
if (point.y > rcClient.bottom - DD_DEFSCROLLINSET)
{
tree.SendMessage(WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), NULL);
return dropEffect | DROPEFFECT_SCROLL;
}
if (currentTicks - m_lastItemTicks > 500 &&
(flags & (TVHT_ONITEM | TVHT_ONITEMBUTTON)) != 0 &&
tree.ItemHasChildren(hti) &&
tree.GetItemState(hti, TVIS_EXPANDED) != TVIS_EXPANDED)
{
tree.Expand(hti, TVE_EXPAND);
}
}
return dropEffect;
}
Tomasz Sowinski
http://www.shooltz.com.pl
|
|
|
|
|
Hi guys,
I have a dialog based app, that I want to copy files from one location to the a:\
The user clicks a button & the files are copied. The user has no control over the folder files that are copied.
I want to be able to check that a disk is in the a:\, & then start copying the files, if the a:\ fills up, don't copy any more files, & if it's in the middle of a copy to rollback & not cancel that file copy.
How best can I do this....sample code or direction to site is good.
Gerry.
|
|
|
|
|
Is it possible to pass formatted string to functions?
//function prototype
void find(CString s, int n);
//code 1
//this is what I want to implement
find("0=", nLevel);
// do something
find("1=", nLevel);
// do something
find("2=", nLevel);
// do something
// code2
// to implement the above in a for loop
// can I do something like this?
for (i = 0, i<=3, i++)
{
//blah blah
find("%d=" i, nLevel);
// blah blah
}
code 2 obviously doesnt work, but is there any other way I can implement code 1?
pls help
|
|
|
|
|
Hi !
Try this:
void find(CString& s, int n);
for (i = 0, i<=3, i++)
{
//blah blah
CString str ;
str.Format("%d", i);
find(str, nLevel);
// blah blah
}
===========================
Is it possible to pass formatted string to functions?
//function prototype
void find(CString s, int n);
//code 1
//this is what I want to implement
find("0=", nLevel);
// do something
find("1=", nLevel);
// do something
find("2=", nLevel);
// do something
// code2
// to implement the above in a for loop
// can I do something like this?
for (i = 0, i<=3, i++)
{
//blah blah
find("%d=" i, nLevel);
// blah blah
}
code 2 obviously doesnt work, but is there any other way I can implement code 1?
Best regards,
-----------
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
igor_soukhov@mailru.com | ICQ:57404554 | http://siv.da.ru
|
|
|
|
|
try something like:
void findV (LPCSTR szFormat, int nLevel,...)
{
va_list argList;
va_start(arglist, nLevel);
CString str;
str.FormatV (szFormat, argList);
va_end(argList);
find(str, nLevel);
}
you can then do
for (int x =0; x<3; x++)
{
findV("%d=", nLevel, x);
}
The nLevel in there makes it kind of odd. If this is an out parameter you might want to change it to a return value.
|
|
|
|
|
Hello everyone!!!!
I've to capture the window messages of programs in execution from my application developed in Visual C++ 6.0.
I'd like to access to the window text and buttons text of any message error. How could I do this?????
Thanks in advance.
|
|
|
|
|
Hi !
Take a look at hooks.
Best regards,
-----------
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
igor_soukhov@mailru.com | ICQ:57404554 | http://siv.da.ru
|
|
|
|
|
Could you have more details in relation to your answer or sample code, please??
Thanks in advance,
LuisFer.
|
|
|
|
|
Using SetWindowsHookEx you should set global hook. Hook procedure should be placed in DLL.
Best regards,
-----------
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
igor_soukhov@mailru.com | ICQ:57404554 | http://siv.da.ru
|
|
|
|
|
Using SetWindowsHookEx you should set global hook. Hook procedure should be placed in DLL.
Use WH_CALLWNDPROC hook type to intercept messages.
Best regards,
-----------
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
igor_soukhov@mailru.com | ICQ:57404554 | http://siv.da.ru
|
|
|
|
|
Thank you for your previous answer, but I need more information or sample code about "Hooks" taking into account my knowledge of Visual C++. I've seen the SetWindowsHookEx function but I don't understand how to use it.
Thanks in advance and best wishes,
LuisFer.
|
|
|
|
|
I took a look, I saw a nook, and on his head he had a hook. On his hook, he had a book, and on his book said how to cook. But a nook, can't read, so a nook can't cook, so what use to a nook is a hook cook book ?
Sorry, it's early Friday....
Christian
The content of this post is not necessarily the opinion of my yadda yadda yadda.
To understand recursion, we must first understand recursion.
|
|
|
|
|
If you don't want to program, you can use the Spy++ tool with ships with VC++.
You can use it to detect all messages received by the window you can inspect.
Regards
Luis
|
|
|
|
|
can't get this code working.
DWORD fileLength = workFile.GetLength(); //line 1
char fileBuf[fileLength]; //line 2
workFile.Read(fileBuf, fileLength); //line 3
compiler says (all for line 2):
error C2057: expected constant expression
error C2466: cannot allocate an array of constant size 0
error C2133: 'fileBuf' : unknown size
|
|
|
|
|
Hi !
Try this:
DWORD fileLength = workFile.GetLength(); //line 1
//char fileBuf[fileLength]; //line 2
char * fileBuf = new char[fileLength];
workFile.Read(fileBuf, fileLength); //line 3
....
delete[] fileBuf;
Best regards,
-----------
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
igor_soukhov@mailru.com | ICQ:57404554 | http://siv.da.ru
|
|
|
|
|
thanz.. that solved part of the problem.. now the compiler says that fileBuf is undeclared (line 2)
*confused*
|
|
|
|
|
correction to my previous post ... the error lies in the line:
delete[] fileBuf;
it says identifier undeclared.
|
|
|
|
|
please ignore all my previous post.. the problem is fixed.. overlooked some areas..
thanz a lot for your help!
|
|
|
|
|
If I make the broadcast to a real nameserver it is ok. If I give INADDR_BROADCAST , no one response. Kindly help to me.
Thankyou
Anita Eugene
|
|
|
|
|