⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 set.c

📁 此代码为WCE5.0下电源管理的源代码
💻 C
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++


Module Name:

    set.c

Abstract:

    Power Manager util to query/set the system power state.

Notes:

Revision History:

--*/

#include <windows.h>
#include <msgqueue.h>
#include <pm.h>

extern int	CreateArgvArgc(TCHAR *pProgName, TCHAR *argv[20], TCHAR *pCmdLine);

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR lpCmdLine, int nCmShow)
{
    WCHAR  state[1024] = {0};
    LPWSTR pState = &state[0];
    TCHAR  *argv[20];
    int     argc;
    DWORD  dwErr=0, dwState=0;
    DWORD  dwStateFlags = 0;    
    DWORD  dwOptions = 0;

    UNREFERENCED_PARAMETER(hInst);
    UNREFERENCED_PARAMETER(hPrevInst);
    UNREFERENCED_PARAMETER(nCmShow);
    
    //
    // parse command line
    //
    argc = CreateArgvArgc(TEXT( "PMSET" ), argv, lpCmdLine);
    if (argc > 1) {
        if (!swscanf(argv[1], TEXT("%d"), &dwState))
            dwState = 1;
        if (dwState == 0)
            pState = NULL;
        else if (!swscanf(argv[1], TEXT("%s"), &state))
            goto _error;
            
        if (argc > 2) {
            if (!swscanf(argv[2], TEXT("%x"), &dwStateFlags))
                goto _error;
        }
        
        if (argc > 3) {        
            if (!swscanf(argv[3], TEXT("%x"), &dwOptions))
                goto _error;
        }
    } else {
_error:    
        RETAILMSG(1, (TEXT("PMSET <State> <HexStateFlags> <HexOptions>\n")));
        RETAILMSG(1, (TEXT("  where <State> is system power state defined in the registry, e.g. RunAC\n")));
        RETAILMSG(1, (TEXT("    optional <StateFlags> specify state flags, in hex, e.g. 200000 (POWER_STATE_SUSPEND)\n")));
        RETAILMSG(1, (TEXT("    optional <Options> specify options, in hex, e.g. 1000 (POWER_FORCE)\n")));
        RETAILMSG(1, (TEXT("  Example: PMSET RunAC 1, sets the system state by name by name\n")));        
        RETAILMSG(1, (TEXT("  Example: PMSET 0 200000 1000, will force a suspend without knowing the state name\n")));
        exit(1);
    }

    dwErr = SetSystemPowerState(pState, dwStateFlags, dwOptions);
    if (ERROR_SUCCESS != dwErr) {
        RETAILMSG(1, (TEXT("PMSET!SetSystemPowerState:'%s' ERROR:%d\n"), state, dwErr));
    }

    return 0;
}

// EOF

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -