本文介绍了我想将此代码转换为java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! < small>< / small> // OptTreeDlg.cpp:实施文件 // #include stdafx.h #include NtRegEdit.h #include OptTreeDlg.h #include SelColorDlg.h #include NtRegistry.h // COptTreeDlg对话框 IMPLEMENT_DYNAMIC(COptTreeDlg,CSAPrefsSubDlg) COptTreeDlg :: COptTreeDlg(CWnd * pParent / * = NULL * / ):CSAPrefsSubDlg(COptTreeDlg :: IDD,pParent) {} COptTreeDlg :: ~COptTreeDlg() {} void COptTreeDlg :: DoDataExchange(CDataExchange * pDX ) { CSAPrefsSubDlg :: DoDataExchange(pDX); DDX_Control(pDX,CHK_BOLD,m_chkBold); DDX_Control(pDX,CHK_BOLD_HIDDEN,m_chkBoldHidden); DDX_Control(pDX,BTN_APPLY_CHGS_TREE,m_btnApplyChgs); DDX_Control(pDX,IDC_TREE1,m_tcTree); DDX_Control(pDX,CHK_COLORS,m_chkColor); } BEGIN_MESSAGE_MAP(COptTreeDlg,CSAPrefsSubDlg) ON_BN_CLICKED(CHK_COLORS,OnColors) ON_NOTIFY(NM_CLICK,IDC_TREE1,OnClickTree) ON_BN_CLICKED (BTN_APPLY_CHGS_TREE,OnApplyChgsTree) ON_BN_CLICKED(CHK_BOLD,OnBold) ON_BN_CLICKED(CHK_BOLD_HIDDEN,OnBoldHidden) END_MESSAGE_MAP() // COptTreeDlg消息处理程序 BOOL COptTreeDlg :: OnInitDialog() { CSAPrefsSubDlg ::的OnInitDialog(); m_bItemsModified = FALSE; m_btnApplyChgs.EnableWindow(m_bItemsModified); m_hRoot = m_tcTree.InsertItem( CNtRegistry,TVI_ROOT); m_hHKCR = m_tcTree.InsertItem( HKEY_CLASSES_ROOT,m_hRoot); m_hHKCU = m_tcTree.InsertItem( HKEY_CURRENT_USER,m_hRoot); m_hHKLM = m_tcTree.InsertItem( HKEY_LOCAL_MACHINE,m_hRoot); m_hHKU = m_tcTree.InsertItem( HKEY_USERS,m_hRoot); m_hHKCC = m_tcTree.InsertItem( HKEY_CURRENT_CONFIG,m_hRoot); m_bBold = theApp.m_clsMainFrm-> m_bBold; m_bBoldHidden = theApp.m_clsMainFrm-> m_bBoldHidden; m_bColors = theApp.m_clsMainFrm-> m_bColors; m_crHKCRColors = theApp.m_clsMainFrm-> m_crHKCRColors; m_crHKCUColors = theApp.m_clsMainFrm-> m_crHKCUColors; m_crHKLMColors = theApp.m_clsMainFrm-> m_crHKLMColors; m_crHKUColors = theApp.m_clsMainFrm-> m_crHKUColors; m_crHKCCColors = theApp.m_clsMainFrm-> m_crHKCCColors; // 让我们获得大胆设置...... m_chkBold.SetCheck(m_bBold); // 让我们获得大胆设置...... m_chkBoldHidden .SetCheck(m_bBoldHidden); // 让我们获取颜色设置...... m_chkColor .SetCheck(m_bColors); m_tcTree.SetItemColor(m_hHKCR,m_crHKCRColors); m_tcTree.SetItemBold(m_hHKCR,m_bBold); m_tcTree.SetItemColor(m_hHKCU,m_crHKCUColors); m_tcTree.SetItemBold(m_hHKCU,m_bBold); m_tcTree.SetItemColor(m_hHKLM,m_crHKLMColors); m_tcTree.SetItemBold(m_hHKLM,m_bBold); m_tcTree.SetItemColor(m_hHKU,m_crHKUColors); m_tcTree.SetItemBold(m_hHKU,m_bBold); m_tcTree.SetItemColor(m_hHKCC,m_crHKCCColors); m_tcTree.SetItemBold(m_hHKCC,m_bBold); m_tcTree.Expand(m_hRoot,TVE_EXPAND); return TRUE; // 除非您将焦点设置为控件 // EXCEPTION:OCX Property Pages应返回FALSE } void COptTreeDlg :: OnClickTree(NMHDR * pNMHDR,LRESULT * pResult) { CPoint pt; GetCursorPos(& pt); CPoint MousePosition = pt; m_tcTree.ScreenToClient(& MousePosition); TVHITTESTINFO HitInfo; HitInfo.pt = MousePosition; UINT uiMask = TVHT_ONITEMLABEL; // TVHT_ONITEM; // | TVHT_ONITEMRIGHT; HTREEITEM hItem = m_tcTree.HitTest(& HitInfo); if (hItem!= NULL&& // 明显 uiMask& HitInfo.flags&& // 制作确定我们在标签上 m_tcTree.GetParentItem(hItem)!= NULL) // 另外我们没有父亲!! { COLORREF rgbColor = m_tcTree.GetItemColor(hItem); // 创建颜色选择器的实例 CSelColorDlg dlgSelColor(GetRValue(rgbColor),GetGValue(rgbColor),GetBValue(rgbColor)); // 显示颜色更改对话框 if (dlgSelColor.DoModal()== IDOK) { m_tcTree.SetRedraw(FALSE); // 选择新颜色 rgbColor = dlgSelColor.GetColor(); // 更改背景颜色 m_tcTree.SetItemColor(hItem,rgbColor) ; CNtRegistry reg; reg.SetKey(HKEY_CURRENT_USER,_T( Software\\NtRegEdit\\Settings \ \TreeCtrl\\KeyColors),FALSE,TRUE); if (m_hHKCR == hItem){ m_crHKCRColors = rgbColor; } else if (m_hHKCU == hItem){ m_crHKCUColors = rgbColor; } else if (m_hHKLM == hItem){ m_crHKLMColors = rgbColor; } else if (m_hHKU == hItem){ m_crHKUColors = rgbColor; } else if (m_hHKCC == hItem){ m_crHKCCColors = rgbColor; } m_bItemsModified = TRUE; m_btnApplyChgs.EnableWindow(m_bItemsModified); // 绘制它...... m_tcTree.SetRedraw (真正); } } * pResult = 0 ; } void COptTreeDlg :: OnColors() { m_bColors =(BOOL)m_chkColor。 GetCheck(); m_bItemsModified = TRUE; m_btnApplyChgs.EnableWindow(m_bItemsModified); RefreshItems(); } void COptTreeDlg :: OnBold() { m_bBold =(BOOL)m_chkBold。 GetCheck(); m_bItemsModified = TRUE; m_btnApplyChgs.EnableWindow(m_bItemsModified); RefreshItems(); } void COptTreeDlg :: OnBoldHidden() { m_bBoldHidden =(BOOL)m_chkBoldHidden。 GetCheck(); m_bItemsModified = TRUE; m_btnApplyChgs.EnableWindow(m_bItemsModified); RefreshItems(); } void COptTreeDlg :: RefreshItems( void ) { m_tcTree.SetRedraw(FALSE); m_tcTree.DeleteAllItems(); m_hRoot = m_tcTree.InsertItem( CNtRegistry,TVI_ROOT); m_hHKCR = m_tcTree.InsertItem( HKEY_CLASSES_ROOT,m_hRoot); m_hHKCU = m_tcTree.InsertItem( HKEY_CURRENT_USER,m_hRoot); m_hHKLM = m_tcTree.InsertItem( HKEY_LOCAL_MACHINE,m_hRoot); m_hHKU = m_tcTree.InsertItem( HKEY_USERS,m_hRoot); m_hHKCC = m_tcTree.InsertItem( HKEY_CURRENT_CONFIG,m_hRoot); m_crHKCRColors = RGB( 0 , 0 , 0 ); m_crHKCUColors = RGB( 0 , 0 , 0 ); m_crHKLMColors = RGB( 0 , 0 , 0 ); m_crHKUColors = RGB( 0 , 0 , 0 ); m_crHKCCColors = RGB( 0 , 0 , 0 ); m_bBold =(BOOL)m_chkBold.GetCheck(); m_bBoldHidden =(BOOL)m_chkBoldHidden.GetCheck(); m_bColors =(BOOL)m_chkColor.GetCheck(); CNtRegistry reg; if (reg.SetKey(HKEY_CURRENT_USER,_T( Software \\NtRegEdit \\Settings \\TreeCtrl),FALSE,TRUE)) { // 从注册表中读取... // m_bBold = reg.ReadBool(_T(UseBold),FALSE); // m_bBoldHidden = reg.ReadBool(_T(UseBoldHidden),FALSE); // m_bColors = reg.ReadBool(_T(UseColor),FALSE); if (m_bColors) { if (reg.SetKey(HKEY_CURRENT_USER,_T( Software\\NtRegEdit\\Settings\\TreeCtrl\\\ KeyColors),FALSE,TRUE)) { m_crHKCRColors = reg.ReadColor(_T( HKCR),RGB( 0 , 0 , 0 )); m_crHKCUColors = reg.ReadColor(_T( HKCU),RGB( 0 , 0 , 0 )); m_crHKLMColors = reg.ReadColor(_T( HKLM),RGB( 0 , 0 , 0 )); m_crHKUColors = reg.ReadColor(_T( HKU),RGB( 0 , 0 , 0 )); m_crHKCCColors = reg.ReadColor(_T( HKCC),RGB( 0 , 0 , 0 )); } } } m_tcTree.SetItemColor(m_hHKCR,m_crHKCRColors); m_tcTree.SetItemBold(m_hHKCR,m_bBold); m_tcTree.SetItemColor(m_hHKCU,m_crHKCUColors); m_tcTree.SetItemBold(m_hHKCU,m_bBold); m_tcTree.SetItemColor(m_hHKLM,m_crHKLMColors); m_tcTree.SetItemBold(m_hHKLM,m_bBold); m_tcTree.SetItemColor(m_hHKU,m_crHKUColors); m_tcTree.SetItemBold(m_hHKU,m_bBold); m_tcTree.SetItemColor(m_hHKCC,m_crHKCCColors); m_tcTree.SetItemBold(m_hHKCC,m_bBold); m_tcTree.Expand(m_hRoot,TVE_EXPAND); m_tcTree.SetRedraw(TRUE); } void COptTreeDlg :: OnApplyChgsTree() { theApp.m_clsMainFrm - > m_bBold = m_bBold; theApp.m_clsMainFrm-> m_bBoldHidden = m_bBoldHidden; theApp.m_clsMainFrm-> m_bColors = m_bColors; theApp.m_clsMainFrm-> m_crHKCRColors = m_crHKCRColors; theApp.m_clsMainFrm-> m_crHKCUColors = m_crHKCUColors; theApp.m_clsMainFrm-> m_crHKLMColors = m_crHKLMColors; theApp.m_clsMainFrm-> m_crHKUColors = m_crHKUColors; theApp.m_clsMainFrm-> m_crHKCCColors = m_crHKCCColors; CNtRegistry reg; if (reg.SetKey(HKEY_CURRENT_USER,_T( Software \\NtRegEdit \\Settings \\TreeCtrl),FALSE,TRUE)) { // 将其保存在注册表中...... reg.WriteBool(_T( UseBold),theApp.m_clsMainFrm-> m_bBold); reg.WriteBool(_T( UseBoldHidden),theApp.m_clsMainFrm-> m_bBoldHidden ); reg.WriteBool(_T( UseColor),theApp.m_clsMainFrm-> m_bColors ); if (reg.SetKey(HKEY_CURRENT_USER,_T( Software \\NtRegEdit \\Settings \\TreeCtrl \\KeyColors),FALSE,TRUE)&& theApp.m_clsMainFrm - > m_bColors) { // 将其保存在注册表中...... reg.WriteColor(_T( HKCR),theApp.m_clsMainFrm-> ; m_crHKCRColors); reg.WriteColor(_T( HKCU),theApp.m_clsMainFrm-> m_crHKCUColors ); reg.WriteColor(_T( HKLM),theApp.m_clsMainFrm-> m_crHKLMColors ); reg.WriteColor(_T( HKU),theApp.m_clsMainFrm-> m_crHKUColors ); reg.WriteColor(_T( HKCC),theApp.m_clsMainFrm-> m_crHKCCColors ); } } RefreshItems(); CTreeCtrl& tc = theApp.m_clsTV-> GetTreeCtrl(); tc.DeleteAllItems(); theApp.m_clsTV-> m_hRoot = tc.InsertItem(_T( CNtRegistry), 0 , 0 ); theApp.m_clsTV-> m_hHKCR = tc.InsertItem(_T( HKEY_CLASSES_ROOT), 2 , 2 ,theApp.m_clsTV-> m_hRoot); tc.InsertItem(FAKEDITEM, 5 , 5 ,theApp.m_clsTV-> m_hHKCR, TVI_LAST); theApp.m_clsTV-> SetItemColor(theApp.m_clsTV-> m_hHKCR,theApp.m_clsMainFrm-> m_crHKCRColors); theApp.m_clsTV-> SetItemBold(theApp.m_clsTV-> m_hHKCR,theApp.m_clsMainFrm-> m_bBold); theApp.m_clsTV-> m_hHKCU = tc.InsertItem(_T( HKEY_CURRENT_USER), 2 , 2 ,theApp.m_clsTV-> m_hRoot); tc.InsertItem(FAKEDITEM, 5 , 5 ,theApp.m_clsTV-> m_hHKCU, TVI_LAST); theApp.m_clsTV-> SetItemColor(theApp.m_clsTV-> m_hHKCU,theApp.m_clsMainFrm-> m_crHKCUColors); theApp.m_clsTV-> SetItemBold(theApp.m_clsTV-> m_hHKCU,theApp.m_clsMainFrm-> m_bBold); theApp.m_clsTV-> m_hHKLM = tc.InsertItem(_T( HKEY_LOCAL_MACHINE), 2 , 2 ,theApp.m_clsTV-> m_hRoot); tc.InsertItem(FAKEDITEM, 5 , 5 ,theApp.m_clsTV-> m_hHKLM, TVI_LAST); theApp.m_clsTV-> SetItemColor(theApp.m_clsTV-> m_hHKLM,theApp.m_clsMainFrm-> m_crHKLMColors); theApp.m_clsTV-> SetItemBold(theApp.m_clsTV-> m_hHKLM,theApp.m_clsMainFrm-> m_bBold); theApp.m_clsTV-> m_hHKU = tc.InsertItem(_T( HKEY_USERS), 2 , 2 ,theApp.m_clsTV-> m_hRoot); tc.InsertItem(FAKEDITEM, 5 , 5 ,theApp.m_clsTV-> m_hHKU, TVI_LAST); theApp.m_clsTV-> SetItemColor(theApp.m_clsTV-> m_hHKU,theApp.m_clsMainFrm-> m_crHKUColors); theApp.m_clsTV-> SetItemBold(theApp.m_clsTV-> m_hHKU,theApp.m_clsMainFrm-> m_bBold); theApp.m_clsTV-> m_hHKCC = tc.InsertItem(_T( HKEY_CURRENT_CONFIG), 2 , 2 ,theApp.m_clsTV-> m_hRoot); tc.InsertItem(FAKEDITEM, 5 , 5 ,theApp.m_clsTV-> m_hHKCC, TVI_LAST); theApp.m_clsTV-> SetItemColor(theApp.m_clsTV-> m_hHKCC,theApp.m_clsMainFrm-> m_crHKCCColors); theApp.m_clsTV-> SetItemBold(theApp.m_clsTV-> m_hHKCC,theApp.m_clsMainFrm-> m_bBold); theApp.m_clsTV-> m_ntReg.LookupSID(theApp.m_clsTV-> m_csSID); theApp.m_clsTV-> m_csSID.Insert( 0 ,_ T( \\Registry\\User\\)); tc.Expand(theApp.m_clsTV-> m_hRoot,TVE_EXPAND); m_bItemsModified = FALSE; m_btnApplyChgs.EnableWindow(m_bItemsModified); } void COptTreeDlg :: OnOK() { if (m_bItemsModified){ if (MessageBox( 某些项目已被修改!是否要保存更改?, TREECTRL - 修改, MB_YESNO | MB_ICONQUESTION)== IDYES){ COptTreeDlg :: OnApplyChgsTree(); } } CSAPrefsSubDlg :: OnOK(); } 解决方案 这里我们回答成员在编程时遇到的具体问题。 我们无法处理整个源代码。你需要自己做。 如果你在编码时遇到任何困难,请随时回到这里,并提出另一个问题来描述这个场景。 各位会员很乐意为您提供帮助。 :) <small></small>// OptTreeDlg.cpp : implementation file//#include "stdafx.h"#include "NtRegEdit.h"#include "OptTreeDlg.h"#include "SelColorDlg.h"#include "NtRegistry.h"// COptTreeDlg dialogIMPLEMENT_DYNAMIC(COptTreeDlg, CSAPrefsSubDlg)COptTreeDlg::COptTreeDlg(CWnd* pParent /*=NULL*/): CSAPrefsSubDlg(COptTreeDlg::IDD, pParent){}COptTreeDlg::~COptTreeDlg(){}void COptTreeDlg::DoDataExchange(CDataExchange* pDX){CSAPrefsSubDlg::DoDataExchange(pDX);DDX_Control(pDX, CHK_BOLD, m_chkBold);DDX_Control(pDX, CHK_BOLD_HIDDEN, m_chkBoldHidden);DDX_Control(pDX, BTN_APPLY_CHGS_TREE, m_btnApplyChgs);DDX_Control(pDX, IDC_TREE1, m_tcTree);DDX_Control(pDX, CHK_COLORS, m_chkColor);}BEGIN_MESSAGE_MAP(COptTreeDlg, CSAPrefsSubDlg)ON_BN_CLICKED(CHK_COLORS, OnColors)ON_NOTIFY(NM_CLICK, IDC_TREE1, OnClickTree)ON_BN_CLICKED(BTN_APPLY_CHGS_TREE, OnApplyChgsTree)ON_BN_CLICKED(CHK_BOLD, OnBold)ON_BN_CLICKED(CHK_BOLD_HIDDEN, OnBoldHidden)END_MESSAGE_MAP()// COptTreeDlg message handlersBOOL COptTreeDlg::OnInitDialog(){CSAPrefsSubDlg::OnInitDialog();m_bItemsModified = FALSE;m_btnApplyChgs.EnableWindow(m_bItemsModified);m_hRoot = m_tcTree.InsertItem("CNtRegistry",TVI_ROOT);m_hHKCR = m_tcTree.InsertItem("HKEY_CLASSES_ROOT",m_hRoot);m_hHKCU = m_tcTree.InsertItem("HKEY_CURRENT_USER",m_hRoot);m_hHKLM = m_tcTree.InsertItem("HKEY_LOCAL_MACHINE",m_hRoot);m_hHKU = m_tcTree.InsertItem("HKEY_USERS",m_hRoot);m_hHKCC = m_tcTree.InsertItem("HKEY_CURRENT_CONFIG",m_hRoot);m_bBold = theApp.m_clsMainFrm->m_bBold;m_bBoldHidden = theApp.m_clsMainFrm->m_bBoldHidden;m_bColors = theApp.m_clsMainFrm->m_bColors;m_crHKCRColors = theApp.m_clsMainFrm->m_crHKCRColors;m_crHKCUColors = theApp.m_clsMainFrm->m_crHKCUColors;m_crHKLMColors = theApp.m_clsMainFrm->m_crHKLMColors;m_crHKUColors = theApp.m_clsMainFrm->m_crHKUColors;m_crHKCCColors = theApp.m_clsMainFrm->m_crHKCCColors;// Lets get Bold setting...m_chkBold.SetCheck(m_bBold);// Lets get Bold setting...m_chkBoldHidden.SetCheck(m_bBoldHidden);// Lets get Color settings...m_chkColor.SetCheck(m_bColors);m_tcTree.SetItemColor(m_hHKCR, m_crHKCRColors);m_tcTree.SetItemBold(m_hHKCR, m_bBold);m_tcTree.SetItemColor(m_hHKCU, m_crHKCUColors);m_tcTree.SetItemBold(m_hHKCU, m_bBold);m_tcTree.SetItemColor(m_hHKLM, m_crHKLMColors);m_tcTree.SetItemBold(m_hHKLM, m_bBold);m_tcTree.SetItemColor(m_hHKU, m_crHKUColors);m_tcTree.SetItemBold(m_hHKU, m_bBold);m_tcTree.SetItemColor(m_hHKCC, m_crHKCCColors);m_tcTree.SetItemBold(m_hHKCC, m_bBold);m_tcTree.Expand(m_hRoot, TVE_EXPAND);return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE}void COptTreeDlg::OnClickTree(NMHDR* pNMHDR, LRESULT* pResult){CPoint pt;GetCursorPos(&pt);CPoint MousePosition = pt;m_tcTree.ScreenToClient ( &MousePosition );TVHITTESTINFO HitInfo;HitInfo.pt = MousePosition;UINT uiMask = TVHT_ONITEMLABEL;//TVHT_ONITEM;// | TVHT_ONITEMRIGHT;HTREEITEM hItem = m_tcTree.HitTest(&HitInfo);if (hItem != NULL &&// ObviousuiMask & HitInfo.flags &&// Make sure we are on the labelm_tcTree.GetParentItem(hItem) != NULL)// Also that we have NO Parent!!{COLORREF rgbColor = m_tcTree.GetItemColor(hItem);// create an instance of the color selectorCSelColorDlg dlgSelColor(GetRValue(rgbColor),GetGValue(rgbColor),GetBValue(rgbColor));// display the color changing dialog boxif(dlgSelColor.DoModal() == IDOK){m_tcTree.SetRedraw(FALSE);// select the new colourrgbColor = dlgSelColor.GetColor();// change the background colorm_tcTree.SetItemColor(hItem, rgbColor);CNtRegistry reg;reg.SetKey(HKEY_CURRENT_USER,_T("Software\\NtRegEdit\\Settings\\TreeCtrl\\KeyColors"),FALSE,TRUE);if (m_hHKCR == hItem) {m_crHKCRColors = rgbColor;}else if (m_hHKCU == hItem) {m_crHKCUColors = rgbColor;}else if (m_hHKLM == hItem) {m_crHKLMColors = rgbColor;}else if (m_hHKU == hItem) {m_crHKUColors = rgbColor;}else if (m_hHKCC == hItem) {m_crHKCCColors = rgbColor;}m_bItemsModified = TRUE;m_btnApplyChgs.EnableWindow(m_bItemsModified);// Paint it...m_tcTree.SetRedraw(TRUE);}}*pResult = 0;}void COptTreeDlg::OnColors(){m_bColors = (BOOL)m_chkColor.GetCheck();m_bItemsModified = TRUE;m_btnApplyChgs.EnableWindow(m_bItemsModified);RefreshItems();}void COptTreeDlg::OnBold(){m_bBold = (BOOL)m_chkBold.GetCheck();m_bItemsModified = TRUE;m_btnApplyChgs.EnableWindow(m_bItemsModified);RefreshItems();}void COptTreeDlg::OnBoldHidden(){m_bBoldHidden = (BOOL)m_chkBoldHidden.GetCheck();m_bItemsModified = TRUE;m_btnApplyChgs.EnableWindow(m_bItemsModified);RefreshItems();}void COptTreeDlg::RefreshItems(void){m_tcTree.SetRedraw(FALSE);m_tcTree.DeleteAllItems();m_hRoot = m_tcTree.InsertItem("CNtRegistry",TVI_ROOT);m_hHKCR = m_tcTree.InsertItem("HKEY_CLASSES_ROOT",m_hRoot);m_hHKCU = m_tcTree.InsertItem("HKEY_CURRENT_USER",m_hRoot);m_hHKLM = m_tcTree.InsertItem("HKEY_LOCAL_MACHINE",m_hRoot);m_hHKU = m_tcTree.InsertItem("HKEY_USERS",m_hRoot);m_hHKCC = m_tcTree.InsertItem("HKEY_CURRENT_CONFIG",m_hRoot);m_crHKCRColors = RGB(0,0,0);m_crHKCUColors = RGB(0,0,0);m_crHKLMColors = RGB(0,0,0);m_crHKUColors = RGB(0,0,0);m_crHKCCColors = RGB(0,0,0);m_bBold = (BOOL)m_chkBold.GetCheck();m_bBoldHidden = (BOOL)m_chkBoldHidden.GetCheck();m_bColors = (BOOL)m_chkColor.GetCheck();CNtRegistry reg;if (reg.SetKey(HKEY_CURRENT_USER,_T("Software\\NtRegEdit\\Settings\\TreeCtrl"),FALSE,TRUE)){// Read it from the registry...//m_bBold = reg.ReadBool(_T("UseBold"),FALSE);//m_bBoldHidden = reg.ReadBool(_T("UseBoldHidden"),FALSE);//m_bColors = reg.ReadBool(_T("UseColor"),FALSE);if (m_bColors) {if (reg.SetKey(HKEY_CURRENT_USER,_T("Software\\NtRegEdit\\Settings\\TreeCtrl\\KeyColors"),FALSE,TRUE)){m_crHKCRColors = reg.ReadColor(_T("HKCR"),RGB(0,0,0));m_crHKCUColors = reg.ReadColor(_T("HKCU"),RGB(0,0,0));m_crHKLMColors = reg.ReadColor(_T("HKLM"),RGB(0,0,0));m_crHKUColors = reg.ReadColor(_T("HKU"),RGB(0,0,0));m_crHKCCColors = reg.ReadColor(_T("HKCC"),RGB(0,0,0));}}}m_tcTree.SetItemColor(m_hHKCR, m_crHKCRColors);m_tcTree.SetItemBold(m_hHKCR, m_bBold);m_tcTree.SetItemColor(m_hHKCU, m_crHKCUColors);m_tcTree.SetItemBold(m_hHKCU, m_bBold);m_tcTree.SetItemColor(m_hHKLM, m_crHKLMColors);m_tcTree.SetItemBold(m_hHKLM, m_bBold);m_tcTree.SetItemColor(m_hHKU, m_crHKUColors);m_tcTree.SetItemBold(m_hHKU, m_bBold);m_tcTree.SetItemColor(m_hHKCC, m_crHKCCColors);m_tcTree.SetItemBold(m_hHKCC, m_bBold);m_tcTree.Expand(m_hRoot, TVE_EXPAND);m_tcTree.SetRedraw(TRUE);}void COptTreeDlg::OnApplyChgsTree(){theApp.m_clsMainFrm->m_bBold = m_bBold;theApp.m_clsMainFrm->m_bBoldHidden = m_bBoldHidden;theApp.m_clsMainFrm->m_bColors = m_bColors;theApp.m_clsMainFrm->m_crHKCRColors = m_crHKCRColors;theApp.m_clsMainFrm->m_crHKCUColors = m_crHKCUColors;theApp.m_clsMainFrm->m_crHKLMColors = m_crHKLMColors;theApp.m_clsMainFrm->m_crHKUColors = m_crHKUColors;theApp.m_clsMainFrm->m_crHKCCColors = m_crHKCCColors;CNtRegistry reg;if (reg.SetKey(HKEY_CURRENT_USER,_T("Software\\NtRegEdit\\Settings\\TreeCtrl"),FALSE,TRUE)){// Save it in the registry...reg.WriteBool(_T("UseBold"),theApp.m_clsMainFrm->m_bBold);reg.WriteBool(_T("UseBoldHidden"),theApp.m_clsMainFrm->m_bBoldHidden);reg.WriteBool(_T("UseColor"),theApp.m_clsMainFrm->m_bColors);if (reg.SetKey(HKEY_CURRENT_USER,_T("Software\\NtRegEdit\\Settings\\TreeCtrl\\KeyColors"),FALSE,TRUE) &&theApp.m_clsMainFrm->m_bColors){// Save it in the registry...reg.WriteColor(_T("HKCR"), theApp.m_clsMainFrm->m_crHKCRColors);reg.WriteColor(_T("HKCU"), theApp.m_clsMainFrm->m_crHKCUColors);reg.WriteColor(_T("HKLM"), theApp.m_clsMainFrm->m_crHKLMColors);reg.WriteColor(_T("HKU"), theApp.m_clsMainFrm->m_crHKUColors);reg.WriteColor(_T("HKCC"), theApp.m_clsMainFrm->m_crHKCCColors);}}RefreshItems();CTreeCtrl &tc = theApp.m_clsTV->GetTreeCtrl();tc.DeleteAllItems();theApp.m_clsTV->m_hRoot = tc.InsertItem(_T("CNtRegistry"),0,0);theApp.m_clsTV->m_hHKCR = tc.InsertItem(_T("HKEY_CLASSES_ROOT"),2,2,theApp.m_clsTV->m_hRoot);tc.InsertItem(FAKEDITEM,5,5,theApp.m_clsTV->m_hHKCR,TVI_LAST);theApp.m_clsTV->SetItemColor(theApp.m_clsTV->m_hHKCR,theApp.m_clsMainFrm->m_crHKCRColors);theApp.m_clsTV->SetItemBold(theApp.m_clsTV->m_hHKCR,theApp.m_clsMainFrm->m_bBold);theApp.m_clsTV->m_hHKCU = tc.InsertItem(_T("HKEY_CURRENT_USER"),2,2,theApp.m_clsTV->m_hRoot);tc.InsertItem(FAKEDITEM,5,5,theApp.m_clsTV->m_hHKCU,TVI_LAST);theApp.m_clsTV->SetItemColor(theApp.m_clsTV->m_hHKCU,theApp.m_clsMainFrm->m_crHKCUColors);theApp.m_clsTV->SetItemBold(theApp.m_clsTV->m_hHKCU,theApp.m_clsMainFrm->m_bBold);theApp.m_clsTV->m_hHKLM = tc.InsertItem(_T("HKEY_LOCAL_MACHINE"),2,2,theApp.m_clsTV->m_hRoot);tc.InsertItem(FAKEDITEM,5,5,theApp.m_clsTV->m_hHKLM,TVI_LAST);theApp.m_clsTV->SetItemColor(theApp.m_clsTV->m_hHKLM,theApp.m_clsMainFrm->m_crHKLMColors);theApp.m_clsTV->SetItemBold(theApp.m_clsTV->m_hHKLM,theApp.m_clsMainFrm->m_bBold);theApp.m_clsTV->m_hHKU = tc.InsertItem(_T("HKEY_USERS"),2,2,theApp.m_clsTV->m_hRoot);tc.InsertItem(FAKEDITEM,5,5,theApp.m_clsTV->m_hHKU,TVI_LAST);theApp.m_clsTV->SetItemColor(theApp.m_clsTV->m_hHKU,theApp.m_clsMainFrm->m_crHKUColors);theApp.m_clsTV->SetItemBold(theApp.m_clsTV->m_hHKU,theApp.m_clsMainFrm->m_bBold);theApp.m_clsTV->m_hHKCC = tc.InsertItem(_T("HKEY_CURRENT_CONFIG"),2,2,theApp.m_clsTV->m_hRoot);tc.InsertItem(FAKEDITEM,5,5,theApp.m_clsTV->m_hHKCC,TVI_LAST);theApp.m_clsTV->SetItemColor(theApp.m_clsTV->m_hHKCC,theApp.m_clsMainFrm->m_crHKCCColors);theApp.m_clsTV->SetItemBold(theApp.m_clsTV->m_hHKCC,theApp.m_clsMainFrm->m_bBold);theApp.m_clsTV->m_ntReg.LookupSID(theApp.m_clsTV->m_csSID);theApp.m_clsTV->m_csSID.Insert(0,_T("\\Registry\\User\\"));tc.Expand(theApp.m_clsTV->m_hRoot,TVE_EXPAND);m_bItemsModified = FALSE;m_btnApplyChgs.EnableWindow(m_bItemsModified);}void COptTreeDlg::OnOK(){if (m_bItemsModified) {if (MessageBox("Some items have been modified! Do you want to save the changes?", "TREECTRL - Modifications ", MB_YESNO|MB_ICONQUESTION) == IDYES) {COptTreeDlg::OnApplyChgsTree();}}CSAPrefsSubDlg::OnOK();} 解决方案 Here we answer specific questions which members face during programming.We can't work on the whole source code. You need to do that yourself.If you face any difficulty while coding, feel free to come back here and ask another question with specific issue describing the scenario.Members will be happy to help you then. :) 这篇关于我想将此代码转换为java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-01 14:35