1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402 |
- // 这段 MFC 示例源代码演示如何使用 MFC Microsoft Office Fluent 用户界面
- // (“Fluent UI”)。该示例仅供参考,
- // 用以补充《Microsoft 基础类参考》和
- // MFC C++ 库软件随附的相关电子文档。
- // 复制、使用或分发 Fluent UI 的许可条款是单独提供的。
- // 若要了解有关 Fluent UI 许可计划的详细信息,请访问
- // https://go.microsoft.com/fwlink/?LinkId=238214.
- //
- // 版权所有(C) Microsoft Corporation
- // 保留所有权利。
- #include "stdafx.h"
- #include "framework.h"
- #include "IRControlWnd.h"
- #include "Resource.h"
- #include "MainFrm.h"
- #include "SATHelper.h"
- #include <filehelper.h>
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #define new DEBUG_NEW
- #endif
- // 重启进程按钮id;
- #define ID_BUTTON_RESTART_PROC 1
- // 复制框控件id;
- #define ID_CHECKBOX_SIGNAL_TYPE 2
- // 切换遥控器;
- #define ID_BUTTON_SWITCH_REMOTE 3
- // 查找红外;
- #define ID_BUTTON_FIND_INFRARED 4
- // 查找蓝牙;
- #define ID_BUTTON_FIND_BLUETOOTH 5
- // 下拉框控件id;
- #define ID_COMBOBOX_SIGNAL_FILE 6
- extern CMainFrame* g_pMainFrame;
- #define RGB_TW RGB(0,162,232)
- #define RGB_RR RGB(255,255,128)
- /////////////////////////////////////////////////////////////////////////////
- // CResourceViewBar
- unsigned char TwoHexChar2Char(char ch1, char ch2)
- {
- char Numb1;
- char Numb2;
- if (ch1 >= 'A')
- Numb1 = (toupper(ch1) - '0' - 7) * 16;
- else
- Numb1 = (ch1 - '0') * 16;
- if (ch2 >= 'A')
- Numb2 = (toupper(ch2) - '0' - 7);
- else
- Numb2 = (ch2 - '0');
- return (Numb1 + Numb2);
- }
- COLORREF HexColor2RGB(std::string strHexColor)
- {
- DWORD r = TwoHexChar2Char(strHexColor[0], strHexColor[1]);
- DWORD g = TwoHexChar2Char(strHexColor[2], strHexColor[3]);
- DWORD b = TwoHexChar2Char(strHexColor[4], strHexColor[5]);
- return RGB(r, g, b);
- }
- CIRControlWnd::CIRControlWnd() noexcept
- {
- m_nComboHeight = 0;
- m_bSendKey = FALSE;
- }
- int CIRControlWnd::CreateCtrl()
- {
- CRect rectDummy;
- rectDummy.SetRectEmpty();
- // 创建组合:
- const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | WS_BORDER | CBS_SORT | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
- #if 0
- if (!m_btnRestart.Create(GlobalString::g_strRestartRemoteDevice, WS_CHILD | WS_VISIBLE, rectDummy, this, ID_BUTTON_RESTART_PROC))
- {
- TRACE0("未能创建遥控器组合 \n");
- return -1; // 未能创建
- }
- if (!m_wndSignalCheck.Create(GlobalString::g_strRemoteSelect, WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX, rectDummy, this, ID_CHECKBOX_SIGNAL_TYPE))
- {
- TRACE0("未能创建信号集下拉框 \n");
- return -1; // 未能创建
- }
- m_wndSignalCheck.SetCheck(Global::g_Config.bGenerics ? BST_CHECKED : BST_UNCHECKED);
- m_wndSignalCheck.m_bHighlightChecked = TRUE;
- // CMFCButton只能用图标来显示check;
- m_wndSignalCheck.SetImage(IDB_UNCHECKED);
- m_wndSignalCheck.SetCheckedImage(IDB_CHECKED);
- m_wndSignalCheck.m_bTransparent = FALSE;
- m_wndSignalCheck.m_bDrawFocus = FALSE;
- m_wndSignalCheck.m_nFlatStyle = CMFCButton::BUTTONSTYLE_FLAT;
- m_wndSignalCheck.SizeToContent();
- #endif
- if (!m_btnSwitchRemote.Create(GlobalString::g_strSwitchRemote, WS_CHILD | WS_VISIBLE, rectDummy, this, ID_BUTTON_SWITCH_REMOTE))
- {
- TRACE0("未能创建遥控器组合 \n");
- return -1; // 未能创建
- }
- if (Global::g_Config.useTW)
- {
- m_btnSwitchRemote.SetWindowText(Global::g_Config.nLanguage ? _T("SwitchToRedRat") : _T("切换到红老鼠"));
- }
- else
- {
- m_btnSwitchRemote.SetWindowText(GlobalString::g_strSwitchRemote);
- }
- m_btnSwitchRemote.SetFaceColor(Global::g_Config.useTW ? RGB_TW : RGB_RR, TRUE);
- if (!m_btnFindinfraRed.Create(GlobalString::g_strFindIR, WS_CHILD | WS_VISIBLE, rectDummy, this, ID_BUTTON_FIND_INFRARED))
- {
- TRACE0("未能创建遥控器组合 \n");
- return -1; // 未能创建
- }
- if (!m_btnFindBluetooth.Create(GlobalString::g_strFindBL, WS_CHILD | WS_VISIBLE, rectDummy, this, ID_BUTTON_FIND_BLUETOOTH))
- {
- TRACE0("未能创建遥控器组合 \n");
- return -1; // 未能创建
- }
- if (!m_wndSignalCombo.Create(dwViewStyle | WS_VSCROLL | WS_HSCROLL, CRect(0, 0, 100, 20), this, ID_COMBOBOX_SIGNAL_FILE))
- {
- TRACE0("未能创建信号集下拉框 \n");
- return -1; // 未能创建
- }
- if (!m_cbTree1.Create(dwViewStyle | WS_VSCROLL | WS_HSCROLL, rectDummy, this, ID_COMBOBOX_SIGNAL_FILE + 1))
- {
- TRACE0("未能创建信号集下拉框 \n");
- return -1; // 未能创建
- }
- if (!m_cbTree2.Create(dwViewStyle | WS_VSCROLL | WS_HSCROLL, rectDummy, this, ID_COMBOBOX_SIGNAL_FILE + 2))
- {
- TRACE0("未能创建信号集下拉框 \n");
- return -1; // 未能创建
- }
- if (!m_cbTree3.Create(dwViewStyle | WS_VSCROLL | WS_HSCROLL, rectDummy, this, ID_COMBOBOX_SIGNAL_FILE + 3))
- {
- TRACE0("未能创建信号集下拉框 \n");
- return -1; // 未能创建
- }
- // 设置透明false以显示背景色
- m_btnSwitchRemote.m_bTransparent = FALSE;
- m_btnSwitchRemote.m_bDontUseWinXPTheme = TRUE;
- // 设置背景色;
- m_btnSwitchRemote.SetFaceColor(Global::g_Config.useTW ? RGB_TW :RGB_RR , TRUE);
- // 消除单击时黑色内圈;
- m_btnSwitchRemote.m_bDrawFocus = FALSE;
- // 设置按钮扁平样式;
- m_btnSwitchRemote.m_nFlatStyle = CMFCButton::FlatStyle::BUTTONSTYLE_FLAT;
- // 设置鼠标形状;
- m_btnSwitchRemote.SetMouseCursorHand();
- return 0;
- }
- CIRControlWnd::~CIRControlWnd()
- {
- RedRat::UnloadLibrary();
- for (std::vector<BtnInfo>::iterator it = m_vtBtnInfo.begin(); it != m_vtBtnInfo.end(); it++)
- {
- if (it->pBTN)
- //it->pBTN->DestroyWindow();
- delete it->pBTN;
- it->pBTN = NULL;
- }
- m_vtBtnInfo.clear();
- }
- BEGIN_MESSAGE_MAP(CIRControlWnd, CDockablePane)
- ON_WM_CREATE()
- ON_WM_SIZE()
- ON_COMMAND(ID_EXPAND_ALL, OnExpandAllProperties)
- ON_UPDATE_COMMAND_UI(ID_EXPAND_ALL, OnUpdateExpandAllProperties)
- ON_COMMAND(ID_SORTPROPERTIES, OnSortProperties)
- ON_UPDATE_COMMAND_UI(ID_SORTPROPERTIES, OnUpdateSortProperties)
- ON_COMMAND(ID_PROPERTIES1, OnProperties1)
- ON_UPDATE_COMMAND_UI(ID_PROPERTIES1, OnUpdateProperties1)
- ON_COMMAND(ID_PROPERTIES2, OnProperties2)
- ON_UPDATE_COMMAND_UI(ID_PROPERTIES2, OnUpdateProperties2)
- ON_WM_SETFOCUS()
- ON_WM_SETTINGCHANGE()
- ON_WM_PAINT()
- ON_MESSAGE(WM_IR_SHOT_IMG, OnIRShotImg)
- ON_CBN_SELCHANGE(ID_COMBOBOX_SIGNAL_FILE, &CIRControlWnd::OnCbnSelchangeSignal)
- ON_CBN_SELCHANGE(ID_COMBOBOX_SIGNAL_FILE + 1, &CIRControlWnd::OnCbnSelchangeTree1)
- ON_CBN_SELCHANGE(ID_COMBOBOX_SIGNAL_FILE + 2, &CIRControlWnd::OnCbnSelchangeTree2)
- ON_CBN_SELCHANGE(ID_COMBOBOX_SIGNAL_FILE + 3, &CIRControlWnd::OnCbnSelchangeTree3)
- // 信号按钮;
- ON_COMMAND_RANGE(BTNID, BTNID + 100, OnSignalBtnClick)
- ON_UPDATE_COMMAND_UI_RANGE(BTNID, BTNID + 100, OnUpdateSignalBtn)
- // checkbox
- ON_UPDATE_COMMAND_UI(ID_CHECKBOX_SIGNAL_TYPE, OnUpdateCheckBox)
- ON_COMMAND(ID_CHECKBOX_SIGNAL_TYPE, OnCheckBoxClicked)
- // 重启按钮;
- ON_UPDATE_COMMAND_UI(ID_BUTTON_RESTART_PROC, OnUpdateBtnRestartProc)
- ON_COMMAND(ID_BUTTON_RESTART_PROC, OnBtnRestartProcClicked)
- // 切换遥控器;
- ON_UPDATE_COMMAND_UI(ID_BUTTON_SWITCH_REMOTE, OnUpdateSwitchRemote)
- ON_COMMAND(ID_BUTTON_SWITCH_REMOTE, OnSwitchRemoteClicked)
- // 查找红外;
- ON_UPDATE_COMMAND_UI(ID_BUTTON_FIND_INFRARED, OnUpdateFindFindinfraRed)
- ON_COMMAND(ID_BUTTON_FIND_INFRARED, OnFindFindinfraRedClicked)
- // 查找蓝牙;
- ON_UPDATE_COMMAND_UI(ID_BUTTON_FIND_BLUETOOTH, OnUpdateFindBluetooth)
- ON_COMMAND(ID_BUTTON_FIND_BLUETOOTH, OnFindBluetoothClicked)
- //ON_UPDATE_COMMAND_UI(ID_BUTTON_RESTART_PROC, OnUpdateReStartBtn)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CResourceViewBar 消息处理程序
- void CIRControlWnd::AdjustLayout()
- {
- if (GetSafeHwnd() == nullptr ||
- (AfxGetMainWnd() != nullptr && AfxGetMainWnd()->IsIconic()))
- {
- return;
- }
- const int dr = 3; // 行间距
- const int dc = 5; // 列间距;
- CRect rcCtrl;
- CRect rectClient;
- GetClientRect(rectClient);
- TRACE2(_T("更新后的大小:%d,%d"), rectClient.Width(), rectClient.Height());
- #if 0
- m_btnRestart.SetWindowPos(nullptr, rectClient.left + dr, rectClient.top + dr, (rectClient.Width() - dr * 3) / 2, m_nComboHeight, SWP_NOACTIVATE | SWP_NOZORDER);
- m_btnRestart.GetWindowRect(rcCtrl);
- ScreenToClient(rcCtrl);
- m_wndSignalCheck.SetWindowPos(nullptr, rcCtrl.right + dr, rectClient.top + dr, rcCtrl.Width(), m_nComboHeight, SWP_NOACTIVATE | SWP_NOZORDER);
- m_wndSignalCheck.GetWindowRect(rcCtrl);
- ScreenToClient(rcCtrl);
- #else
- int nBtnWidth = (rectClient.Width() - dr * 4) / 3;
- m_btnSwitchRemote.SetWindowPos(nullptr, rectClient.left + dr, rectClient.top + dr, nBtnWidth, m_nComboHeight, SWP_NOACTIVATE | SWP_NOZORDER);
- m_btnFindinfraRed.SetWindowPos(nullptr, rectClient.left + dr*2 + nBtnWidth, rectClient.top + dr, nBtnWidth, m_nComboHeight, SWP_NOACTIVATE | SWP_NOZORDER);
- m_btnFindBluetooth.SetWindowPos(nullptr, rectClient.left + dr*3 + nBtnWidth *2, rectClient.top + dr, nBtnWidth, m_nComboHeight, SWP_NOACTIVATE | SWP_NOZORDER);
- m_btnFindBluetooth.GetWindowRect(rcCtrl);
- ScreenToClient(rcCtrl);
- #endif
- // 注意:此combobox高度并是包含了下拉项的高度;
- m_wndSignalCombo.SetWindowPos(nullptr, rectClient.left + dr, rcCtrl.bottom + dr, rectClient.Width() - dc * 2, m_nComboHeight + 233, SWP_NOACTIVATE | SWP_NOZORDER);
- //::MoveWindow(m_wndSignalCombo.m_hWnd, rectClient.left + 5, rcCtrl.bottom + 5, rectClient.Width() - 10, m_nComboHeight + 233, TRUE);
- //m_wndSignalCombo.SendMessage(CB_SETITEMHEIGHT, (WPARAM)-1, (LPARAM)19); //改变控件本身的高度
- m_wndSignalCombo.GetWindowRect(rcCtrl);
- ScreenToClient(rcCtrl);
- // 注意:此combobox高度并是包含了下拉项的高度;
- m_cbTree1.SetWindowPos(nullptr, rectClient.left + dr, rcCtrl.bottom + dr, (rectClient.Width() - dr*4) / 3, m_nComboHeight + 233, SWP_NOACTIVATE | SWP_NOZORDER);
- m_cbTree1.GetWindowRect(rcCtrl);
- ScreenToClient(rcCtrl);
- // 注意:此combobox高度并是包含了下拉项的高度;
- m_cbTree2.SetWindowPos(nullptr, rcCtrl.right + 2, rcCtrl.top, rcCtrl.Width(), m_nComboHeight + 233, SWP_NOACTIVATE | SWP_NOZORDER);
- m_cbTree2.GetWindowRect(rcCtrl);
- ScreenToClient(rcCtrl);
- // 注意:此combobox高度并是包含了下拉项的高度;
- m_cbTree3.SetWindowPos(nullptr, rcCtrl.right + 2, rcCtrl.top, rcCtrl.Width(), m_nComboHeight + 233, SWP_NOACTIVATE | SWP_NOZORDER);
- #if __PANE_DLG__
- m_dlgIRControl.SetWindowPos(nullptr, rectClient.left, rectClient.top + m_nComboHeight + 50, rectClient.Width(), rectClient.Height(), SWP_NOACTIVATE);
- #endif
- m_cbTree3.GetWindowRect(rcCtrl);
- ScreenToClient(rcCtrl);
- int sx = 0, sy = rcCtrl.bottom + dr;
- int i = 0, id = 10000;
- int nWidth = (rectClient.Width() - 25) / 4;
- DWORD dwStyle = WS_CHILD | WS_VISIBLE;
- for (std::vector<BtnInfo>::iterator it = m_vtBtnInfo.begin(); it != m_vtBtnInfo.end(); it++)
- {
- if (it->pBTN == nullptr)
- continue;
- if (i != 0 && i % 4 == 0)
- {//换行;
- sy += it->height + 5;
- }
- sx = (i % 4) * nWidth + (i % 4 + 1) * 5;
- it->pBTN->SetWindowPos(nullptr, sx, sy, nWidth, it->height, SWP_NOACTIVATE | SWP_NOZORDER);
- i++;
- }
- }
- int CIRControlWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CDockablePane::OnCreate(lpCreateStruct) == -1)
- return -1;
- if (CreateCtrl() != 0)
- return -1;
- LoadSignals();
- SetPropListFont();
- LoadMenuTreePath();
- ReadResourceRunCfg();
- InitMenuTreeCombobox();
- CRect rectCombo;
- m_wndSignalCombo.GetClientRect(&rectCombo);
- m_nComboHeight = rectCombo.Height();
- #if __PANE_DLG__
- if (!m_dlgIRControl.Create(IDD_DLG_IRCONTROL, this))
- {
- TRACE0("未能创建遥控器主窗口 \n");
- return -1; // 未能创建
- }
- m_dlgIRControl.ShowWindow(SW_SHOW);
- #else
- Loadlayout(m_vtBtnInfo);
- #endif
- // 设置最小窗体;
- SetMinSize((530, 260));
- // 校正布局;
- AdjustLayout();
- //////////////////////////////////////////////////////////////////////////
- // 启动红老鼠;
- if (!RedRat::LoadLibrary())
- {
- AfxMessageBox(Global::g_Config.nLanguage ? "Load dll Fail, pelease check dll is ok!" : "加载遥控dll失败,请检测dll是否正常!");
- }
- StartIRDevice(FALSE);
- if (Global::g_Config.useTW) {
- std::string signaldir = Global::g_Config.twSignaldir;
- std::string signalpath = signaldir + "\\";
- signalpath.append(Global::g_Config.twUseSignal + ".xml");
- TW::LoadXml(signalpath.c_str());
- }
- std::thread t([](CIRControlWnd* pWnd) {
- //while (true)
- while (IsWindow(pWnd->m_hWnd))
- {
- if (g_pMainFrame->m_bShotIR && pWnd->m_bSendKey)
- {
- pWnd->m_bSendKey = FALSE;
- Sleep(200);
- CUB530View* pView = (CUB530View*)g_pMainFrame->m_pUB530View->GetActiveView();
- if (pView)
- {
- pView->OnCutJpg();
- }
- }
- Sleep(20);
- }
- }, this);
- t.detach();
- return 0;
- }
- void CIRControlWnd::OnSize(UINT nType, int cx, int cy)
- {
- CDockablePane::OnSize(nType, cx, cy);
- TRACE2("坐标:%d,%d\n", cx, cy);
- AdjustLayout();
- }
- void CIRControlWnd::OnExpandAllProperties()
- {
- //m_wndPropList.ExpandAll();
- }
- void CIRControlWnd::OnUpdateExpandAllProperties(CCmdUI* /* pCmdUI */)
- {
- }
- void CIRControlWnd::OnSortProperties()
- {
- //m_wndPropList.SetAlphabeticMode(!m_wndPropList.IsAlphabeticMode());
- }
- void CIRControlWnd::OnUpdateSortProperties(CCmdUI* pCmdUI)
- {
- //pCmdUI->SetCheck(m_wndPropList.IsAlphabeticMode());
- }
- void CIRControlWnd::OnProperties1()
- {
- // TODO: 在此处添加命令处理程序代码
- }
- void CIRControlWnd::OnUpdateProperties1(CCmdUI* /*pCmdUI*/)
- {
- // TODO: 在此处添加命令更新 UI 处理程序代码
- }
- void CIRControlWnd::OnProperties2()
- {
- // TODO: 在此处添加命令处理程序代码
- }
- void CIRControlWnd::OnUpdateProperties2(CCmdUI* /*pCmdUI*/)
- {
- // TODO: 在此处添加命令更新 UI 处理程序代码
- }
- void CIRControlWnd::OnSetFocus(CWnd* pOldWnd)
- {
- CDockablePane::OnSetFocus(pOldWnd);
- }
- void CIRControlWnd::OnSettingChange(UINT uFlags, LPCTSTR lpszSection)
- {
- CDockablePane::OnSettingChange(uFlags, lpszSection);
- SetPropListFont();
- }
- void CIRControlWnd::OnCbnSelchangeSignal()
- {
- CString strSignal;
- int nCurSel = m_wndSignalCombo.GetCurSel();
- if (nCurSel != CB_ERR)
- {
- std::string signalpath;
- m_wndSignalCombo.GetLBText(nCurSel, strSignal);
- // 保存到配置文件中;
- if (Global::g_Config.useTW)
- {
- Global::g_Config.twUseSignal = strSignal.GetString();
- WritePrivateProfileString("TestWizard", "useSignal", strSignal.GetString(), Global::g_szConfig);
- }
- else {
- Global::g_Config.use_signal = strSignal.GetString();
- WritePrivateProfileString("ir-device", "use-signal", strSignal.GetString(), Global::g_szConfig);
- }
- }
- DisableSignalBtn();
- ReLoadSignalXml();
- }
- void CIRControlWnd::OnCbnSelchangeTree1()
- {
- // UI下拉框;
- CString strTree1;
- int nCurSel = m_cbTree1.GetCurSel();
- if (nCurSel != CB_ERR)
- {
- m_cbTree1.GetLBText(nCurSel, strTree1);
- }
- m_cbTree2.ResetContent();
- for (auto it : m_map_tree.find(strTree1.GetString())->second)
- {
- m_cbTree2.AddString(it.ui.c_str());
- }
- m_cbTree2.SetCurSel(0);
- // SUBUI下拉框;
- CString strTree2 = _T("");
- nCurSel = m_cbTree2.GetCurSel();
- if (nCurSel != CB_ERR)
- {
- m_cbTree2.GetLBText(nCurSel, strTree2);
- }
- m_cbTree3.ResetContent();
- std::vector<UITree>& ui = m_map_tree.find(strTree1.GetString())->second;
- for (std::vector<UITree>::iterator it = ui.begin(); it != ui.end(); it++)
- {
- if (_tcsicmp(strTree2.GetString(), it->ui.c_str()) == 0)
- {
- if (it->vtSubUI.size() == 0)
- break;
- for (auto SubUI : it->vtSubUI)
- {
- m_cbTree3.AddString(SubUI.c_str());
- }
- m_cbTree3.SetCurSel(0);
- }
- }
- // 保存结果;
- WritePrivateProfileString(_T("MenuTree"), _T("menutreeselectedchip"), strTree1, Global::g_szResuorceCfg);
- WritePrivateProfileString(_T("MenuTree"), _T("menutreeselectedstyle"), strTree2, Global::g_szResuorceCfg);
- CString strTree3 = _T("");
- nCurSel = m_cbTree3.GetCurSel();
- if (nCurSel != CB_ERR)
- {
- m_cbTree3.GetLBText(nCurSel, strTree3);
- }
- WritePrivateProfileString(_T("MenuTree"), _T("menutreeselectedchannel"), strTree3, Global::g_szResuorceCfg);
- _stprintf_s(g_pMainFrame->m_szCurMenuTreeDir, _T("%s%s%s\\%s\\"), m_rscfg.sat_home.c_str(), _T("resource\\MenuTree\\"), strTree1.GetString(), strTree2.GetString());
- }
- void CIRControlWnd::OnCbnSelchangeTree2()
- {
- CString strTree1;
- int nCurSel = m_cbTree1.GetCurSel();
- if (nCurSel == CB_ERR)
- return;
- m_cbTree1.GetLBText(nCurSel, strTree1);
- // SUBUI下拉框;
- CString strTree2 = _T("");
- nCurSel = m_cbTree2.GetCurSel();
- if (nCurSel == CB_ERR)
- return;
-
- m_cbTree2.GetLBText(nCurSel, strTree2);
- // 清空tree3;
- m_cbTree3.ResetContent();
- std::vector<UITree>& ui = m_map_tree.find(strTree1.GetString())->second;
- for (std::vector<UITree>::iterator it = ui.begin(); it != ui.end(); it++)
- {
- if (_tcsicmp(strTree2.GetString(), it->ui.c_str()) == 0)
- {
- if (it->vtSubUI.size() == 0)
- break;
- for (auto SubUI : it->vtSubUI)
- {
- m_cbTree3.AddString(SubUI.c_str());
- }
- m_cbTree3.SetCurSel(0);
- }
- }
- // 保存结果;
- WritePrivateProfileString(_T("MenuTree"), _T("menutreeselectedstyle"), strTree2, Global::g_szResuorceCfg);
- CString strTree3 = _T("");
- nCurSel = m_cbTree3.GetCurSel();
- if (nCurSel != CB_ERR)
- {
- m_cbTree3.GetLBText(nCurSel, strTree3);
- }
- WritePrivateProfileString(_T("MenuTree"), _T("menutreeselectedchannel"), strTree3, Global::g_szResuorceCfg);
- _stprintf_s(g_pMainFrame->m_szCurMenuTreeDir, _T("%s%s%s\\%s\\"), m_rscfg.sat_home.c_str(), _T("resource\\MenuTree\\"), strTree1.GetString(), strTree2.GetString());
- }
- void CIRControlWnd::OnCbnSelchangeTree3()
- {
- // UI下拉框;
- CString strTree3 = _T("");
- int nCurSel = m_cbTree3.GetCurSel();
- if (nCurSel != CB_ERR)
- {
- m_cbTree3.GetLBText(nCurSel, strTree3);
- WritePrivateProfileString(_T("MenuTree"), _T("menutreeselectedchannel"), strTree3, Global::g_szResuorceCfg);
- }
- }
- void CIRControlWnd::SetPropListFont()
- {
- ::DeleteObject(m_fntPropList.Detach());
- LOGFONT lf;
- afxGlobalData.fontRegular.GetLogFont(&lf);
- NONCLIENTMETRICS info;
- info.cbSize = sizeof(info);
- afxGlobalData.GetNonClientMetrics(info);
- lf.lfHeight = info.lfMenuFont.lfHeight;
- lf.lfWeight = info.lfMenuFont.lfWeight;
- lf.lfItalic = info.lfMenuFont.lfItalic;
- m_fntPropList.CreateFontIndirect(&lf);
- m_wndSignalCombo.SetFont(&m_fntPropList);
- m_cbTree1.SetFont(&m_fntPropList);
- m_cbTree2.SetFont(&m_fntPropList);
- m_cbTree3.SetFont(&m_fntPropList);
- }
- void CIRControlWnd::StartIRDevice(BOOL bReStart)
- {
- std::thread t([&](BOOL _bReStart_) {
- // 结束进程;
- if (_bReStart_ && RedRat::g_CloseApp)
- RedRat::g_CloseApp();
- // 默认加载配置的信号集文件;
- std::string signale = Global::g_Config.bGenerics ? Global::g_Config.signaldir + "\\general\\" : Global::g_Config.signaldir + "\\product\\";
- signale.append(Global::g_Config.use_signal + ".xml");
- if (!PathFileExists(signale.c_str()))
- {
- m_wndSignalCombo.SetCurSel(-1);
- signale = ".\\default.xml";
- }
- else
- {
- m_wndSignalCombo.SelectString(0, Global::g_Config.use_signal.c_str());
- }
- if (!RedRat::g_IsAppRunning(Global::g_Config.redratpath.c_str()))
- {
- if (RedRat::g_StartIRApp(Global::g_Config.redratpath.c_str(), signale.c_str(), 40000))
- {
- TRACE("启动红老鼠进程启动成功\r");
- }
- else
- {
- TRACE("启动红老鼠进程启动失败\r");
- AfxMessageBox(Global::g_Config.nLanguage ? "Failed to start red mouse process" : "启动红老鼠进程失败!");
- return 0;
- }
- }
- BOOL bRet = FALSE;
- // 连接服务器;
- for (int i = 0; i < 5; i++)
- {
- if ((bRet = RedRat::g_Connect(_T("127.0.0.1"), 40000)))
- break;
- Sleep(1000);
- }
- if (!bRet)
- AfxMessageBox(Global::g_Config.nLanguage ? "Failed to connect to red mouse server. Please restart the device!" : "连接红老鼠服务端失败,请重启设备!");
- // 更新按钮状态;
- UpdateSignalBtnStatus();
- // 获取设备列表,以逗号分隔;
- std::string devices = RedRat::g_getDeviceNames();
- if (devices.size() == 0)
- {
- AfxMessageBox(Global::g_Config.nLanguage ? "There is currently no red mouse device connection" :"当前无红老鼠设备连接!");
- }
- return 1;
- }, bReStart);
- t.detach();
- }
- void CIRControlWnd::ReLoadSignalXml()
- {
- if (Global::g_Config.useTW)
- {
- std::string signaldir = Global::g_Config.twSignaldir;
- std::string signalpath = signaldir + "\\";
- signalpath.append(Global::g_Config.twUseSignal + ".xml");
- if (!PathFileExists(signalpath.c_str()))
- {
- AfxMessageBox(Global::g_Config.nLanguage ? "The signal file does not exist" :_T("该信号文件不存在!"));
- // 设置默认的;
- CString strSignal;
- m_wndSignalCombo.SetCurSel(0);
- m_wndSignalCombo.GetLBText(0, strSignal);
- signalpath = signaldir;
- signalpath.append(strSignal.GetString());
- signalpath.append(".xml");
- // 保存到配置文件中;
- Global::g_Config.twUseSignal = strSignal.GetString();
- WritePrivateProfileString("TestWizard", "useSignal", strSignal.GetString(), Global::g_szConfig);
- }
- else // 切换通用类型时用到;
- {
- m_wndSignalCombo.SelectString(0, Global::g_Config.twUseSignal.c_str());
- }
- // 加载指定目录的xml信号集文件;
- if (0 != TW::LoadXml(signalpath.c_str()))
- {
- TRACE("加载信号集文件失败\r");
- }
- else
- {
- TRACE("加载信号集文件成功\r");
- UpdateSignalBtnStatus();
- }
- }
- else {
- std::string signaldir, signalpath;
- if (Global::g_Config.bGenerics)
- {
- signaldir = Global::g_Config.signaldir + "\\general\\";
- }
- else
- {
- signaldir = Global::g_Config.signaldir + "\\product\\";
- }
- signalpath = signaldir;
- signalpath.append(Global::g_Config.use_signal + ".xml");
- if (!PathFileExists(signalpath.c_str()))
- {
- AfxMessageBox(Global::g_Config.nLanguage ? "The signal file does not exist" : _T("该信号文件不存在!"));
- // 设置默认的;
- CString strSignal;
- m_wndSignalCombo.SetCurSel(0);
- m_wndSignalCombo.GetLBText(0, strSignal);
- signalpath = signaldir;
- signalpath.append(strSignal.GetString());
- signalpath.append(".xml");
- // 保存到配置文件中;
- Global::g_Config.use_signal = strSignal.GetString();
- WritePrivateProfileString("ir-device", "use-signal", strSignal.GetString(), Global::g_szConfig);
- }
- else // 切换通用类型时用到;
- {
- m_wndSignalCombo.SelectString(0, Global::g_Config.use_signal.c_str());
- }
- // 加载指定目录的xml信号集文件;
- if (!RedRat::g_loadSignalDataSet(signalpath.c_str()))
- {
- TRACE("加载信号集文件失败\r");
- }
- else
- {
- TRACE("加载信号集文件成功\r");
- UpdateSignalBtnStatus();
- }
- }
- }
- void CIRControlWnd::LoadSignals()
- {
- //AfxMessageBox("LoadSignals\r");
- m_wndSignalCombo.ResetContent();
- if (Global::g_Config.useTW)
- {
- filehelper fh;
- m_vtsignal_tw.clear();
- fh.getfiles_findout_subfolder(Global::g_Config.twSignaldir.c_str(), NULL, &m_vtsignal_tw);
- m_wndSignalCombo.ResetContent();
- for (auto it : m_vtsignal_tw)
- {
- m_wndSignalCombo.AddString(fh.getfilename(it).c_str());
- }
- }
- else
- {
- filehelper fh;
- m_vtsignal_gen.clear();
- m_vtsignal_pro.clear();
- fh.getfiles_findout_subfolder((Global::g_Config.signaldir + "\\general\\").c_str(), NULL, &m_vtsignal_gen);
- fh.getfiles_findout_subfolder((Global::g_Config.signaldir + "\\product\\").c_str(), NULL, &m_vtsignal_pro);
- // 添加到combobox中;
- if (Global::g_Config.bGenerics)
- {
- m_wndSignalCombo.ResetContent();
- for (auto it : m_vtsignal_gen)
- {
- m_wndSignalCombo.AddString(fh.getfilename(it).c_str());
- }
- }
- else
- {
- m_wndSignalCombo.ResetContent();
- for (auto it : m_vtsignal_pro)
- {
- m_wndSignalCombo.AddString(fh.getfilename(it).c_str());
- }
- }
- }
- AutoSetDroppedWidth(&m_wndSignalCombo);
- }
- void CIRControlWnd::Loadlayout(std::vector<BtnInfo>& vt)
- {
- // 解析xml;
- std::string path;
- path.append(Global::g_szCurModuleDir);
- path.append("layout.xml");
- tinyxml2::XMLDocument doc;
- if (tinyxml2::XML_SUCCESS != doc.LoadFile(path.c_str()))
- {
- return;
- }
- vt.clear();
- std::string data;
- tinyxml2::XMLElement* pXmlRoot = NULL;
- if ((pXmlRoot = doc.RootElement()) != NULL)
- {
- if (_tcsicmp(pXmlRoot->Value(), "ButtonList") == 0)
- {
- // 子项;
- tinyxml2::XMLElement* pXmlElent = pXmlRoot->FirstChildElement();
- while (pXmlElent)
- {
- BtnInfo btninfo;
- if (_tcsicmp(pXmlElent->Value(), _T("ITEM")) == 0)
- {
- tinyxml2::XMLElement* pItem = pXmlElent->FirstChildElement();
- while (pItem)
- {
- if (_tcsicmp(pItem->Value(), _T("NAME")) == 0)
- {
- btninfo.name = pItem->GetText();
- }
- else if (_tcsicmp(pItem->Value(), _T("WIDTH")) == 0)
- {
- data = pItem->GetText();
- btninfo.width = _ttol(data.c_str());
- }
- else if (_tcsicmp(pItem->Value(), _T("HEIGHT")) == 0)
- {
- data = pItem->GetText();
- btninfo.height = _ttol(data.c_str());
- }
- else if (_tcsicmp(pItem->Value(), _T("COLOR")) == 0)
- {
- data = pItem->GetText();
- btninfo.color = HexColor2RGB(data);
- }
- btninfo.pBTN = new CMFCButton();
- pItem = pItem->NextSiblingElement();
- }
- }
- vt.push_back(btninfo);
- pXmlElent = pXmlElent->NextSiblingElement();
- }
- }
- }
- int sx = 0, sy = m_nComboHeight * 2 + 15;
- int i = 0, id = 10000;
- DWORD dwStyle = WS_CHILD | WS_VISIBLE;
- for (std::vector<BtnInfo>::iterator it = vt.begin(); it != vt.end(); it++)
- {
- if (i != 0 && i % 4 == 0)
- {//换行;
- sy += it->height + 5;
- }
- sx = (i % 4) * it->width + (i % 4 + 1) * 5;
- it->pBTN->Create(it->name.c_str(), dwStyle, CRect(sx, sy, sx + it->width, sy + it->height), this, BTNID + i);
- // 设置透明false以显示背景色
- it->pBTN->m_bTransparent = FALSE;
- it->pBTN->m_bDontUseWinXPTheme = TRUE;
- // 设置背景色;
- it->pBTN->SetFaceColor(it->color, TRUE);
- // 消除单击时黑色内圈;
- it->pBTN->m_bDrawFocus = FALSE;
- // 设置按钮扁平样式;
- it->pBTN->m_nFlatStyle = CMFCButton::FlatStyle::BUTTONSTYLE_FLAT;
- // 设置鼠标形状;
- it->pBTN->SetMouseCursorHand();
- // 存入map中;
- m_map_btn.insert(std::pair<UINT, BtnInfo&>(BTNID + i, *it));
- i++;
- }
- }
- // 如果CDockablePane无控件,改变大小时背景会刷新失败;
- // 所以要重载onpaint;
- void CIRControlWnd::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- // TODO: 在此处添加消息处理程序代码
- // 不为绘图消息调用 CDockablePane::OnPaint();
- CRect rc;
- GetClientRect(rc);
- CBrush brush;
- brush.CreateSolidBrush(0xFFEFD5);
- dc.FillRect(&rc, &brush);
- }
- void CIRControlWnd::OnSignalBtnClick(UINT uId) // 发送遥控信号;
- {
- CWnd* pWnd = GetFocus();
- int id = pWnd->GetDlgCtrlID();
- if (id >= BTNID && id <= BTNID + 100)
- {
- CString text;
- pWnd->GetWindowText(text);
- if (Global::g_Config.useTW)
- {
- TW::SendKey(text.GetString());
- }
- else {
- // 发送单信号;
- if (RedRat::g_sendSignal(text.GetString(), 1, 20))
- {
- m_bSendKey = TRUE;
- TRACE("发送单信号成功\n");
- }
- else
- {
- TRACE("发送单信号失败\n");
- }
- }
- }
- }
- void CIRControlWnd::OnUpdateSignalBtn(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(m_map_btn.find(pCmdUI->m_nID)->second.bEnable);
- }
- void CIRControlWnd::OnUpdateCheckBox(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(!Global::g_Config.useTW);
- }
- void CIRControlWnd::OnCheckBoxClicked()
- {
- if (Global::g_Config.useTW)
- {
- }
- else {
- Global::g_Config.bGenerics = m_wndSignalCheck.IsChecked();
- // 保存到配置文件中;
- WritePrivateProfileString("ir-device", "generics", Global::g_Config.bGenerics ? "1" : "0", Global::g_szConfig);
- // 添加到combobox中;
- if (Global::g_Config.bGenerics)
- {
- m_wndSignalCombo.ResetContent();
- for (auto it : m_vtsignal_gen)
- {
- m_wndSignalCombo.AddString(filehelper::getfilename(it).c_str());
- }
- }
- else
- {
- m_wndSignalCombo.ResetContent();
- for (auto it : m_vtsignal_pro)
- {
- m_wndSignalCombo.AddString(filehelper::getfilename(it).c_str());
- }
- }
- AutoSetDroppedWidth(&m_wndSignalCombo);
- DisableSignalBtn();
- ReLoadSignalXml();
- }
- }
- void CIRControlWnd::OnUpdateBtnRestartProc(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(!Global::g_Config.useTW);
- }
- void CIRControlWnd::OnBtnRestartProcClicked() // 重启红老鼠;
- {
- DisableSignalBtn();
- StartIRDevice();
- }
- void CIRControlWnd::OnUpdateSwitchRemote(CCmdUI* pCmdUI)
- {
- }
- void CIRControlWnd::OnSwitchRemoteClicked()
- {
- Global::g_Config.useTW = !Global::g_Config.useTW;
- if (Global::g_Config.useTW)
- {
- OutputDebugString(_T("Global::g_Config.useTW=True;\n"));
- m_btnSwitchRemote.SetWindowText(Global::g_Config.nLanguage ? _T("SwitchToRedRat") : _T("切换到红老鼠"));
- }
- else
- {
- OutputDebugString(_T("Global::g_Config.useTW=False;\n"));
- m_btnSwitchRemote.SetWindowText(GlobalString::g_strSwitchRemote);
- }
- m_btnSwitchRemote.SetFaceColor(Global::g_Config.useTW ? RGB_TW : RGB_RR, TRUE);
- WritePrivateProfileString(_T("SATHelper"), _T("useTW"), Global::g_Config.useTW ? _T("1") : _T("0"), Global::g_szConfig);
- // 同时写入resource_run.cfg中:[devices].[rcudevice_selected]
- WritePrivateProfileString(_T("devices"), _T("rcudevice_selected"), Global::g_Config.useTW ? _T("tw") : _T("redrat4"), g_pMainFrame->m_szRsCfgPath);
- LoadSignals();
- ReLoadSignalXml();
- }
- void CIRControlWnd::OnUpdateFindFindinfraRed(CCmdUI* pCmdUI)
- {
- }
- void CIRControlWnd::OnFindFindinfraRedClicked()
- {
- std::thread t([](CIRControlWnd* p) {
- p->m_btnFindinfraRed.EnableWindow(FALSE);
- CCallPython pycall;
- TCHAR szPath[MAX_PATH] = { 0 };
- _stprintf_s(szPath, _T("%sscripts\\FindRC.py"), Global::g_szCurModuleDir);
- PyObject* pRet = pycall.CallPython(szPath, _T("API_FindIRRC"), 1, _variant_t(Global::g_Config.useTW ? Global::g_Config.twSignaldir.c_str() : Global::g_Config.signaldir.c_str()) );
- if (pRet == NULL)
- {
- if (Global::g_Config.nLanguage)
- AfxMessageBox("Running error, please check the script!");
- else
- AfxMessageBox("运行出错,请检查脚本!");
- }
- else
- {
- filehelper fh;
- std::string file = pycall.GetUTF8String(pRet);
- if (PathFileExists(file.c_str())) {
- if (Global::g_Config.useTW) {
- TW::LoadXml(file.c_str());
- Global::g_Config.twUseSignal = file;
- p->m_wndSignalCombo.SelectString(0, fh.getfilename(file).c_str());
- WritePrivateProfileString("TestWizard", "useSignal", file.c_str(), Global::g_szConfig);
- }
- else
- {
- Global::g_Config.use_signal = file;
- WritePrivateProfileString("ir-device", "use-signal", file.c_str(), Global::g_szConfig);
- // 切换通用类型时用到;
- p->m_wndSignalCombo.SelectString(0, Global::g_Config.use_signal.c_str());
- // 加载指定目录的xml信号集文件;
- RedRat::g_loadSignalDataSet(file.c_str());
- }
- }
- else {
- if (Global::g_Config.nLanguage)
- AfxMessageBox("file does not exist!");
- else
- AfxMessageBox("文件不存在!");
- }
- if (pRet)
- Py_DECREF(pRet);
- }
- p->m_btnFindinfraRed.EnableWindow();
- }, this);
- t.detach();
- }
- void CIRControlWnd::OnUpdateFindBluetooth(CCmdUI* pCmdUI)
- {
- }
- void CIRControlWnd::OnFindBluetoothClicked()
- {
- std::thread t([](CIRControlWnd* p) {
- p->m_btnFindBluetooth.EnableWindow(FALSE);
- CCallPython pycall;
- TCHAR szPath[MAX_PATH] = { 0 };
- _stprintf_s(szPath, _T("%sscripts\\FindRC.py"), Global::g_szCurModuleDir);
- PyObject* pRet = pycall.CallPython(szPath, _T("API_FindBLRC"), 1, _variant_t(Global::g_Config.useTW ? Global::g_Config.twSignaldir.c_str() : Global::g_Config.signaldir.c_str()));
- if (pRet == NULL)
- {
- if (Global::g_Config.nLanguage)
- AfxMessageBox("Running error, please check the script!");
- else
- AfxMessageBox("运行出错,请检查脚本!");
- }
- else
- {
- filehelper fh;
- std::string file = pycall.GetUTF8String(pRet);
- if (PathFileExists(file.c_str())) {
- if (Global::g_Config.useTW) {
- TW::LoadXml(file.c_str());
- Global::g_Config.twUseSignal = file;
- p->m_wndSignalCombo.SelectString(0, fh.getfilename(file).c_str());
- WritePrivateProfileString("TestWizard", "useSignal", file.c_str(), Global::g_szConfig);
- }
- else
- {
- Global::g_Config.use_signal = file;
- WritePrivateProfileString("ir-device", "use-signal", file.c_str(), Global::g_szConfig);
- // 切换通用类型时用到;
- p->m_wndSignalCombo.SelectString(0, Global::g_Config.use_signal.c_str());
- // 加载指定目录的xml信号集文件;
- RedRat::g_loadSignalDataSet(file.c_str());
- }
- }
- else {
- if (Global::g_Config.nLanguage)
- AfxMessageBox("file does not exist!");
- else
- AfxMessageBox("文件不存在!");
- }
- if (pRet)
- Py_DECREF(pRet);
- }
- p->m_btnFindBluetooth.EnableWindow();
- }, this);
- t.detach();
- }
- void CIRControlWnd::UpdateSignalBtnStatus()
- {
- std::string data;
- if (Global::g_Config.useTW)
- {
- if (TW::GetSignalsName)
- data = TW::GetSignalsName();
- }
- else {
- // 获取信号集;
- if (RedRat::g_getSignalsName) {
- // 获取信号数据集,以\n分隔;
- data = RedRat::g_getSignalsName();
- }
- }
- CString signals = data.append(1, '\n').c_str();
- signals.MakeUpper();
- for (std::vector<BtnInfo>::iterator it = m_vtBtnInfo.begin(); it != m_vtBtnInfo.end(); it++)
- {
- if (signals.Find((it->name + '\n').c_str()) == -1)
- {
- it->bEnable = false;
- }
- else
- {
- it->bEnable = true;
- }
- }
- }
- void CIRControlWnd::AutoSetDroppedWidth(CComboBox *pCombobox)
- {
- return AddHScroll(pCombobox);
- // Set the height of every item so the item
- // is completely visible.
- CString str;
- CSize sz;
- int dx = 0;
- CDC* pDC = m_wndSignalCombo.GetDC();
- for (int i = 0; i < m_wndSignalCombo.GetCount(); i++)
- {
- m_wndSignalCombo.GetLBText(i, str);
- sz = pDC->GetTextExtent(str);
- // Only want to set the item height if the current height
- // is not big enough.
- if (m_wndSignalCombo.GetItemHeight(i) < sz.cy)
- m_wndSignalCombo.SetItemHeight(i, sz.cy);
- // Only want to set the item width if the current width
- // is not big enough.
- if (m_wndSignalCombo.GetDroppedWidth() < sz.cx)
- {
- m_wndSignalCombo.SetDroppedWidth(sz.cx + 50);
- }
- }
- m_wndSignalCombo.ReleaseDC(pDC);
- }
- void CIRControlWnd::AddHScroll(CComboBox* pCombobox)
- {
- if (!pCombobox)
- return;
- // Find the longest string in the combo box.
- CString str;
- CSize sz;
- int dx = 0;
- TEXTMETRIC tm = { 0 };
- CDC* pDC = pCombobox->GetDC();
- CFont* pFont = pCombobox->GetFont();
- // Select the listbox font, save the old font
- CFont* pOldFont = pDC->SelectObject(pFont);
- // Get the text metrics for avg char width
- pDC->GetTextMetrics(&tm);
- for (int i = 0; i < pCombobox->GetCount(); i++)
- {
- pCombobox->GetLBText(i, str);
- sz = pDC->GetTextExtent(str);
- // Add the avg width to prevent clipping
- sz.cx += tm.tmAveCharWidth;
- if (sz.cx > dx)
- dx = sz.cx;
- }
- // Select the old font back into the DC
- pDC->SelectObject(pOldFont);
- pCombobox->ReleaseDC(pDC);
- // Set the horizontal extent so every character of all strings can
- // be scrolled to.
- pCombobox->SetHorizontalExtent(dx);
- }
- void CIRControlWnd::ReadResourceRunCfg()
- {
- TCHAR szValue[MAX_PATH] = { 0 };
- GetPrivateProfileString(_T("COMM"), _T("issendkeytakepicture_tester"), NULL, szValue, MAX_PATH, Global::g_szResuorceCfg);
- m_rscfg.full_cut = szValue;
- GetPrivateProfileString(_T("COMM"), _T("tg39_port"), NULL, szValue, MAX_PATH, Global::g_szResuorceCfg);
- m_rscfg.tg39_port = szValue;
- GetPrivateProfileString(_T("COMM"), _T("serial_communicator_port"), NULL, szValue, MAX_PATH, Global::g_szResuorceCfg);
- m_rscfg.tv_port = szValue;
- GetPrivateProfileString(_T("COMM"), _T("sat_home"), NULL, szValue, MAX_PATH, Global::g_szResuorceCfg);
- m_rscfg.sat_home = szValue;
- GetPrivateProfileString(_T("COMM"), _T("sat_result_dir"), NULL, szValue, MAX_PATH, Global::g_szResuorceCfg);
- m_rscfg.sat_result_dir = szValue;
- GetPrivateProfileString(_T("COMM"), _T("chroma22293"), NULL, szValue, MAX_PATH, Global::g_szResuorceCfg);
- m_rscfg.chroma22293 = szValue;
- //...
- GetPrivateProfileString(_T("MenuTree"), _T("menutreeselectedchip"), NULL, szValue, MAX_PATH, Global::g_szResuorceCfg);
- m_rscfg.menutree_chip = szValue;
- GetPrivateProfileString(_T("MenuTree"), _T("menutreeselectedstyle"), NULL, szValue, MAX_PATH, Global::g_szResuorceCfg);
- m_rscfg.menutree_style = szValue;
- GetPrivateProfileString(_T("MenuTree"), _T("menutreeselectedchannel"), NULL, szValue, MAX_PATH, Global::g_szResuorceCfg);
- m_rscfg.menutree_channel = szValue;
- }
- void CIRControlWnd::LoadMenuTreePath()
- {
- TCHAR szValue[MAX_PATH] = {0};
- TCHAR szRootDir[MAX_PATH] = { 0 };
- GetPrivateProfileString(_T("COMM"), _T("sat_home"), NULL, szValue, MAX_PATH, Global::g_szResuorceCfg);
- _stprintf_s(szRootDir, _T("%s%s"), szValue, _T("resource\\MenuTree\\"));
- auto _get_dir = [](std::string dir) {
- int nIndex = dir.find_last_of('\\');
- if (nIndex != std::string::npos)
- {
- return dir.substr(nIndex + 1);
- }
- return dir;
- };
- auto _get_name = [](std::string dir) {
- int pos1 = dir.find_last_of('\\');
- if (pos1 != std::string::npos)
- {
- dir = dir.substr(pos1 + 1);
- int pos2 = dir.find_last_of('.');
- if (pos2 != std::string::npos)
- {
- dir = dir.substr(0, pos2);
- int pos3 = dir.find("MenuTree_");
- if (pos3 != std::string::npos)
- {
- return dir.substr(strlen("MenuTree_"));
- }
- }
- }
- return std::string();
- };
- // 查找根目录下的目录;
- filehelper fh;
- STR_VEC vt_dir;
- fh.getsubfolder(szRootDir, &vt_dir);
- for (auto it : vt_dir)
- {
- STR_VEC vt_subdir;
- std::vector<UITree> vtTree;
- fh.getsubfolder(it.c_str(), &vt_subdir);
- for (auto ui : vt_subdir)
- {
- // 查找xls文件;
- UITree uitree;
- uitree.ui = ui;
- fh.getfiles_findout_subfolder(ui.c_str(), _T("*.xls"), &uitree.vtSubUI);
- vtTree.push_back(uitree);
- }
- m_map_tree.insert(std::pair<std::string, std::vector<UITree>>(_get_dir(it), vtTree));
- }
- // 去除目录级;
- for (std::map<std::string, std::vector<UITree>>::iterator it = m_map_tree.begin(); it != m_map_tree.end(); it++)
- {
- for (std::vector<UITree>::iterator ui = it->second.begin(); ui != it->second.end(); ui++)
- {
- ui->ui = _get_dir(ui->ui);
- for (std::vector<std::string>::iterator xls = ui->vtSubUI.begin(); xls != ui->vtSubUI.end();)
- {
- *xls = _get_name(xls->c_str());
- if (xls->size() == 0)
- {
- xls = ui->vtSubUI.erase(xls);
- }
- else
- {
- xls++;
- }
- }
- }
- }
- }
- void CIRControlWnd::InitMenuTreeCombobox()
- {
- if ( m_map_tree.size())
- {
- for (auto it : m_map_tree)
- {
- m_cbTree1.AddString(it.first.c_str());
- }
- // 选择默认项;
- m_cbTree1.SelectString(0, m_rscfg.menutree_chip.c_str());
- // UI下拉框;
- int nIndex = 0;
- CString curText;
- if ((nIndex = m_cbTree1.GetCurSel()) != CB_ERR)
- {
- m_cbTree1.GetLBText(nIndex, curText);
- std::map<std::string, std::vector<UITree>>::iterator itTree = m_map_tree.find(curText.GetString());
- if (itTree != m_map_tree.end())
- {
- for (auto it : itTree->second)
- {
- m_cbTree2.AddString(it.ui.c_str());
- }
- }
- }
- CString strCurChip = _T("");
- CString strCurStyle = _T("");
- m_cbTree2.SelectString(0, m_rscfg.menutree_style.c_str());
- if ((nIndex = m_cbTree2.GetCurSel() ) != CB_ERR)
- {
- m_cbTree2.GetLBText(nIndex, strCurChip);
- }
- if ((nIndex = m_cbTree3.GetCurSel()) != CB_ERR)
- {
- m_cbTree3.GetLBText(nIndex, strCurStyle);
- }
- _stprintf_s(m_szCurMenuTreeDir, _T("%s%s%s\\%s\\"), m_rscfg.sat_home.c_str(), _T("resource\\MenuTree\\"), strCurChip.GetString(), strCurStyle.GetString());
- }
- AutoSetDroppedWidth(&m_cbTree1);
- AutoSetDroppedWidth(&m_cbTree2);
- AutoSetDroppedWidth(&m_cbTree3);
- }
- LRESULT CIRControlWnd::OnIRShotImg(WPARAM wparam, LPARAM lparam)
- {
- return LRESULT();
- }
|