VC雕虫小技集(六)1,,如何取得Tree Control上的CheckBox状态~ OnInit中加: m_treeCtrl.InsertItem("item1"); m_treeCtrl.InsertItem("item2"); :office" /> void CCDialogDlg::OnButton1() { HTREEITEM hItem = m_treeCtrl.GetRootItem(); while(NULL != hItem) { CString str= m_treeCtrl.GetItemText(hItem); if("item2" == str) { if(m_treeCtrl.GetCheck(hItem)) AfxMessageBox("选中"); } hItem = m_treeCtrl.GetNextVisibleItem(hItem); } }
首先通过FindWindow取得windows程序的窗口句柄, 然后通过GetDlgItem取得其中输入框的窗口句柄, 最后,向该窗口句柄发送WM_CHAR消息即可显示字符 例如,对于Notepad窗口,可以以如下的方式向其中输入一个'a': 取得记事本的窗口句柄 HWND hWnd = ::FindWindow( NULL , "未定标题 - 记事本" ); 取得其中输入框的窗口句柄 HWND hEdit = ::GetDlgItem( hWnd , 0x0F ); // 这里0x0F是编辑框的ID,可在SPY++中观察得到 向输入框中填写'a' ::SendMessage( hEdit , WM_CHAR , (WPARAM)'A' , 0x00000001 );
3, 当前时间: CTime t = CTime::GetCurrentTime(); CString str; str.Format("%d-%d-%d",t.GetYear(),t.GetMonth(),t.GetDay()); str+= t.Format("--%H-%M-%S"); AfxMessageBox(str); 一定要用CTime::GetCurrentTime();GetCurrentTime()是一个过时的函数.
4, //改变按钮的背景色。 HBRUSH CRectWindow2View::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor); switch (nCtlColor) { case CTLCOLOR_BTN: { CBrush Brush (RGB (128 , 0 , 128) );//你的颜色
CBrush* pOldBrush = pDC->SelectObject(&Brush);
pDC->SelectObject (pOldBrush ); } } return CFormView::OnCtlColor(pDC, pWnd, nCtlColor); }
5, 加速键的使用. 在Dlg的头文件中加入: HACCEL m_hAccel; 在Dlg的构造函数中加载加速键: 基于对话框的程序如何使用加速键? m_hAccel=::LoadAccelerators(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_ACCELERATOR1));//加速键ID 重载PreTranslateMessage函数: BOOL CDlg::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if(m_hAccel!=NULL) if(::TranslateAccelerator(m_hWnd,m_hAccel,pMsg)) return TRUE; return CDialog::PreTranslateMessage(pMsg); }
6,怎么把一个文件保存到其它地方? if(!CopyFile("f://he.txt","d://he1.txt",true)) { if(IDOK == MessageBox("有同名文件,你要覆盖吗?",NULL,MB_OKCANCEL)) { CopyFile("f://he.txt","d://he1.txt",false); } else return; } DeleteFile("f://he.txt");
|
VC雕虫小技集(六)
最新推荐文章于 2024-07-20 23:14:06 发布
原文:
VC雕虫小技集(六)