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),?0,?0,?0);
????m_MainWnd.Show();
????//?return?TRUE?means?init?success.
????return?TRUE;
??}
};
//?The?global?variable?of?the?application.
/*
?*?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),?0,?0,?0);
????m_MainWnd.Show();
????//?return?TRUE?means?init?success.
????return?TRUE;
??}
};
//?The?global?variable?of?the?application.
轉載于:https://www.cnblogs.com/we-hjb/archive/2009/09/18/1569731.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
- 上一篇: javascript”面向对象编程”-
- 下一篇: ISS配置