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

📄 commandapi.cpp

📁 一个WinCE6。0下的IP phone的源代码
💻 CPP
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
#include "CommandApi.hpp"
#include "Common.hpp"


static HWND s_Windows[phaLast] = {0};

struct ApplicationInfo_t
{
    const WCHAR* m_pApplicationName;
    const WCHAR* m_pClassName;
};

static const ApplicationInfo_t sc_MappingApplicationInfo[] =
{
    {L"PhoneApp.exe",       WNDCLASS_PHONEAPP},
    {L"HomeScreen.exe",     WNDCLASS_HOMEAPP},
    {L"PHSettings.exe",     WNDCLASS_SETTINGS},
    {L"PHInfo.exe",         WNDCLASS_INFOAPP},
};

EXTERN_C
HWND
WINAPI
PHGetAppWindow(
    PH_APPLICATION Id,
    BOOL SleepRetry
    )
{    
    if (Id >= phaLast)
    {
        ASSERT(0);
        return NULL;
    }

    HANDLE EventSleep = NULL;
    EventSleep = CreateEvent(NULL, FALSE, FALSE, NULL);

    if (!s_Windows[Id] || !IsWindow(s_Windows[Id]))
    {
        s_Windows[Id] = FindWindow(sc_MappingApplicationInfo[Id].m_pClassName, NULL);

        int RetryAttempts = 10;
        while(
            SleepRetry &&
            (RetryAttempts-- > 0) &&
            !s_Windows[Id]
            )
        {
            DEBUGMSG(1, (L"PHGetAppWindow: Had to SLEEP\r\n"));
            if (EventSleep)
            {
                //wait for 200ms
                WaitForSingleObject(EventSleep, 200);
            }
            else
            {
                //event creation failed
                Sleep(200);

            }
            s_Windows[Id] = FindWindow(sc_MappingApplicationInfo[Id].m_pClassName, NULL);
        }
        RETAILMSG(
            1,
                (
                L"PHGetAppWindow: new %s = 0x%08x\r\n",
                sc_MappingApplicationInfo[Id].m_pClassName,
                s_Windows[Id]
                )
            );
    }

    ASSERT(!SleepRetry || s_Windows[Id]);

    if (EventSleep)
    {
        CloseHandle(EventSleep);
    }

    return s_Windows[Id];
}


EXTERN_C
HRESULT
WINAPI
PHLaunchProcess(
    __in const WCHAR* pApplicationName,
    __in const WCHAR* pArguments,
    __out_opt HPROCESS* pHandle
    )
{
    if (!pApplicationName || !pArguments)
    {
        return E_INVALIDARG;
    }

    PROCESS_INFORMATION Info;
    if (
        !CreateProcessW(
            pApplicationName,
            pArguments,
            NULL,
            NULL,
            FALSE,
            0,
            NULL,
            NULL,
            NULL,
            &Info
            )
        )
    {
        ASSERT(0);
        return CommonUtilities_t::GetErrorFromWin32();
    }

    CloseHandle(Info.hThread);
    if (pHandle)
    {
        *pHandle = Info.hProcess;
    }
    else
    {
        CloseHandle(Info.hProcess);
    }

    return S_OK;
}


EXTERN_C
HRESULT
WINAPI
PHSendCommandLine(
    PH_APPLICATION Id,
    __in const WCHAR* pArguments
    )
{
    if (Id >= phaLast)
    {
        ASSERT(0);
        return E_INVALIDARG;
    }

    HRESULT hr;

    HWND Application = PHGetAppWindow(Id, FALSE);
    if (Application)
    {
        hr = SendMessage(
            Application,
            WM_NEW_COMMAND_LINE,
            0,
            reinterpret_cast<LPARAM>(pArguments)
            ) ? S_OK : CommonUtilities_t::GetErrorFromWin32();
        return hr;
    }

    hr = PHLaunchProcess(
        sc_MappingApplicationInfo[Id].m_pApplicationName,
        pArguments,
        NULL
        );

    return hr;
}

⌨️ 快捷键说明

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