M8RDP源代码

/************************************************************************/
/*
 * Copyright (C) Meizu Technology Corporation Zhuhai China
 * All rights reserved.
 * 中国珠海, 魅族科技有限公司, 版权所有.
 *
 * This file is a part of the Meizu Foundation Classes library.
 * Author:    Michael
 * Create on: 2008-12-1
 
*/
/************************************************************************/
#include 
"stdafx.h"
// The steps for running this sample code:
// Use Visual Studio 2005/2008 to create a smart device project,
// Choose M8SDK,
// Choose empty project,
// Add a sample.cpp file to the project,
// Copy this peace of code into the sample.cpp,
// Now, you can build the project and try to run it in M8 emulator or device.

// include the MZFC library header file
#include <mzfc_inc.h>

// This sample shows in a MZFC application:
// application's creation & initialization,
// window's creation & initialization,
// using button control, and process its command.

// ID of the button in the window
#define MZ_IDC_EXITBTN        101
#define MZ_IDC_RUNRDPBTN    102
#define MZ_IDC_SHOWIMBTN    103
#define MZ_IDC_HIDEIMBTN    104

HWND g_hTaskBar;

CLSID g_curCLSID;

static int iLargeIndex;
static int iSmallIndex;
static int iCount = 0;

IMENUMINFO g_IMInfo[
5];

int SipEnumIMProc(IMENUMINFO *pIMInfo)
{
    memcpy((
char*)(&g_IMInfo[iCount].clsid),(char*)(&pIMInfo->clsid),sizeof(CLSID));
    wcscpy(g_IMInfo[iCount].szName,pIMInfo
->szName);
    
if (!wcscmp(pIMInfo->szName,_T("LargeKB")))
    {
        iLargeIndex 
= iCount;
    }

    
if (!wcscmp(pIMInfo->szName,_T("键盘")))
    {
        iSmallIndex 
= iCount;
    }
    iCount
++;
    
return 1;
}


// Main window derived from CMzWndEx
class CSample1MainWnd: public CMzWndEx
{
  MZ_DECLARE_DYNAMIC(CSample1MainWnd);
public:
  
// A button control in the window
  UiButton m_btnExit;
  UiButton m_btnRun;
  UiButton m_btnShowIM;
  UiButton m_btnHideIM;
  TCHAR m_szPath[MAX_PATH];

  
// Initialization of the window (dialog)
  virtual BOOL OnInitDialog()
  {
    
// Must all the Init of parent class first!
    if (!CMzWndEx::OnInitDialog())
    {
      
return FALSE;
    }

    m_btnShowIM.SetButtonType(MZC_BUTTON_GREEN);
    m_btnShowIM.SetPos(
10,10,220,100);
    m_btnShowIM.SetID(MZ_IDC_SHOWIMBTN);
    m_btnShowIM.SetText(L
"显示软键盘");
    m_btnShowIM.SetTextColor(RGB(
255,255,255));
    
    m_btnHideIM.SetButtonType(MZC_BUTTON_GREEN);
    m_btnHideIM.SetPos(
240,10,220,100);
    m_btnHideIM.SetID(MZ_IDC_HIDEIMBTN);
    m_btnHideIM.SetText(L
"隐藏软键盘");
    m_btnHideIM.SetTextColor(RGB(
255,255,255));

    m_btnRun.SetButtonType(MZC_BUTTON_GREEN);
    m_btnRun.SetPos(
100,130,280,100);
    m_btnRun.SetID(MZ_IDC_RUNRDPBTN);
    m_btnRun.SetText(L
"启用远程桌面连接");
    m_btnRun.SetTextColor(RGB(
255,255,255));

    
// Then init the controls & other things in the window
    m_btnExit.SetButtonType(MZC_BUTTON_GREEN);
    m_btnExit.SetPos(
100,230,280,100);
    m_btnExit.SetID(MZ_IDC_EXITBTN);
    m_btnExit.SetText(L
"退出程序");
    m_btnExit.SetTextColor(RGB(
255,255,255));

    
// Add the control into the window.
    AddUiWin(&m_btnShowIM);
    AddUiWin(
&m_btnHideIM);
    AddUiWin(
&m_btnExit);
    AddUiWin(
&m_btnRun);

    
//获取当前程序所在的路径
    GetModuleFileName(NULL,m_szPath,MAX_PATH);
    DWORD dwLen 
= wcslen(m_szPath);
    
while(--dwLen)
    {
        
if(m_szPath[dwLen] == _T('\\'))
        {
            m_szPath[dwLen] 
= 0;
            
break;
        }
    }    
    wcscat(m_szPath,_T(
"\\cetsc.exe"));
    
    
return TRUE;
  }

  
// override the MZFC command handler
  virtual void OnMzCommand(WPARAM wParam, LPARAM lParam)
  {
    UINT_PTR id 
= LOWORD(wParam);
    TCHAR szBuf[MAX_PATH];
    
switch(id)
    {
    
case MZ_IDC_SHOWIMBTN:
        SipShowIM(SIPF_ON);
        
break;
    
case MZ_IDC_HIDEIMBTN:
        SipShowIM(SIPF_OFF);
        
break;
    
case MZ_IDC_EXITBTN:
      {
          ::ShowWindow(g_hTaskBar,SW_SHOWNORMAL);
          SipSetCurrentIM(
&g_curCLSID);
          SipShowIM(SIPF_OFF);
          PostQuitMessage(
0);
      }
      
break;
    
case MZ_IDC_RUNRDPBTN:
      {
            
//查找当前窗口,如果找到,则置前
            HWND hWnd = FindWindow(_T("TSSHELLWND"),NULL);
            
if(hWnd)
            {
                ::GetWindowText(hWnd,szBuf,MAX_PATH);                
                
if(wcscmp(szBuf,_T("Remote Desktop Connection")))
                {
                    ::ShowWindow(hWnd,SW_SHOWNORMAL);
                    SetForegroundWindow(hWnd);
                    
return;    
                }
            }

            hWnd 
= FindWindow(NULL,_T("Remote Desktop Connection"));
            
if(hWnd)
            {
                ::ShowWindow(hWnd,SW_SHOWNORMAL);
                SetForegroundWindow(hWnd);
                
return;
            }
            
else
            {
                
//启动CETSC程序
                PROCESS_INFORMATION proinfo;
                
if(CreateProcess(m_szPath,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,&proinfo))
                {
                    CloseHandle(proinfo.hProcess);
                    SipShowIM(SIPF_ON);
                }
                
else
                {
                    MzMessageBoxEx(m_hWnd, L
"没有找到cetsc.exe", L"提示", MB_OK, false);
                }    
            }
      }
      
break;
    }
  }
};

MZ_IMPLEMENT_DYNAMIC(CSample1MainWnd)

// Application class derived from CMzApp
class CSample1App: public CMzApp
{
public:
  
// The main window of the app.
  CSample1MainWnd m_MainWnd;

  
// Initialization of the application
  virtual BOOL Init()
  {
    
// Init the COM relative library.
    CoInitializeEx(0, COINIT_MULTITHREADED);

    
//获取系统当前的输入法
    SipGetCurrentIM(&g_curCLSID);
    
    
//枚举系统所有输入法
    SipEnumIM(SipEnumIMProc);
    
    
//设置系统的输入法为大键盘的方式
    
//SipSetCurrentIM(&g_IMInfo[iSmallIndex].clsid);
    SipSetCurrentIM(&g_IMInfo[iLargeIndex].clsid);

    
//隐藏状态栏,全屏运行该程序
    g_hTaskBar = FindWindow(_T("CTaskBar"),NULL);
    ::ShowWindow(g_hTaskBar,SW_HIDE);

    
// Create the main window
    HWND hDesktop = GetDesktopWindow();
    RECT rect;
    GetWindowRect(hDesktop,
&rect);

    
//设置软键盘的位置
    SIPINFO    si;
    si.dwImDataSize 
= 0;
    si.cbSize 
= sizeof(si);
    SipGetInfo(
&si);
    
    si.rcSipRect.top 
= RECT_HEIGHT(rect) - RECT_HEIGHT(si.rcSipRect);
    si.rcSipRect.left 
= 0;

    SipSetInfo(
&si);

    m_MainWnd.Create(rect.left,rect.top,RECT_WIDTH(rect),RECT_HEIGHT(rect), 
000);
    m_MainWnd.Show();

    
// return TRUE means init success.
    return TRUE;
  }
};
// The global variable of the application.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值