|
Can anyone guide me on how to go about programmatically powering down a Windows 98 system - I'm pretty confused about what sequence of functions should be used to achieve this. Any recomendadtions would be appreciated !
Doug
|
|
|
|
|
Lookup ExitWindowsEx in MSDN.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
I tried to use the sample code given in MSDN for shutting down the system using ExitWindowsEx(). (I've reproduced it below for reference):-
BOOL MySystemShutdown()
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
// Get a token for this process.
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return( FALSE );
// 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);
if (GetLastError() != ERROR_SUCCESS)
return FALSE;
// Shut down the system and force all applications to close.
if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0))
return FALSE;
return TRUE;
}
It worked fine on my Win2000 Pro system but not on the Win98 machine (for which I actually need it !). It fails on the
OpenProcessToken() function and when I call GetLastError() in response, it returns a value of 120 ("The function is not
supported on this system")
How should I be using ExitWindowsEx on Win98 ?? (or is there a better way to do it ?)
Thanks for any help !
Doug
|
|
|
|
|
Windows 9x does not use privileges, just call ExitWindowsEx directly. You can use GetVersionEx to see if the program is running on 9x or NT.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
Hi again !!
I have now just used ExitWindowsEx(), but the program just returns without causing the PC to power down - however, I can't get it to stop at a breakpoint beyong ExitWindowsEx(). I should say that this was the problem that I had before I made my original post asking for help !! I'm calling the function as follows:-
BOOL rc;
rc = ExitWindowsEx(EWX_POWEROFF | EWX_FORCE | EWX_LOGOFF, 0);
if (!rc)
{
dwError = GetLastError();
}
Hopefully someone can tell me what I'm doing wrong !!
Doug
|
|
|
|
|
From the MSDN article on ExitWindowsEx
Parameters
uFlags
[in] Specifies the type of shutdown. This parameter must include one of the following values. This leads me to believe that the EWX_* values you specified are supposed to be mutually exclusive.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
Hi PJ,
AT LONG LAST, I've cracked it !! Despite the descriptions of the possible values for uiFlags, EWX_SHUTDOWN appears to do the trick !! For reference, the values are EWX_POWEROFF = 8, EWX_FORCE = 4, EWX_REBOOT = 2, EWX_SHUTDOWN = 1, EWX_LOGOFF = 0. These are clearly bit-orientated and one would therefore assume that they could/should be used in combination. (I really don't understand why the use of EWX_SHUTDOWN doesn't result in the message "The system may now be powered off" and why don't I need to use EWX_FORCE (or maybe I do ?) Anyway, thanks for staying with me through this "journey" !!
Doug
|
|
|
|
|
Hello
I am trying to use the built-in OSK (On-Screen Keyboard) that comes bundled with W2K and Win-XP. I need this inside a STATIC control in my dialog based app.
So, I use
ShellExecute(AfxGetMainWnd()->m_hWnd,_T("open"),_T("osk.exe"), NULL, NULL, SW_SHOWMINIMIZED );
And do a bit of gymnastics to resize it into the static, remove the menu and the caption through using the following:
CMenu* pMenu = cOsk->GetMenu();
if(pMenu) // We don't want the users to 'Play' with any of the functions
{ pMenu->DeleteMenu(3,MF_BYPOSITION);
pMenu->DeleteMenu(2,MF_BYPOSITION);
pMenu->DeleteMenu(1,MF_BYPOSITION);
pMenu->DeleteMenu(0,MF_BYPOSITION);
}
cOsk->ModifyStyle(WS_CAPTION | WS_THICKFRAME ,WS_POPUP, SWP_NOSIZE );
cOsk->DrawMenuBar();
It all works fine as intended, but the initial load of the OSK flickers at the default place on screen, and only after that gets moved through ha call to MoveWindow() to where I need it
If anyone has any idea on how to load the OSK in a “Silent” mode, so that I can do what I want and only then show it to the user – please tell..
Cheers
Alex
|
|
|
|
|
Would you please let me know some concepts ,algorithms or codes regarding to the translation from a regional language(i.e.,Bengali) to English.Its may be a part of transliteration also.Particularly, it is needy to identify proper nouns from a given sentence or statement.How would I implement this?I approached to search a database (say,some.mdb)having names of persons in ISCII format .But it may become time consuming!!
Let it be identified, then is it possible to translate without searching database?
Help me.......
|
|
|
|
|
How to make a disabled button enabled at runtime by pressing a certain button
|
|
|
|
|
Call the disabled button's EnableWindow(TRUE) when the trigger button is pressed.
If this doesn't work, you may have to add an Update handler for the disabled button. Let me know....
Bob Ciora
|
|
|
|
|
In the "certain" button's handler, enable the disabled button by calling EnableWindow() . For example:
void CMyDialog::OnCertainButton()
{
m_disabledButton.EnableWindow (TRUE);
}
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
I have a struct
struct CoData {
float x;
float y;
};
// Adding position of mouse every left click
CArray<codata,codata> arrayPoint;
CoData strRawCoords, strOut;
CString m_list;
if((nFlags & MK_LBUTTON) == MK_LBUTTON) {
strRawCoords.x = point.x;
strRawCoords.y = point.y;
arrayPoint.Add(strRawCoords);
}
// Print out the coordinates when right click
if((nFlags & MK_RBUTTON) == MK_RBUTTON) {
for(int i=0;i<getupperbound();i++) {
="" strout="arrayPoint.GetAt(i);
" m_list.format("%f="" %f",strout.x,strout.y);
="" pdc-="">TextOut(0,0,m_list);
pDC->SetTextColor(RGB(0,0,0));
pDC->SelectObject(NormalPen);
}
}
Cant work.
|
|
|
|
|
Do you see any output at all?
Is all of this within your OnMouseMove function? If so, then the problem is one of scope.
arrayPoint is local to OnMouseMove . When OnMouseMove exits, the array is destroyed, since its a local variable of OnMouseMove . So every time the mouse moves and your OnMouseMove is called, it builds, then destroys, this array.
Try moving the array out of the function and make it a member variable of your window or dialog.
Hope this helps!
Bob Ciora
|
|
|
|
|
Hi thanks,
Can you give me some guides?
|
|
|
|
|
First off, did that fix the problem?
What sorts of guides are you looking for? This website is full of guides! For general VisualStudio programming, I find the MSDN Library[^] an invaluable source of information.
Bob Ciora
|
|
|
|
|
I understand but it tried to create member variable but the VC++ doesnt allow me to add CArray<mystruct,mystruct> type of variable. I need more detail solution. I am new to VC++ but have C b/ground. THanks.
|
|
|
|
|
Instead of making the CArray a member of the class, just move the declaration to just above your OnMouseMove function. This moves it outside the function and outside the class. Effectively, it becomes a global variable *shudder* but it should still put a temporary band-aid on the problem.
As for C++ in general, if you're a seasoned C programmer, see if you can find a book called "Moving From C To C++". I got this book about 10 years ago, and it's the only C++ book I've ever needed.
Bob Ciora
|
|
|
|
|
Hi thanks
Do you mean outside the class or outside the onmouseover? It is actually outside the onmouseover and inside the class.
Do you mean declaring as public variable? What kind of type of variable shld I use? CArray <codata,codata>? The VC++ doesnt allow me the declare this type.
Someone in the forum mentioned to create another header file and include it before declaring it. I got a lot of errors after I did that.
|
|
|
|
|
i compile a COM then use it (by Windows).
when i try to re-compile it, VC said "can not open file ..."
it means VC can not delete it for generating a new one.
i try to delete the COM manually from Explorer but failed.
after use Regsvr32 to unregister the COM, i still can not delete the COM.
i have to restart my PC for any code modifications.
How to solve the problem?
thx
includeh10
|
|
|
|
|
Are you AddRef 'ing and Release 'ing the COM object correctly in your application? It could be that the object's ref count never got cleared, and the object won't remove itself because of it.
Bob Ciora
|
|
|
|
|
Hi Bob,
thanks.
I am testing a sample downloaded.
the sample uses a ref count (ULONG m_uRefCount) initialized as 1 in construct;
in AddRef(), the count inc 1;
in Release(), the count dec 1;
in QueryInterface(), it may inc 1;
is the idea right?
details are in followings:
----------------------------------------
//construct
CContextMenu::CContextMenu()
{
m_uRefCount=1;
}
STDMETHODIMP_(ULONG)CContextMenu::AddRef()
{
return ++m_uRefCount;
}
STDMETHODIMP_(ULONG)CContextMenu::Release()
{
if(--m_uRefCount==0)
{
delete this;
return 0;
}
return m_uRefCount;
}
STDMETHODIMP CContextMenu::QueryInterface(REFIID iid,LPVOID FAR*ppv)
{
m_uRefCount++;
if(IsEqualIID(riid,IID_IUnknown))
{
*ppv=this;
return NOERROR;
}
else if(IsEqualIID(riid,IID_IShellExtInit))
{
*ppv=(LPSHELLEXTINIT)this;
return NOERROR;
}
else if(IsEqualIID(riid,IID_IContextMenu))
{
*ppv=(IContextMenu*)this;
return NOERROR;
}
else
{
m_uRefCount--;
*ppv=0;
return ResultFromScode(E_NOINTERFACE);
}
}
m_uRefCount is NOT used by other placess.
what is wrong?
|
|
|
|
|
Isn't it a shell exension? (what I can guess from the code). In that case the explorer.exe holds your dll. You need to kill the explorer process somehow - first method is to simply kill it in taskman, but there's some other method - after you do ctrl-alt-del, but I can't remember it now - check the codeproject's page about shell extensions.
|
|
|
|
|
Can anybody tell me why this won't break out of the for() loop when it returns -2. Or any other suggestions.
#include <iostream>
#include <cmath>
#include <time.h>
using namespace std;
int playRockPaperScissors();
double calculateWinRatio(int,int);
int didUserWin(int,int);
int main()
{
int roundScore,
totalGames,
wins;
double winRatio;
totalGames=0,
wins=0,
roundScore=0,
winRatio=0;
cout << "Welcome to Rock, Paper, Scissors.\n"<< endl;
for (;;)
{
roundScore = playRockPaperScissors();
if ( roundScore == -2 ) break; // break out of loop if user wants to
}
winRatio = calculateWinRatio(wins, totalGames);
cout << "The Ratio of Wins to Losses is: " << winRatio << endl;
return 0;
}
int playRockPaperScissors()
{
int userChoice,
computerChoice,
did;
userChoice=0,
computerChoice=0;
cout << "\nRock = 1"<< endl;
cout << "Paper = 2" << endl;
cout << "Scissors = 3" << endl;
cout << "Enter your choice (0 to quit). \n \n" << endl;
cin >> userChoice; // get user's choice here
srand(time(NULL)); // seed a random number based on time
computerChoice=(rand()%3+1);// gets the number to guess 1 to 3
if ( computerChoice <= 1 && computerChoice >=3) // this if statement
checks the input
{ cout << "ERROR\n";
return -2;
}
if ( cin.bad() || cin.fail() ) // this if statement checks the input
{ cout << "Invalid Input. \n";
return -2;
}
if ( userChoice>=4 || userChoice<=-1) // this if statement checks the
input
{ cout << "Invalid Input. \n";
return -2;
}
if ( userChoice == 0) // this if statement checks the input
{ cout << "Quit already." << endl;
return -2;
}
did=didUserWin(userChoice, computerChoice);
return did;
}
|
|
|
|
|
First off....
if ( computerChoice <= 1 && computerChoice >=3 )
{
cout << "ERROR\n";
return -2;
}
Can never succeed. computerChoice can never satisfy both conditions of the && . Try an OR instead:
if( (computerChoice <= 1) || (computerChoice >=3) )
But here's your real problem:
if ( userChoice>=4 || userChoice<=-1 )
{
cout << "Invalid Input. \n";
return -2;
}
if ( userChoice == 0 )
{
cout << "Quit already." << endl;
return -2;
}
You need to be checking for characters, not integers. Change it to this, and it should work fine (note the comparison changes):
if ( userChoice > '3' || userChoice < '0' )
{
cout << "Invalid Input. \n";
return -2;
}
if ( userChoice == '0' )
{
cout << "Quit already." << endl;
return -2;
}
Hope it helps!
Bob Ciora
|
|
|
|