VC++编程常见问题解答十二

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 mynote 的 blog

问:cfile使用了缓冲区吗?
请告诉我cfile到底有没有使用缓冲区来处理文件?
答:cfile没有使用运行库的i/o缓冲例程,从这个意义上讲cfile并没有使用缓冲.
但是有可能操作系统在处理文件时使用了缓冲区,如果你完全不需要缓冲区, 你可
以设置file_flag_no_buffering.cfile工作在这种模式下的唯一的方法 是cfile::attach().
问:dao的密码?
我创建了一个使用数据库的mfc应用程序.用类模板生成cdaorecordset直接打开
数据库(不通过odbc),但问题是我如何打开有密码保护的数据库?
答:试试下面的代码:
 daodbengine* pdbengine = afxdaogetengine();
 assert(pdbengine != null);
 colevariant varusername (strusername, vt_bstrt);
 colevariant varpassword (strpassword, vt_bstrt);
 dao_check(pdbengine->put_defaultuser (v_bstr(&varusername));
 dao_check(pdbengine->put_defaultpassword (v_bstr(&varpassword));
a2:你可以使用cdaodatabase的open方法来打开:
mydaodatabase->open("c:\mydatabasefile.mdb",false,false,";pwd=mypassword");
btw:不要忘了pwd=前面的;号.
问:如何知道clistbox什么时候滚动了?
答:每次绘制列表框都要重绘某项,通过消息wm_ctlcolor从父窗口获得dc颜色.因
此每次列表框的滚动 你都可以用wm_ctlcolor来检验是否滚动.
hbrush cparentdlg::onctlcolor(cdc* pdc, cwnd* pwnd, uint nctlcolor)
  // is the control _the_ list box we're interested in?
  if( nctlcolor == ctlcolor_listbox &&   pwnd->getdlgctrlid() == idc_list )
  {
   // if the top index changed, the list box has been scrolled
   int itop = ((clistbox*)pwnd)->gettopindex();
   if( itop != m_itopold )
   {
     // keeps tracking of the top index changes
     m_itopold = itop;
     // process scrolling
     ...
   }
  }
  hbrush hbr = cdialog::onctlcolor(pdc, pwnd, nctlcolor);
  return hbr;
使用这种方法可以不必为了实现这个功能而去产生一个继承类.
问:视口的不活动性如何处理?
有什么方法使clistview成为类似wm_diasbled的风格,或者使它和背景色一致.
答:你所要做的是处理clistview的wm_setfocus消息,然后在treeview中调用
setfocus, 这样,listview就永远不会获得焦点.
  afx_msg void cmylistview::onsetfocus(cwnd* poldwnd);
  {
    // assuming m_pwndtreeview points to the valid treeview
    // on the left side
    m_pwndtreeview->setfocus();
  }
a2:重载pretranslatemessage,然后当消息为wm_lbuttondown或wm_rbuttondown时 返回真即可.

本文关键:VC++编程常见问题解答十二
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top