链接:MSDN UserNet等

Q我想知道如何在VC中实现可塌陷的PanelBar界面(类似于OutlookBar)? 
T可塌陷的PanelBar界面比outlookbar更有吸引力,Windows XP左边的导航工具面版就是采用这种风格,采用这种风格的应用程序也越来越多,比如各种杀毒软件,可能delphi提供的vcl组件可以简化这种操作,对于这种“傻瓜式”的实现我不喜欢。我还是想用C++,实现这种界面,而且我不喜欢附带额外的动态链接库,也不想让程序超过1M,我现在的程序界面已经355K。我采用属性表属性页界面,我想把它修改为这种界面。
http://www.codeproject.com/useritems/CollapsiblePanelBar.asp
是一个使用C#实现的例子程序。怎么使用现成的类代码实现这种界面呢?
Ahttp://freehost10.websamba.com/jiangsheng/water/
DHTML based
Q为什么在debug下运行完全正常的程序在release下却通不过? 
T在程序中我派生了一个标签静态类,在类中映射了单击函数,有函数中用GetParent()->PostMessage(MyMessage);发送一个自定义消息给父窗口(对话框),在对话框中映射一个响应该消息的函数用做数据处理。在release下经跟踪,消息得到响应,消息处理函数中的代码均能正常通过,但总会弹出提示,说0X??????指令引用的0000????的内存不能读,请各位大侠们指点一二,在下先谢谢了!!
Ahttp://support.microsoft.com/default.aspx?scid=KB;en-us;195032&
Q两个问题:IHTMLDocument3为什么不能用;如何利用IHTMLDocument2把TABLE中CELL解析出来 
T他SDK开发包?
2:如何利用IHTMLDocument2把页面中的一个TABLE表所有的CELL的文字都解析出来?
帮帮忙各位!!!!
A1 去http://www.microsoft.com/msdownload/platformsdk/sdkupdate/升级你的SDK头文件
2 http://www.codeguru.com/atl/AnalyzeIE.html
Q如何把ie内嵌到自己的dialog中
T如何把ie内嵌到自己的dialog中
Ahttp://msdn.microsoft.com/workshop/browser/webbrowser/tutorials/wbtutorial.asp
Q大家帮忙看看,IHTMLDocument2 的问题? 
T我的第一种是先设置了SetCapture();
然后在下面
void CDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
 static TCHAR buf[100];
  POINT pt;
  GetCursorPos(&pt);
  HWND hwnd=::WindowFromPoint(pt);
  if(hwnd!=NULL){
   ::GetClassName( hwnd, (LPTSTR)&buf, 100 );
   if ( _tcscmp( buf, _T("Internet Explorer_Server") ) == 0 ){
    POINT iept=pt;
    ::ScreenToClient(hwnd,&iept);
    GetDocInterfaceByMSAA(hwnd);//这个函数里面得到句柄 ,
//GetDocInterface(hwnd);这个不行
   }
  }
 CDialog::OnLButtonUp(nFlags, point);
}

而第2种方法是,做了一个mouse钩子,给onLButtonUp时间发一个WM_LBUUTONUP消息,则上面的两个函数都没有取到IHTMLDocument2,在下面的代码中,列出了出错的位置,不知道是什么原因?

IHTMLDocument2* GetDocInterfaceByMSAA(HWND hwnd)
{
 HRESULT hr;
 HINSTANCE hInst = ::LoadLibrary( _T("OLEACC.DLL") );

 IHTMLDocument2* pDoc2=NULL;
 if ( hInst != NULL ){
  if ( hwnd != NULL ){
      LPFNACCESSIBLEOBJECTFROMWINDOW pfAccessibleObjectFromWindow =
    (LPFNACCESSIBLEOBJECTFROMWINDOW)::GetProcAddress(hInst,_T("AccessibleObjectFromWindow"));
   if(pfAccessibleObjectFromWindow != NULL){
    CComPtr<IAccessible> spAccess;
    hr=pfAccessibleObjectFromWindow(hwnd,0,
     IID_IAccessible,(void**) &spAccess);//取得Webbrowser控件的IAccessible接口
    if ( SUCCEEDED(hr) ){
     CComPtr<IServiceProvider> spServiceProv;
     hr=spAccess->QueryInterface(IID_IServiceProvider,(void**)&spServiceProv);//第2种方法执行这里就hr小于0了
     if(hr==S_OK){
      CComPtr<IHTMLWindow2> spWin;
      hr=spServiceProv->QueryService(IID_IHTMLWindow2,IID_IHTMLWindow2,
       (void**)&spWin);
            if(hr==S_OK)
       spWin->get_document(&pDoc2);
     }
    }
   }
  }
  ::FreeLibrary(hInst);
 }
 else{
  AfxMessageBox(_T("请您安装Microsoft Active Accessibility"));
 }
 return pDoc2;
}

IHTMLDocument2* GetDocInterface(HWND hWnd)
{
 HINSTANCE hInst = ::LoadLibrary( _T("OLEACC.DLL") );
 IHTMLDocument2* pDoc2=NULL;
 if ( hInst != NULL ){
  if ( hWnd != NULL ){
   CComPtr<IHTMLDocument> spDoc=NULL;
   LRESULT lRes;

   UINT nMsg = ::RegisterWindowMessage( _T("WM_HTML_GETOBJECT") );
   ::SendMessageTimeout( hWnd, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes );

   LPFNOBJECTFROMLRESULT pfObjectFromLresult = (LPFNOBJECTFROMLRESULT)::GetProcAddress( hInst, _T("ObjectFromLresult") );
   if ( pfObjectFromLresult != NULL ){
    HRESULT hr;
    hr=(*pfObjectFromLresult)( lRes,IID_IHTMLDocument,0,(void**)&spDoc);//第2种方法执行到此处错误
    if ( SUCCEEDED(hr) ){
     CComPtr<IDispatch> spDisp;
     CComQIPtr<IHTMLWindow2> spWin;
     spDoc->get_Script( &spDisp );
     spWin = spDisp;
     spWin->get_document( &pDoc2 );
    }
   }
  }
  ::FreeLibrary(hInst);
 }
 else
  AfxMessageBox(_T("请您安装Microsoft Active Accessibility"));
 }
 return pDoc2;
}

我之所以用鼠标钩子的原因是,我的程序在后台执行,
Ahttp://www.codeguru.com/ieprogram/SPwdSpy.html
Q要做一个局域网内的屏幕实时监控程序,有什么好思路吗? 
T初步想法是客户端程序定时抓图,压缩后传给服务端,不知是否有更高效的处理方法吗?比如以视频的方式传送,或是捕获windows的消息只截取有变化的部分屏幕传送等等。。。看pcanywhere在广域网上运行速度都很快,不知它用了什么技术?
Ahttp://www.rendersoftware.com/products/camstudio/
Q找对地方啦,问一下怎么不使用navigate2函数直接显示网页?
T老总让我把一个很大的HTML文件分割成很多小的文件来显示打印,
而我对于VC不熟悉,对COM也只是在VB应用方面有些了解。

我现在使用put_innerHTML实现了显示,但是右键看源文件的时候只有
<html></html>,如果用鼠标选择一下,程序就死了。

我不想使用临时文件的方式,因为这样会有大量的临时文件!
而且也不方便数据访问。如何实现不使用navigate2,显示和打印都没有问题?

我做这个程序的目的是打印
我现在有两个效果没有达到,一个是侦测系统的打印队列里面有多少打印任务,
如果任务多,我就暂时不打印。
一个是让用户选择某个打印机,某个纸型,然后记录下来,以后都不用再让用户
来选择。

上面的问题有些我在VB问过,没有人知道,
希望在这里能够碰上好运。但解决问题还是要靠自己,看msdn去了
A浏览器控件教学:使用流加载和保存HTML内容 http://www.csdn.net/develop/read_article.asp?id=18465
Q给一个HTML文件,把文件里的所有链接取出来,怎么做? 
T给你一个HTML文件名比方说,“C:/a.htm”,用什么方法把里面的所有链接取出来?不会要自己打开文件去分析吧?有现成的语句或命令吗?
ASecurity (General) Technical Articles  

Strsafe.h: Safer String Handling in CMichael Howard
Secure Windows Initiative
Microsoft Corporation

June 2002

Summary: Keep your C code secure with strsafe.h functions, a set of safer string handling functions for the C programming language. (3 printed pages)

http://msdn.microsoft.com/downloads/samples/internet/browser/walkall/default.asp
Q请教更改设置的问题 
T在IE中,选择“工具->Internet选项”后,对选项进行设置,点“确定”,IE将自动通知所有的IE窗口,包括CHtmlView窗口,对选项进行更改。
现在想请教的是:在CHtmlView窗口中,怎样才能模拟这种通知机制,让CHtmlView更改字体、颜色等?
A
support.microsoft.com/support/kb/articles/q175/5/13.asp
support.microsoft.com/support/kb/articles/q156/6/93.asp
www.csdn.net/develop/read_article.asp?id=19627
Q如何实现像OutLook一样的收发邮件的功能?
T如何使用VC++实现像OutLook一样的收发邮件的功能,感兴趣而已,希望大家能和我交流交流。
A
用MAPI.DLL就可以
MAPI
Simple MAPI
Simple MAPI is a set of functions and related data structures you can use to add messaging functionality to C, C++, or Visual Basic Windows applications. The Simple MAPI functions are available in C and C++ and Visual Basic versions.

msdn.microsoft.com/library/en-us/mapi/html/_mapi1book_simple_mapi.asp
Q100分求精解:如何非常灵活地控制线条?
T
我在某MDI程序中想实现这样的Drag and Drop功能:
1、在子窗口A中根据多个点坐标Point[n]画一条折线Line;
2、左键点击时判断鼠标坐标是否在此折线上,选中时每个顶点处画一个小方块;
3、可对此折线进行拖放操作:
  a、拖动顶点,则可以改变此折线的形状;
  b、拖动顶点之间的线段,则可以改变整条折线的位置;
  c、特别的是,如果拖放到另一个子窗口B,则在子窗口B中画出此折线,原子窗口A中的折线保持不变。
4、右键点击顶点,弹出一对话框,直接输入此顶点新的坐标,改变此点位置。

我想这应该是类CAD绘图程序的基本功能。
请高手不吝指点,鄙人表示感谢先!
ASee MFC sample Scribble.
Q求一段高级抓图代码
T
越简短越好

我的程序窗口在前面

在不移动或缩小我的窗口前

抓到我的被我窗口遮挡的另一个窗口的图

已知另一个窗口的句柄


A看来过于简单
http://www.fengyuan.com/article/wmprint.html
Q设置菜单或工具栏的选中究竟用什么啊
T我这儿有两个例子一个是非模态,一个是sdi的,都有ON_UPDATE_COMMAND_UI(IDM_CHECK, OnUpdateCheck),但是非模态的那个程序却无法设置菜单选中,都用的 pCmdUI->Enable(m_fCheck);
而且它们的触发机制还不一样,设置断点后,SDI那个老在那儿停,但非模态那个只有点击时才触发的

Ahttp://www.csdn.net/develop/read_article.asp?id=9481
Q互斥量问题,一个服务创建了一个互斥量,另一个普通exe再创建和他同名的互斥量总是返回"拒绝访问"错误, 人人有份!谢谢! 
T两个进程间创建互斥量的问题

一个进程为服务,创建了一个互斥量,在另一个exe里面也创建同名的互斥量,但在另一个exe里面创建互斥量的时候总是返回"拒绝访问"的错误

我把作为服务的这个进程不注册为服务而直接运行,这两个程序就能运行的很正常

我在普通exe里面CreateMutex之前也提升了权限,但还是返回同样的错误
Amsdn.microsoft.com/library/en-us/ dnaskdr/html/drgui49.asp
Q如何实现搜索网页链接的方法~~~~~~~~~求救
T我做了一个专门保存网页的类,下载网页什么的都不是很难,我听说,好像搜索网页链接要对下载的网页的源码进行搜索,我不知道到底要搜索什么,怎么搜索,当然最好还是能调用windows里面自带的网页链接提取,但是哪一个也行,我都不知道怎么下手,请诸位大哥大爷,大婶子,帮帮忙,给我引引路吧,呵呵,谢了
Ahttp://msdn.microsoft.com/downloads/samples/internet/default.asp?url=/downloads/samples/internet/browser/driller/default.asp
Q起一个新的IE窗口时,如何让窗口上的所有菜单和控件都消失??
T我用createprocess和ShellExecuteEx都试过了,都不行,有可能是我的参数没设定对,
有人知道该怎么搞吗,谢谢,就是使IE看起来象一个普通的程序,没有其他东西,谢谢
Ahttp://search.cpan.org/src/GMPASSOS/Wx-ActiveX-0.04/activex/IEHtmlWin.cpp
Q新手首次发问:有谁研究过多重继承下如何实现序列化的功能? 
T在现在的MFC框架下,如果想要实现序列化的功能,必须是继承自CObject,而CObject又不支持多重继承。那么,如果已经运用了多重继承如何才能实现序列化呢?
A
都不看MSDN的么?

MFC Library Reference  
TN016: Using C++ Multiple Inheritance with MFC
Q请问COM对象如何响应事件?
T
我有VC7写程序 (不是从MFC开发的)
那么想调用一个COM组件(这里或说是ACTIVEX也可以)要以下步聚:
1:初始化
2;创建类厂
3:创建一个实例并且得到一个接口
4:使用接口

但问题是比如我想做一个窗口由WEBBROWSER CONTROL来控制, 想要响应其BEFORENAVIGATE的事件, 应该怎么做???
再次说明::不是从MFC的APP WIZARD创的工程, 急盼解决, 谢谢。
AKnowledge Base 
Q246247
HOWTO: Sink HTML Document Events for WebBrowser Host
Q高分求教!!派生状态栏的详细生成方法
T请说明详细的步骤?谢谢.
AKnowledge Base 
Q315603
HOW TO: Create a Class Derived from CControlBar and Its SubClasses in Visual C++ 6.
Q请问,如何做一个象IE中前进后退那种带个下来箭头和下拉菜单的按钮?
TAdding a drop arrow to a toolbar button
http://www.codeproject.com/docking/toolbar_droparrow.asp
Asee MFCIE sample in MSDN
QVC下,如何取得DOM节点的值及其的孩子节点?
Thttp://www.csdn.net/develop/author/netauthor/jiangsheng/files/webbrowserAutomationsrc.zip
Ahttp://www.csdn.net/develop/read_article.asp?id=21702
Q怎么把24位的RGB转成16位的RGB?
T怎么把24位的RGB转成16位的RGB?谢了
Ahttp://blog.joycode.com/jiangsheng/posts/3579.aspx
Q那位大侠救急(SOS)!!
T
找工作人家要我先做一个东西,具体描述如下:
一曲线的数据存储在文件里,可以打开显示,对曲线能进行如下操作:移动,可以用
虚的矩形框似的东西选中其中一段,并且被选中的这段改变颜色,还可以删除、复制
等。那位大侠做过,或者看到过这样的例子告诉我一下!万分感激,以前没做过,并且要的比较急!

A去看MSDN中MFC的scribble示例和drawcli示例
QOCX控件上想添加一个工具栏要怎么做?
TOCX控件上想添加一个工具栏要怎么做?控件不是基于对话框,当然也没有框架。特急,各位哥哥姐姐救命啊!
A
Knowledge Base 
Q166193 SAMPLE: ColorFrm Demonstrates ActiveX Control with Popup Toolbar
The ColorFrm sample demonstrates adding a popup toolbar to an ActiveX Control. ColorFrm uses a CMiniFrameWnd derived class to contain the toolbar that is visible whenever the control is UI Active. When the control is no longer active, the toolbar is hidden and its position is saved.

Q194294 HOWTO: Add Toolbars and Tooltips to ActiveX Controls
An ActiveX control can have a toolbar (a CToolBar class) as its child window. This article shows a way to create such a toolbar and also how to implement tooltips for buttons on the toolbar window.

http://www.kbalertz.com/technology.aspx?tec=278&pNo=22
http://www.kbalertz.com/technology.aspx?tec=274&pNo=17
Q麻烦问题,如何把word菜单融入到应用程序中???
T我看到有高手做的程序可以把word菜单(文件,编辑。。。)融合在自己程序中的mainmenu和popupmenu中,我想在程序中也嵌入word并有这些菜单,特别是将word菜单(文件,编辑。。。等菜单)融合到popupmenu中。
A
Knowledge Base 
Q311765 SAMPLE: Visual C++ ActiveX Control for Hosting Office Documents in Visual Basic or HTML
http://support.microsoft.com/support/kb/articles/q311/7/65.asp
Q[sdk]如何获取鼠标的屏幕位置?
T
想做一个星号密码显示的程序,找到一篇文章,差不多简直都已经实现了,只是用的VC,文章在这里:
http://www.springcome.com/lb5000/cgi-bin/topic.cgi?forum=59&topic=315

看来,问题的关键是取得鼠标的屏幕位置,然后即可使用WindowFromPoint取得窗口句柄,有了句柄一切就都好办了。

可是,我在WM_MOUSEMOVE中,想通过得到LOWORD(lParam)和HIWORD(lParam)来得到鼠标坐标,当鼠标移动到本程序的窗口范围以外时,就不再向本程序发送WM_MOUSEMOVE消息了。

又想用SetCapture,可是,必须在鼠标键被下的情况下,鼠标在本程序以外的位置才会被捕捉,我觉得这样的程序还是不太满意。使用不方便。

如果不用钩子的话,有没有其它的办法呢?

如果没有的话,我看我只有学习HOOK和DLL和怎样把DLL嵌入EXE中了。

因为我很希望发布的程序是个小程序,用SDK,主要就是贪图LCC-Win32生成的EXE文件小。^_^

帮帮忙吧!指点指点吧!
Awww.codeguru.com/ieprogram/SPwdSpy.html
Q用MFC写的COM如何实现包容或聚合?
T如题,能不能给的资料和简单例子?
A
去看MFC的技术文章TN038
MFC的CCmdTarget有专用的函数和宏支持包容和聚合

Q对话框的MENU无法使用COMMAND_UI,如何是好?
T对话框的MENU无法使用COMMAND_UI,如何是好?
A
在对话框中使用ON_UPDATE_COMMAND_UI更新菜单 (jiangsheng翻译)
http://www.csdn.net/develop/read_article.asp?id=9481
Q如何实现屏幕的抓取然后通过网络传输到其他机器显示出来?
T
如何实现屏幕的抓取然后通过网络传输到其他机器显示出来?
我目前的想法是这样的,先在一个机器上抓屏,然后通过winsocket传输到其他机器上,并将抓取的屏幕信息显示出来,如何实现?最好有原代码,或给一个思路.谢谢
Ahttp://blog.joycode.com/jiangsheng/posts/10410.aspx
Q为什么DAO不能打开ACCESS 2000版的数据库?
T
CDaoDatabase m_DB;
try{ m_DB.Open("X://xxxx.mdb")}catch(CDaoException *e){...}

用上面的代码却不能打开ACCESS 2000 的数据库。
而用
try{m_DB.Create("X://xxxx.mdb")}...建一个数据库在ACCESS 2000 里打开时却提示
是旧版本的数据库,这是为什么?有什么方法用DAO可以打开ACCESS 2000的数据库吗?
难道是VC++6.0已不支持DAO以吗?


A
6.3.10.2. Service Pack 3 更正的错误:
下列 MFC 问题已经被更正:

MFC 6.0 可以使用 Microsoft(R) Access 2000 数据库。若要在应用程序中使用此功能,必须使用下例方法启用 DAO 3.6:
在进行任何与数据库相关的调用前,链接 DLL 版的 MFC,并将下列行添至 InitInstance 中:
AfxGetModuleState()->m_dwVersion = 0x0601
在 _MFC_VER 设置为 0x0601 后重新编译 MFC 静态库。
Q急!!急!!怎样在ToolBar中加入下拉组合框啊?jiangsheng和用过BCGControlBar的进来救救小弟!
T我按照帮助上面的作了,可是编译后工具条上新添加的那个按钮并没有被替换为组合框而且显示为不可选状态!!!救救我吧!!
A
参见MSDN中的CTRLBARS 示例
Custom toolbars, dynamic rearrangement of buttons in the toolbar, and adding controls (such as a combo box) to a toolbar. CTRLBARS demonstrates two ways of customizing a toolbar. The first toolbar, the Tool Bar, changes the arrangement of buttons between short (5 buttons) and long (10 buttons). CTRLBARS calls CToolBar::SetButtonInfo for each button to map it to a tile position in the toolbar's bitmap and to a command identification. The second toolbar, the Style Bar, illustrates replacing a toolbar button (or separator) with a control — a combo box in this example. CMainFrame::CreateStyleBar creates a 100-pixel-wide toolbar separator. It then creates the combo box (IDW_COMBO) as a child of the toolbar, and sets the position of the combo box to take the space it just allocated for the separator.
Q救命呀!怎么在CDialogBar上画东西呀?
T
本人在CDialogBar上放了一个Bitmap,现在想在Bitmap上画一些东西,但就是画不上。
我在WM_CREATE的响应函数中,有如下代码,
 CBrush*  pBrush = new CBrush() ;

 CDC* pDC = GetDC();

// pBrush->CreateSolidBrush(m_fontColor);
// pDC->FillRect(m_fontColorRect , pBrush);

 pBrush->CreateSolidBrush(m_backColor);
 pDC->TextOut(0,0,"akldfj");
 pDC->FillRect(m_backColorRect , pBrush);
但是全无效果。不知道如何处理,请指教!
另外,我的CDialogBar还能够Float,不知道是不是应该在什么消息的响应中重绘我画的东西。
谢谢了!
A
看看MSDN里面的DIBLOOK示例吧
DIBLOOK: Illustrates the Use of DIBs and Color Palettes
Click to open or copy the DIBLOOK project files.

The DIBLOOK sample illustrates the use of device-independent bitmaps (DIBs) and the closely related use of color palettes.

DIBLOOK also illustrates a document that has an externally defined file format (in this case, the DIB file format). This is in contrast to an internally defined file format, which is otherwise implied when the framework automatically calls the document's Serialize function to store the contents of the document on disk. DIBLOOK further illustrates use of the Clipboard, CFile, and scroll views.

DIBLOOK is a Multiple Document Interface (MDI) application that lets you view multiple bitmaps at the same time. Use File Open to open an existing device-independent bitmap (.dib) file or device-dependent bitmap (.bmp) file. Alternatively, you can create a new bitmap document by copying a bitmap from another application, such as Paint, using the Clipboard, as follows:

From the other application, copy a bitmap to the Clipboard.


Use the DIBLOOK File New command to create a new bitmap document.


Use the Edit Paste command to copy the bitmap from the Clipboard into the new document.
Although you cannot edit the image in DIBLOOK, you can save the bitmap to another file by using the File Save As command. The bitmap is saved in device-independent bitmap format, even if its original format was device-dependent.


Q怎样在运行时改变控件的颜色
T比如按"黄色"菜单,则控件变为黄色.
Ahttp://www.csdn.net/develop/read_article.asp?id=9603
Q我增加了一个Dialogbar,可是我创建跟他对应的类时,找不到CDialogBar基类,怎么办
T
wizard只有CDialog基类可选

我想用wizard创建一个象
class CMyBar : public CDialogBar
{}
的类,并且与我Insert资源的DialogBar对话框相关联
怎么办

请指教
A
Because ClassWizard does not support deriving a class from CDialogBar, this article shows the steps necessary to create a class from CDialog and then "convert" the class to CDialogBar.



MORE INFORMATION
To start out, create a CDialog class with the child controls you want to use. You can transform the CDialog class into a CDialogBar class using the following nine steps:



Change the base class from CDialog to CDialogBar in the class declaration. Don't forget to also change the base class in BEGIN_MESSAGE_MAP in the .cpp file.


Change the constructor in both the .h and the .cpp files. Also make the change to the DoDataExchange(). Below are three items to change.

Change the following from



      CMyDlgBar (CWnd* pParent = NULL);   // standard constructor

      CMyDlgBar:: CMyDlgBar (CWnd* pParent /*=NULL*/)
         : CDialog(CMyDlgBar::IDD, pParent)
      {
         ...

      void CMyDlgBar::DoDataExchange(CDataExchange* pDX)
      {
         CDialog::DoDataExchange(pDX);
         ...
to the following:

      CMyDlgBar ();   // standard constructor

      CMyDlgBar:: CMyDlgBar ()
      {
         ...

      void CMyDlgBar::DoDataExchange(CDataExchange* pDX)
      {
         CDialogBar::DoDataExchange(pDX);
         ...
The key to the transformation is the conversion of the virtual OnInitDialog() member function to the WM_INITDIALOG message mapped method by changing the OnInitDialog method and by adding the ON_MESSAGE() handler. You may not have an override of OnInitDialog(). If not, add one before proceeding.
Remove "virtual BOOL OnInitDialog();" from the class header and add "afx_msg LONG OnInitDialog ( UINT, LONG );" in its place. For example:

      class CMyDlgBar : public CDialogBar
      {
         ...
      // Implementation
      protected:

         // Generated message map functions
         //{{AFX_MSG(CMyDlgBar)
         virtual BOOL OnInitDialog();                // <-Remove this line.
         //}}AFX_MSG

         afx_msg LONG OnInitDialog ( UINT, LONG );   // <-Add this line.
         DECLARE_MESSAGE_MAP()
      };
Now, in the class implementation section, make the corresponding changes.


Add "ON_MESSAGE(WM_INITDIALOG, OnInitDialog );" to the message map in the .CPP implementation file. For example:

      BEGIN_MESSAGE_MAP(CMyDlgBar, CDialogBar)

         //{{AFX_MSG_MAP(CMyDlgBar)
         ...
         //}}AFX_MSG_MAP
         ON_MESSAGE(WM_INITDIALOG, OnInitDialog )    // <-- Add this line.
      END_MESSAGE_MAP()
Now, convert the virtual OnInitDialog() to the message-mapped OnInitDialog().


Make the OnInitDialog() conversion as follows:

   Change the following:

      BOOL CMyDlgBar::OnInitDialog()
      {
         CDialog::OnInitDialog();   // <-- Replace this line:
            ...
to the following:

      LONG CMyDlgBar::OnInitDialog ( UINT wParam, LONG lParam)
      {
                       // <-- with these lines. -->

         if ( !HandleInitDialog(wParam, lParam) || !UpdateData(FALSE))
         {
            TRACE0("Warning: UpdateData failed during dialog init./n");
            return FALSE;
         }
         ...
The CDialogBar class doesn't have a virtual OnInitDialog(), and therefore calling one does not work. UpdateData is called to subclass or initialize any child controls.


Make sure the dialog box resource styles to the following:
Style: Child
Boarder: None
Visible: Unchecked
At this point, everything has been reconnected to make the transformation from a CDialog class to a CDialogBar class work correctly. Now, create and use it.


Add an instance of the derived CDialogBar to the CframeWnd-derived class (normally called CMainFrame). For example:



      class CMainFrame : public CFrameWnd
      {
          ...
          CMyDlgBar m_myDlgBar;
          ...
      };
Call the create method for the m_myDlgBar variable in the CFrameWnd::OnCreate() method similar to the following:



      int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
      {
         ...
         if (!m_myDlgBar.Create(this, IDD_DLGBAR1, CBRS_LEFT,
            IDD_DLGBAR1))
         {
            TRACE0("Failed to create dialog bar/n");
            return -1;      // fail to create
         }
         ...
      }
Finally, if you want to support dynamic docking and resizing of the CDialogBar, add the following lines to the end of CMainFrame::OnCreate():



      int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
      {
         ...
         m_myDlgBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
            CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
         m_myDlgBar.EnableDocking(CBRS_ALIGN_ANY);
         DockControlBar(&m_myDlgBar);

         return 0;
      }

Q我想从CDialog派生自己的一个对话框类,以后我的程序里的对话框都从这个对话框派生以保持统一的风格,怎么直接继承不行呢?我该如何做?
T 
A
http://www.csdn.net/expert/topic/345/345143.shtm
关于CFormView的派生

Q怎样从DLL中使用类,导入,动态导出。
T不用MFC的话把AFX_EXT_CLASS的定义拷过来用,当然AFX_DLL之类的你得自己定义
A
Export and Import Using AFX_EXT_CLASS
Home |  Overview |  How Do I |  FAQ |  Details |  Sample

Extension DLLs use the macro AFX_EXT_CLASS to export classes; the executables that link to the extension DLL use the macro to import classes. With the AFX_EXT_CLASS macro, the same header file(s) used to build the extension DLL can be used with the executables that link to the DLL.

In the header file for your DLL, add the AFX_EXT_CLASS keyword to the declaration of your class as follows:

class AFX_EXT_CLASS CMyClass : public CDocument
{
// <body of class>
};

This macro is defined by MFC as __declspec(dllexport) when the preprocessor symbols _AFXDLL and _AFXEXT are defined. But the macro is defined as __declspec(dllimport) when _AFXDLL is defined and _AFXEXT is not defined. When defined, the preprocessor symbol _AFXDLL indicates that the shared version of MFC is being used by the target executable (either a DLL or an application). When both _AFXDLL and _AFXEXT are defined, this indicates that the target executable is an extension DLL.

Because AFX_EXT_CLASS is defined as __declspec(dllexport) when exporting from an extension DLL, you can export entire classes without placing the decorated names for all of that class’s symbols in the .DEF file. This method is used by the MFC Advanced Concepts sampleDLLHUSK.

Although you can avoid creating a .DEF file and all the decorated names for the class with this method, creating a .DEF file is more efficient because the names can be exported by ordinal. To use the .DEF file method of exporting, place the following code at the beginning and end of your header file:

#undef AFX_DATA
#define AFX_DATA AFX_EXT_DATA
// <body of your header file>
#undef AFX_DATA
#define AFX_DATA

Caution   Be careful when exporting inline functions, because they can create the possibility of version conflicts. An inline function gets expanded into the application code; therefore, if you later rewrite the function, it does not get updated unless the application itself is recompiled. (Normally, DLL functions can be updated without rebuilding the applications that use them.)

Exporting Individual Members in a Class
Sometimes you may want to export individual members of your class. For example, if you are exporting a CDialog-derived class, you might only need to export the constructor and the DoModal call. You can use AFX_EXT_CLASS on the individual members you need to export.

For example:

   class CExampleDialog : public CDialog
   {
   public:
     AFX_EXT_CLASS CExampleDialog();
     AFX_EXT_CLASS int DoModal();
     ...
     // rest of class definition
     ...
   };

Because you are no longer exporting all members of the class, you may run into an additional problem because of the way that MFC macros work. Several of MFC's helper macros actually declare or define data members. Therefore, these data members must also be exported from your DLL.

For example, the DECLARE_DYNAMIC macro is defined as follows when building an extension DLL:

   #define DECLARE_DYNAMIC(class_name)    protected:      static CRuntimeClass* PASCAL _GetBaseClass();    public:      static AFX_DATA CRuntimeClass class##class_name;      virtual CRuntimeClass* GetRuntimeClass() const;
The line that begins with static AFX_DATA is declaring a static object inside of your class. To export this class correctly and access the run-time information from a client executable, you must export this static object. Because the static object is declared with the modifier AFX_DATA, you only need to define AFX_DATA to be __declspec(dllexport) when building your DLL and define it as __declspec(dllimport) when building your client executable. Because AFX_EXT_CLASS is already defined in this way, you just need to redefine AFX_DATA to be the same as AFX_EXT_CLASS around your class definition.

For example:

   #undef  AFX_DATA
   #define AFX_DATA AFX_EXT_CLASS

   class CExampleView : public CView
   {
      DECLARE_DYNAMIC()
      // ... class definition ...
   };

   #undef  AFX_DATA
   #define AFX_DATA

MFC always uses the AFX_DATA symbol on data items it defines within its macros, so this technique will work for all such scenarios. For example it will work for DECLARE_MESSAGE_MAP.

Note   If you are exporting the entire class rather than selected members of the class, static data members are automatically exported.



Q我做了个ActiveX控件,怎么让它响应PreTranslateMessage函数.
T 
A
in MSDN KB:
PRB: TranslateAccelerator() Not Called for ActiveX Controls
ID: Q183167
PRB: MFC ActiveX Control Ignores ARROW Keys on VB Container
ID: Q180402
PRB: TAB Behavior When Using MFC Subclassed Control on VB Form
ID: Q214476
PRB: KeyPress Problem When Using MFC Control on MDI Child Form
ID: Q197504
PRB: MFC ActiveX Control in IE Doesn't Detect Keystrokes
ID: Q168777

HOWTO: Add Toolbars and Tooltips to ActiveX Controls
ID: Q194294
Q急急急!!!!1一个关于CDialogBar的问题
T
今本人欲在一CDialogBar上创建一个CTreeCtrl,并在一CStatic对象上画图.
我把CTreeCtrl的初始化代码应当放在对应的CDialogbar对象的什么地方??
(我放在initdialog中好像不行),画图函数在OnPaint()中,但也没有画出来
我怀疑是不是我的CDialogBar是从CDialog派生的缘故(我是象通常普通对话
框一样利用ClassWizard提示给CDialogBar对应的对话框定义了一个类)

这一切到底是怎么回事??到底怎么初始化CDialogBar,望各位高手指点,

十万火急阿!!!!!!!!~~~~~~~~~~~~~~~~~~~~~`
A
HOWTO: How to Initialize Child Controls in a Derived CDialogBar
ID: Q185672


--------------------------------------------------------------------------------
The information in this article applies to:

The Microsoft Foundation Classes (MFC), used with:
Microsoft Visual C++, 32-bit Editions, versions 5.0, 6.0
Qjiangsheng(蒋晟)请回答一个问题,谢谢(其他高手请帮忙)
T
我星期天问您一个问题,关于在statusbar上面创建progress问题,而且就是按照
您的方法作的,结果还是显示不出来,经过GetItemRect(),之后得到的rc的各个参数如下
:rc.top=2;
rc.bottom=rc.left=rc.right=0;
这根本就不可能阿,请问这是怎么一回事?谢谢
是不是我的vc由问题阿
这是6.0企业版
A去MSDN KB看看这篇文章
HOWTO: Create a Progress Bar on the Status Bar
ID: Q142202
Q我动态生成了一个CDialogBar对象,怎样添加CToolTipCtrl???马上给分,现在不够,以后补上!!!!
T
生成代码如下::
if (!m_wndDialogBar.Create(this, IDD_DIALOGBAR,CBRS_BOTTOM,NULL))
    {
  RACE0("Failed to create dialog bar m_wndDialogBar/n");
   return -1; / fail to create
    }

怎样添加,工具提示。。谢谢
A
自己Create&AddTool
再不行就把Dialogbar当CWnd,处理TTN_NEEDTEXT

http://www.codeguru.com/controls/index.shtml
Tooltip controls那一节
Q真诚请教:做一个IE浏览器,想做文件菜单下的'另存为...'功能,不知道如何实现.
T
不知道如何读取浏览器中的页面的内容并保存.
我会尽我所有给很多分,说到做到

A
用Document的All集合或其他集合遍历。
参见
http://www.csdn.net/expert/topic/375/375478.shtm
http://www.csdn.net/expert/topic/351/351580.shtm
http://www.csdn.net/expert/topic/360/360785.shtm
Q超高难度:VC通过ODBC访问SQL数据库,使用CListCtrl虚表显示,速度N慢!!如何解决??
T

VC通过ODBC访问SQL数据库,使用CListCtrl虚表显示,速度N慢!!如何解决??
我分别使用ODBC、DAO方式访问SQL SERVER 7.0数据库服务器,在显示一个只有4000多
条记录的表时,速度太慢了,界面有明显的停顿!!!

通过比较ODBC 和 DAO,我发现使用DAO访问比使用ODBC访问要快!!是不是很意外!!
A虚列表有缓存机制的,你可以在显示前缓存当前显示的数据。

http://msdn.microsoft.com/library/en-us/shellcc/platform/CommCtls/ListView/ListView_Using.asp?frame=true#Using_Virtual_ListView_Controls
Q关于dialog和控件回车键消息处理的小问题
T
我在一个dialog上放了一个CTreeCtrl(设置为可编辑),在一个tree item上编辑后想回车确定,但是这个回车被dialog的OnOK()处理了,如果去掉这个OnOK(),dialog就直接退出了。现在我想做的是:按下回车键时,
1、如果当前正在编辑tree item,能得到TVN_ENDLABELEDIT通知消息
2、否则才调用OnOK()。

另:如果从CTreeCtrl派生一个子类,怎样才能对话框资源编辑里画的那个CTreeCtrl直接联系起来?
ABUG: ESC/ENTER Keys Do Not Work When Editing CTreeCtrl Labels
ID: Q167960


Qhow to textout with line spacing in a given rect?
T
1可选择非等宽字体
2可选水平和垂直对齐方式(左中右,上中下对齐)
3可选多行/单行输出方式
4可自定义行距
5可自动调整字体大小以适应目标矩形
A
解决了
方案在http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnprogwin/html/ch17-05.asp
Q属性页SetActivePage问题
T
楼上《怎么在启动属性表时把每个属性页激活一遍???》提到用SetActivePage可以在属性页的OnInitDialog函数中激活每一页,让每一页都能够初始化。

我创建的是一个非模态属性页,在CPropertySheet派生类的OnInitDialog中使用SetActivePage并不起作用,不知道是怎么原因,请教!
BOOL CMySheet::OnInitDialog()
{
 BOOL bResult = CPropertySheet::OnInitDialog();

 for (int i = GetPageCount() - 1; i >= 0; i--)
  SetActivePage(i);

 SetIcon(m_hIcon, TRUE);  // Set big icon
 SetIcon(m_hIcon, FALSE);  // Set small icon

 return bResult;
}
请jiangsheng(蒋晟)、funone()多多关注!
A
Return Value
Nonzero if the property sheet is activated successfully; otherwise 0.
??

Example

// The code fragment below sets the last active page (i.e. the
// active page when the propertysheet was closed) to be the first
// visible page when the propertysheet is shown. The last active
// page was saved in m_LastActivePage, (a member variable of
// CDocument-derived class) when OK was selected from the
// propertysheet. CMyPropertySheet is a CPropertySheet-derived class.
BOOL CMyPropertySheet::OnInitDialog()
{
   BOOL bResult = CPropertySheet::OnInitDialog();

   CFrameWnd* frame = (CFrameWnd*) AfxGetMainWnd();
   CPSheetDoc* doc = (CPSheetDoc*) frame->GetActiveDocument();
   SetActivePage(doc->m_LastActivePage);
   return bResult;
}

BOOL CMyPropertySheet::OnCommand(WPARAM wParam, LPARAM lParam)
{
   if (LOWORD(wParam) == IDOK)
   {
      CFrameWnd* frame = (CFrameWnd*) AfxGetMainWnd();
      CPSheetDoc* doc = (CPSheetDoc*) frame->GetActiveDocument();
      doc->m_LastActivePage = GetPageIndex(GetActivePage());
         // or GetActiveIndex()
   }

   return CPropertySheet::OnCommand(wParam, lParam);
}


Example

// This code fragment shows how to create a modeless property sheet
// dialog in a command message handler (OnModelessPropertySheet())
// of a CView-derived class.

void CMyView::OnModelessPropertySheet()
{
   // Declare a CPropertySheet object.  m_dlgPropertySheet is a data
   // member of type CPropertySheet in CView-derived class.
   m_dlgPropertySheet = new CPropertySheet("Simple PropertySheet");
   ASSERT(m_dlgPropertySheet);

   // Add two pages to the CPropertySheet object.  Both m_stylePage and
   // m_colorPage are data members of type CPropertyPage-derived classes
   // in CView-derived class.
   m_stylePage = new CStylePage;
   m_colorPage = new CColorPage;
   m_dlgPropertySheet->AddPage(m_stylePage);
   m_dlgPropertySheet->AddPage(m_colorPage);

   // Create a modeless CPropertySheet dialog.
   m_dlgPropertySheet->Create();
}

// The code fragment below shows how to destroy the C++ objects for
// propertysheet and propertypage in the destructor of CView-derived
// class.
// NOTE:  DestroyWindow() is called in CPropertySheet::OnClose() so
// you do not need to call it here.  Property pages are children
// of the CPropertySheet, they will be destroyed by their parents.

CMyView::~CMyView()
{
   if (m_dlgPropertySheet)
   {
      delete m_stylePage;
      delete m_colorPage;
      delete m_dlgPropertySheet;
   }
}

CPropertySheet


不是BUG
MFC内部使用的消息就在这个范围,看看你定义的消息是否和MFC冲突了。:(


Q如何实现象Foxmail那样嵌入IE浏览邮件
T
我现在把收到的邮件存成.eml, 然后用Outlook 打开。
但是,我希望在我自己的窗口显示邮件内容,而不是Outlook窗口。
象 Foxmail 那样
Ahttp://msdn.microsoft.com/workshop/browser/prog_browser_node_entry.asp
QWuxuehui(Exception)和jiangsheng(蒋晟)请进(关于MSHTML Editor)
T
首先,谢谢你们的回答(如何实现象Foxmail那样嵌入IE浏览邮件)。
现在,我还要求能够编辑HTML。经过查找在MSDN上找到以下文章
  Activating the MSHTML Editor
不过看了以后还是不太明白。
CHtmlView->GetHtmlDocument 应该返回 pointer to IHTMLDocuemnt2 .
但是,接下来如何用就不太清楚了。
不知道那里有Sample.

还有 如果写 IHTMLDocuemnt2 p = CMyHtmlView->GetHtmlDocument()
编译不会通过。
这个问题解决了。不过,如何取得修改后的内容呢?
HTML和插入的Picture
Ahttp://msdn.microsoft.com/library/en-us/dnmind99/html/cutting1199.asp
QDHTML Edit控件可以从内存中读文件吗?
T看msdn好像有LoadURL和LoadDocument两个函数,都不能从内存的一个buffer载入文件,JiangCheng,您知道吗???请指教。
A
晕~
连我的名字都敲错……
最简单的办法是写到临时文件
用COM的办法比较麻烦,去看
http://www.csdn.net/expert/topic/481/481701.shtm
Q如何控制Explorer,各位帮着看看
T
1.已知C:/xxx/xxx/xxx.doc,如何叫explorer打开这个文件夹,并同时选中这个文件(这是关键),如同快捷方式中的查找目标.

2.已知C:/xxx/xxx/xxx.doc,如何叫explorer打开这个文件的属性对话框(像VC的dependency工具那样)

我想以上两点都可以应该可以用Explorer的命令行参数实现,不过不知道具体参数是什?

而且气人的是Win2000死命不让我替换explorer.exe,该死的文件保护


ACommand-Line Switches for Windows Explorer

Q130510
Q怎样扩展系统的打开对话框?
T
我是用VB6在编,估计在VB区问的话没有人回答,只有跑到VC区问了。

我是用API函数 GetOpenFileName 来实现打开对话框的,它的OPENFILENAME型参数的lpfnHook元素已设置好函数地址。

现在的问题是:怎样知道 在打开对话框中的列表框选中的文件的文件名(包括路径)?

我发现在打开对话框中的列表框选择时,我在lpfnHook设置的函数会接受到一个值为 0x4E 的消息,同时 lParam 也有值,我估计它包含了文件名的信息,但我不知道如何将它转化为文件名字符串?


我不懂VC,请详细讲解一下方法,最好帮我改成VB代码。

A
看代码算了

Using the Common Dialogs Under Windows 95
Nancy Winnick Cluts
Microsoft Developer Network Technology Group

Created: October 25, 1994

Click to open or copy the files in the CMNDLG32 sample application for this technical article.

also in MSDN.
Q请问:有没有人用api做过打印预览和打印?请高手指点!
T越详细越好,有代码更佳,谢了先!
A
HOWTO: Print a Document

Q139652


--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Win32 Application Programming Interface (API), used with:
Microsoft Windows NT Server versions 3.5, 3.51
Microsoft Windows NT Workstation versions 3.5, 3.51
Microsoft Windows 95
Microsoft Windows CE Services version 2.0
Q俺要做分析报表,需要根据数据生成一些图形文件(*.gif)在web上显示,比如柱状图(类似Office的),请问如何实现。
T哪里有这方面的资料,最好有源代码啦。
Ahttp://www.codeproject.com/gdi/webimagedc.asp
QDLL中的对话框输出问题
T
某DLL中有一对话框MyDialog,封一类CMyClass,此类中有一方法MyFunc,在此方法中调用MyDilog.DoModal(),导出CMyClass.在静态链接时,调用MyFunc,在加载对话框资源时总是出错,具体是在CMyDialog::DoDataExchange(CDataExchange* pDX)中,重试是在
HWND CDataExchange::PrepareCtrl(int nIDC)
{
 ASSERT(nIDC != 0);
 ASSERT(nIDC != -1); // not allowed
 HWND hWndCtrl;
 m_pDlgWnd->GetDlgItem(nIDC, &hWndCtrl);
 if (hWndCtrl == NULL)
 {
  TRACE1("Error: no data exchange control with ID 0x%04X./n", nIDC);
  ASSERT(FALSE);
  AfxThrowNotSupportedException();
 }
 m_hWndLastControl = hWndCtrl;
 m_bEditLastControl = FALSE; // not an edit item by default
 ASSERT(hWndCtrl != NULL);   // never return NULL handle
 return hWndCtrl;
}
中的m_pDlgWnd->GetDlgItem(nIDC, &hWndCtrl)执行后hWndCtrl为空,请问该如何解决?还有就是加载DLL中的对话框中的资源时该如何正确操作?

A去看MFC示例DLLHUSK: Dynamically Links the MFC Library
Q如何在html文件中修改xml数据岛中的数据的问题(参与有分)
T
请教各位大侠:
我象在IE控件中对一个html文件中的嵌入的xml数据岛中的数据进行修改,现在我的做法是用get_outerHTML提取出包含有该部分数据的文本。然后用DOM方法对进行解析并修改数据,但我无法将修改后的XML格式的文本送回到html文件中,请各位大侠帮忙给点建议。或者有更好的方法请赐教。
多谢了。
A
SAMPLE: DLLList.exe Lists DLL Details with Binary Element Behavior

Q271239


--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Internet Explorer (Programming) version 5.5

--------------------------------------------------------------------------------

QVC中,有目录对话框吗??如何用?
T各位兄弟:我想用VC实现,Delphi下的目路对话框,输入目录,如何做???
A
怎么没一个释放获得的pidl的?
The calling application is responsible for freeing the returned PIDL with the Shell allocator's IMalloc::Free method. To retrieve a handle to the Shell allocator's IMalloc interface, call SHGetMalloc. See The Shell Namespace for further discussion of the Shell allocator and PIDLs. LPMALLOC pMalloc = NULL;
How do I display a Choose Directory dialog, instead of a Choose File dialog?

/* Works only if we're Windows 95 capable */
if (afxData.bWin4)
{
    LPMALLOC pMalloc;
    /* Gets the Shell's default allocator */
    if (::SHGetMalloc(&pMalloc) == NOERROR)
    {
        BROWSEINFO bi;
        char pszBuffer[MAX_PATH];
        LPITEMIDLIST pidl;
        // Get help on BROWSEINFO struct - it's got all the bit settings.
        bi.hwndOwner = GetSafeHwnd();
        bi.pidlRoot = NULL;
        bi.pszDisplayName = pszBuffer;
        bi.lpszTitle = _T("Select a Starting Directory");
        bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
        bi.lpfn = NULL;
        bi.lParam = 0;
        // This next call issues the dialog box.
        if ((pidl = ::SHBrowseForFolder(&bi)) != NULL)
        {
            if (::SHGetPathFromIDList(pidl, pszBuffer))
            {
            // At this point pszBuffer contains the selected path */.
                DoingSomethingUseful(pszBuffer);
            }
            // Free the PIDL allocated by SHBrowseForFolder.
            pMalloc->Free(pidl);
        }
        // Release the shell's allocator.
        pMalloc->Release();
    }
}


Q如何将ListCtrl里的滚动条做成透明式样,或者改变滚动条的颜色?
T做了一个ListCtrl类,想把滚动条的颜色做成和窗口颜色一样的,透明效果。怎样做呢?
A
CWnd::GetScrollBarCtrl 
virtual CScrollBar* GetScrollBarCtrl( int nBar ) const;
subclass it and do some drawing with it

http://www.codeproject.com/useritems/colorizedscrolls.asp

要求这么高啊
要是你要这种效果的话
http://www.codeproject.com/dialog/CoolScroll/coolscroll02.gif
可以去看
http://www.codeproject.com/dialog/coolscroll.asp

http://people.freenet.de/markus.loibl/Scrolltestcode.zip

http://www.codeproject.com/dialog/coolscroll.asp
不光要看文章,还要看作者/其他读者做了那些改进

QCListCtrl的使用????
T我在Dialog上放了一个listctrl控件,选中可编辑属性,可是只有每一行的第一列可以编辑,不只何故?清高收指点.
Ahttp://www.codeguru.com/listview/edit_subitems.shtml
Q非模态的属性页该怎么做!望各位大侠不吝赐教!
T
建立了两个属性页CPropPage1和CPropPage1,还有CPropSheet(:CPropertySheet)
按着几位大侠以前的帖子(都是模态的)做下去,却始终没有成功,痛苦难耐!!!!

还有CPropSheet有两个构造函数:
CPropSheet::CPropSheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
 :CPropertySheet(nIDCaption, pParentWnd, iSelectPage)

CPropSheet::CPropSheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
 :CPropertySheet(pszCaption, pParentWnd, iSelectPage)
有什么不同也请解释一下,必定重谢!!

请jiangsheng(蒋晟)、LorDong (漏洞)多多关注!
Asee sample SNAPVW: Using Property Pages in a Form View Application
in MSDN
Q关于BMP文件的问题
T各位高手,有谁会编一个显示BMP文件的程序(即通过BMP文件内容一个像素一个象素的显示)。如果有源代码一定高分相送,谢谢!!!
Ahttp://www.csdn.net/Develop/article/12/12866.shtm
Q如何动态生成弹出菜单(菜单项的个数和内容都不一定),以及怎么响应消息?
T
程序中会根据数据库中的记录来动态的生成弹出菜单,我知道怎么做,但是问题是怎么响应点击菜单的消息
因为菜单的项数不一定
所以不能用On_Command_extent(....)来做,请问怎么做?
在defWindowProc()里可以做吗?

Ahttp://www.csdn.net/Develop/read_article.asp?id=9413
Q在dll中能不能产生事件呢?
T
我使用vc++的atl com wizard做了一个dll,可是,我不知道如何在dll中产生事件,请高人指点一二。
在activex control中可以通过fireevent来实现,在dll中该使用什么手段呢?
Ahttp://msdn.microsoft.com/msdnmag/issues/0400/mfc/TOC.asp
Q不惜重金,请教打印高手
T
各位大虾:
    我在做打印程序时遇到了一个问题,代码如下:
出现的问题是运行到标识的一步时,弹出出错对话框三个按钮的那种,终止,重试,取消
LRESULT CShenjianView::OnMyPrint(WPARAM a,LPARAM b)
{
    CDC dc;
 PRINTDLG pd;
    LPDEVMODE lpDevMode;
    CPrintDialog printDlg(FALSE);
    if(AfxGetApp()->GetPrinterDeviceDefaults(&pd))
    {
 lpDevMode=(LPDEVMODE)pd.hDevMode;
    lpDevMode->dmPaperLength=1500;
 lpDevMode->dmPaperWidth=1100;
 }   
   printDlg.m_pd.hDevMode=pd.hDevMode;
   dc.Attach(printDlg.GetPrinterDC());         
   dc.m_bPrinting = TRUE;
   CString strTitle;                          
    strTitle="您当前打印的是生检质量";
    DOCINFO di;                               
    ::ZeroMemory (&di, sizeof (DOCINFO));
    di.cbSize = sizeof (DOCINFO);
    di.lpszDocName = strTitle;
    BOOL bPrintingOK = dc.StartDoc(&di); //运行到这一步时有问题    
    CPrintInfo Info;
    OnBeginPrinting(&dc, &Info);      
    for (UINT page = Info.GetMinPage();
         page <= Info.GetMaxPage() && bPrintingOK;
         page++)
    {
        dc.StartPage();                 
        Info.m_nCurPage = page;
  int sty;  
        sty=Stpoint(m_pSet);
     PrintBiaotou(&dc,sty);
        bPrintingOK = (dc.EndPage() > 0);     
   }
    OnEndPrinting(&dc, &Info);                 
    if (bPrintingOK)
        dc.EndDoc();                          
    else

        dc.AbortDoc();                        

    dc.Detach();
 return 1;
}
A
HOWTO: Implement a View-Based Default Printer in Microsoft Foundation Classes

Q193103


--------------------------------------------------------------------------------
The information in this article applies to:

The Microsoft Foundation Classes (MFC), used with:
Microsoft Visual C++, 32-bit Editions, versions 5.0, 6.0

--------------------------------------------------------------------------------
Q同样一套代码,我想在编译时指定我的资源是中文编译出来的程序就是中文版的,如果指定资源是英文,编译出来的就是英文版。主要表现在菜单
T我很急,希望大家能帮忙
AHOWTO: Create Localized Resource DLLs for MFC Application

Q198846


--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Visual Studio 97
Microsoft Visual C++, 32-bit Professional Edition, version 5.0
Microsoft Visual Basic Enterprise Edition for Windows, version 5.0

http://www.csdn.net/expert/topic/620/620869.xml
Q当动态链接库里的对话框使用和主程序(.exe)文件中同样的对话框 ID 时,会装入主程序中的对话框资源!
T当动态链接库里的对话框使用和主程序(.exe)文件中同样的对话框 ID 时,会出现大问题!会装入主程序中的对话框资源!
A
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnmag01/html/c0101.asp
Q
I've got a library that has some dialogs (and thus some re-source IDs). Now, using this library within a main app, the resource IDs collide with resource IDs in the app. The result is that instead of showing the library's dialog, the app dialog pops up. How can I avoid this? Do I have to set the resource IDs from the library manually?

Hans Zwahlen

A
Alas, this is one of those problems that doesn't have any really satisfying solution, only a few intelligent workarounds. The fundamental problem is that every resource in Windows must belong to some module (EXE or DLL), and resources of a given type within a module can't have the same name or ID. With DLLs, this isn't a problem because your DLL has its very own HINSTANCE handle that distinguishes it from the app; but in a statically linked library, all resources must cohabit the same EXE file like a big extended family. And, as with families, there's always a potential for conflict.
………………
Q基于对话框的程序是如何进入消息循环的?对VC运作机制有研究的请进!!!
T
基于对话框的程序是如何进入消息循环的?
BOOL CComboBoxApp::InitInstance()
{
 .....
 this->m_nCmdShow = SW_HIDE;
 CComboBoxDlg dlg;
 m_pMainWnd = &dlg;
 int nResponse = dlg.DoModal();
///
 在这里程序应该是不能向下执行的,但是,程序是如何进入RUN函数的呢?
///
 if (nResponse == IDOK)
 {
  // TODO: Place code here to handle when the dialog is
  //  dismissed with OK
 }
 else if (nResponse == IDCANCEL)
 {
  // TODO: Place code here to handle when the dialog is
  //  dismissed with Cancel
 }
 ......
 
}

谢谢.
A
CDialog创建的对话框实际上是伪模态的
具体资料可以看这里
http://www.csdn.net/Develop/read_article.asp?id=9490
Q如何在工具栏上放控件?
T像VC,VB开发环境里的那些属性工具栏?我想在上面放上表格,以控制View里的对象的属性,急,请指教?!!!谢谢
A
MSDN/VC/MFC/Samples
CTRLBARS: Illustrates Custom Control Bars

Custom toolbars, dynamic rearrangement of buttons in the toolbar, and adding controls (such as a combo box) to a toolbar. CTRLBARS demonstrates two ways of customizing a toolbar. The first toolbar, the Tool Bar, changes the arrangement of buttons between short (5 buttons) and long (10 buttons).

Q如何获得当前正被激活的IE浏览器
T使用IWEBBROWSER2时如何在已经打开的很多IE窗口中得到正在被激活的窗口?
A>pdoc2->QueryService(IID_IWebBrowserApp,IID_IWebBrowser2, (void**)&pweb);

你要获得顶层的document的IWebBrowser2才行
http://www.csdn.net/Expert/TopicView1.asp?id=709395
QAfxMessageBox("该文件没有关联程序执行操作。请在控制面板的文件夹选项中创建关联程序。");
T


我修改.gif文件的关联程序,遂将
HKEY_CLASSES_ROOT/giffile/shell/open/command

的键值改成了我的执行程序的路径:

"d:/TouchGif/TouchGif.exe %1"

之后我打开*.gif文件却打不开TouchGif程序,连InitInstance都没调用,可见关联根本没有效果。


之后我用windows的“打开方式”修改关联,结果打开gif时候弹出对话框说:

   该文件没有关联程序执行操作。请在控制面板的文件夹选项中创建关联程序。

随即打开失败。

-----------------------------

我的程序是个SDI程序,没有Document支持。所以,使用
EnableShellOpen();
RegisterShellFileTypes(TRUE);
不行。

——————————————————————

我如何让关联有效?用我的程序打开GIF????
A
Knowledge Base Articles  

SAMPLE: FileAsso.exe Demonstrates How to Use File Associations
Q122787


--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Win32 Software Development Kit (SDK)
Microsoft Windows Software Development Kit (SDK) 3.1
Qdao对access数据库进行查询的示例程序
Tdao对access数据库进行查询的示例程序
A
DAOVIEW: Database Browser
Click to open or copy the DAOVIEW project files.

DAOVIEW illustrates the use of many new features in MFC 4.0 to implement a moderately sophisticated database browser. It relies heavily on the new DAO classes to communicate with the Microsoft Jet database engine. It allows the user to view the database schema and data. It can also be used to create or modify stored SQL queries.

QIHTMLDocument2的问题,为什么得到文档对象指针会失败。
T
IHTMLDocument2* GetDocInterface(HWND hWnd)
{
 // 我们需要显示地装载OLEACC.DLL,这样我们才知道有没有安装MSAA
 HINSTANCE hInst = ::LoadLibrary( _T("OLEACC.DLL") );
 IHTMLDocument2* pDoc2=NULL;
 if ( hInst != NULL ){
  if ( hWnd != NULL ){
   CComPtr<IHTMLDocument> spDoc=NULL;
   LRESULT lRes;

   UINT nMsg = ::RegisterWindowMessage( _T("WM_HTML_GETOBJECT") );
   ::SendMessageTimeout( hWnd, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes );

   LPFNOBJECTFROMLRESULT pfObjectFromLresult = (LPFNOBJECTFROMLRESULT)::GetProcAddress( hInst, _T("ObjectFromLresult") );
   if ( pfObjectFromLresult != NULL ){
    HRESULT hr;
    hr=pfObjectFromLresult(lRes,IID_IHTMLDocument,0,(void**)&spDoc);
    if ( SUCCEEDED(hr) ){
     CComPtr<IDispatch> spDisp;
     CComQIPtr<IHTMLWindow2> spWin;
     spDoc->get_Script( &spDisp );
     spWin = spDisp;
     spWin->get_document( &pDoc2 );
    }
   }
  }
  ::FreeLibrary(hInst);
 }
 else{//如果没有安装MSAA
  AfxMessageBox(_T("请您安装Microsoft Active Accessibility"));
 }
 return pDoc2;
}
hwnd为正确的窗口句柄,当程序执行到hr=pfObjectFromLresult(lRes,IID_IHTMLDocument,0,(void**)&spDoc);这一句,lRes值为0,hr为一个负数。有什么原因会导致这种错误产生。
A
看文档
比如这样
IMAPISession::Advise
The IMAPISession::Advise method registers to receive notification of specified events affecting the session.
……
Return Values
S_OK
The registration was successful.
MAPI_E_INVALID_ENTRYID
The entry identifier pointed to by lpEntryID does not represent a valid entry identifier.
MAPI_E_NO_SUPPORT
The service provider responsible for the entry identifier pointed to by lpEntryID either does not support the type of events specified in the ulEventMask parameter or does not support notification.
MAPI_E_UNKNOWN_ENTRYID
The entry identifier pointed to by lpEntryID cannot be handled by any of the service providers in the profile.

微软文档
ObjectFromLresult
The ObjectFromLresult function retrieves a requested interface pointer for an accessible object based on a previously generated object reference.

This function is designed for internal use by Active Accessibility and is documented for informational purposes only. Neither clients nor servers should call this function.

STDAPI ObjectFromLresult(
  LRESULT lResult,
  REFIID riid,
  WPARAM wParam,
  void** ppvObject
);
Parameters
lResult
[in] A 32-bit value returned by a previous successful call to the LresultFromObject function.
riid
[in] Reference identifier of the interface to be retrieved. This is IID_IAccessible.
wParam
[in] Additional information is provided in the associated wParam parameter of the WM_GETOBJECT message.
ppvObject
[out] Receives the address of the interface pointer to return to the client.
Return Values
If successful, returns S_OK.

If not successful, returns one of the following standard COM error codes.

Error Description
E_INVALIDARG  One or more arguments are invalid. This occurs when the lResult parameter specified is not a value obtained by a call to LresultFromObject, or when lResult is a value used on a previous call to ObjectFromLresult. 
E_NOINTERFACE  The object does not support the interface specified by the riid parameter. 
E_UNEXPECTED  An unexpected error occurred. 


Requirements
  Windows NT/2000/XP: Included in Windows XP and Windows .NET Server.
  Windows 95/98/Me: Unsupported.
  Redistributable: Requires Active Accessibility 2.0 RDK on Windows NT 4.0 SP6 and Windows 98.
  Header: Declared in Oleacc.h.
  Library: Use Oleacc.lib.




Qjiangsheng我在程序中host住了WebBrowser,但网页中有类似window.close()的脚本.... 
T
我在程序中host住了WebBrowser,但网页中有类似window.close()的脚本执行时,
我的程序不能够像IE那样关闭,而是一片空白,我怎么解决这个问题。

我同时查了一个msdn,发现在IE5.5中的Webbrowser2有一个windowcloseing事件可以
办到,但我想到ie5.0版本中就做到类似的功能,是不是也可以。如果不可能,那么ie5.0里面是怎么做的。

  谢谢。
A
RESOLUTION
In Internet Explorer 5.5, the WebBrowser control's default source interface, DWebBrowserEvents2, exposes a new event called WindowClosing. You can sink DWebBrowserEvents2 and set the Cancel parameter of the event to TRUE to prevent the close from occurring, or you can close the host windows.

In Internet Explorer 5.01 and earlier, the WM_PARENTNOTIFY message is sent to the parent of a child window when the child window is created or destroyed, or when the user clicks a mouse button while the cursor is over the child window. Thus, the hosting container of the WebBrowser control can watch for a WM_DESTROY notification message. If LOWORD of the wParam field of the WM_PARENTNOTIFY message is set to WM_DESTROY, the HIWORD of wParam contains the child window identifier, and the lParam field contains the hWnd of the child control. If the hWnd in lParam matches the hWnd of the WebBrowser control, you can determine that the WebBrowser control is being destroyed. You can then take the appropriate action, which typically means to close the child window for multiple-document interface (MDI) applications and quit the applications for single-document interface (SDI) applications.
When the script calls window.close, the WebBrowser control destroys its window, but the control is still in its "running" state (that is, the control is not completely destroyed). The WebBrowser control does not inform its container on deactivation through the IOleInPlaceSite::OnUIDeactivate method.

Handling the WM_PARENTNOTIFY message
Add a handler prototype for the OnParentNotify function to the CHtmlView-derived class:



 afx_msg void OnParentNotify( UINT message, LPARAM lParam ); 
Add a WM_PARENTNOTIFY handler to the message map:



BEGIN_MESSAGE_MAP(CQ253219View, CHtmlView)
.
.
 ON_WM_PARENTNOTIFY()
.
.
END_MESSAGE_MAP()
Implement the WM_PARENTNOTIFY event handler. For example:



void CQ253219View::OnParentNotify(UINT message, LPARAM lParam ) 
{ 
 if ((LOWORD(message) == WM_DESTROY) && ((HWND)lParam == m_wndBrowser)) 
 { 
  // Close the parent frame window.
  GetParentFrame()->PostMessage(WM_CLOSE, 0, 0);
 } 
 else  
  CHtmlView::OnParentNotify(message, lParam );
}


Q又一个Debug/release问题?
T
最近给朋友做界面时碰到的。界面是这样的:
SDI , 窗口被静态分割成左右两部分,右边用作试图切换。左边上部是个TabCtrl,下边是几个按钮。左边的TabCtrl是竖向排列的,所以我专门做了个基于CTabCtrl的类CKxTabCtrl.该类说起来比较简单,初始化时new几个对话框(Child,None board),然后把对话框移到TabCtrl的客户区.
问题出在:我重载了CTabCtrl的鼠标双击的消息映射函数,在该函数中向左边视图发了个消息,希望双击TabCtrl的ItemHead时,右边的视图能切换到相应的视图。
左边视图的指针是CKxTabCtrl初始化时传到CKxTabCtrl的,消息WM_MY_TABDBCLICK。想来不会有什么问题。m_pView->PostMessage(WM_MY_TANDBCLICK,(WPARAM)GetCurSel());
然后在左边视图类中处理消息,根据wParam的值进行切换。
这一切在Debug下运行得很好,然而一到release下,只要双击TabCtrl的ItemHead,视图切换过去后不到1秒就出错!
我检查了该类的GetDocument(),和Document类的变量。没什么异常,该初始化的都做到位了。
我特意在左边加了一排按钮来尝试切换,release非常正常!
最后,我把m_pView->PostMessage(WM_MY_TANDBCLICK,(WPARAM)GetCurSel());屏蔽掉,release正常!但不能切换了.
我尝试减少PostMessage的参数,没用!
我干脆让m_pView->PostMessage(WM_MY_TANDBCLICK,(WPARAM)GetCurSel());有效,但左边视图不处理该消息。正常!

这条路就走到这里了。双击切换的功能最后我在左边视图内通过处理CTabCtrl的Onclick(),配合定时器做出来了。
但为什么我在release下就不能像debug下那么发消息?


上面的程序在Win2k下VC++6.0(No service pack)完成。以上提到的函数可能有误,请相信我的程序里写的是正确的。

欢迎大家讨论。如果认为我某些地方没讲清楚,请跟贴,或者直接发到ahphone@263.net.
这个油箱已经转为收费油箱了。



AKnowledge Base Articles  

PRB: Incorrect Function Signatures May Cause Problems in Release
Q195032
Q请问如何把CPropertySheet加到CMainFrame的右面的视图中
T
我先告诉你CMainFrame长的什么样

CMainFrame右面本来是继承直CListView的一个View
CMainFrame左面是继承自CTreeView的CLeftView

我想把CPropertySheet显示在右面。我的代码不行
 CDlgProps* dlgProp=new CDlgProps(_T("abc"),this->GetRightPane());
 dlgProp->Create(this->GetRightPane(),WS_CHILD | WS_VISIBLE,0);
 CDlgPropMail* dlgPropMail=new CDlgPropMail();
 dlgProp->AddPage(dlgPropMail);
 dlgProp->ShowWindow(SW_SHOW);
运行没有错误,但是看不见东西,就是看不见

AHOWTO: Use CPropertySheet as a Child of CSplitterWnd

Q262024
Q请问jiangsheng(蒋晟.Net) 什么是T20LE ole2t ?
T请问jiangsheng(蒋晟.Net) 什么是T20LE ole2t ?
A
问这么多次干什么?
去搜MSDN
HOWTO: Convert from ANSI to Unicode & Unicode to ANSI for OLE

Q138813
QCOleDispatchDriver类型的对象能否用于多线程???
T如果可用应怎么写代码?!
Ahttp://www.csdn.net/Expert/FAQ/FAQ_Index.asp?id=84
Q对话框类中没有m_bAutoMenuEnable数据成员怎样使EnableMenuItem函数起作用?! 
T
CMenu* mmenu = GetMenu();
CMenu* submenu = mmenu->GetSubMenu(0);
submenu->EnableMenuItem(ID_FILE_NEW, MF_BYCOMMAND | MF_GRAYED);


在基于对话框的应用程序中,没有使用ON_UPDATE_COMMAND_UI,想使右键弹出式菜单的一些菜单项根据条件有效或无效,用EnableMenuItem函数因为先要在CMainFrame类及派生类对象的构造函数中将m_bAutoMenuEnable 设为FALSE,但m_bAutoMenuEnable 不是CDialog的数据成员,而只是CMainFrame的数据成员,怎么办?怎样使EnableMenuItem函数起作用?!



Ahttp://www.csdn.net/Develop/read_article.asp?id=9481
Q病毒?
T
奇怪的错误,病毒?:
 昨天这一段代码都可以运行,今天下午就不成功了!其实原理很简单,就是获得IHTMLDocument2/IHTMLWindow2的接口然后互调,结果发现IHTMLWindow2::get_document的函数错误,错误代码是
hr=0x800703e6,内存分配访问无效
 这个错误是我在调试IFrame的时候发现的,我已经能成功获得IFrame的IHTMLWindow2的接口,但是无论如何无法获得IHTMLDocument2的接口。
 我也尝试使用MSDN提供的方法,但是结果是一样的。
系统平台:
 Win2kServer Sp2/IE6.0
 WinXPHome/IE6.0

Reference:
 Q249232
 
Source code here:

#include <stdafx.h>
#include <atlbase.h>
#include <mshtml.h>
#import "P://WINNT//system32//mshtml.tlb"
#include <oleacc.h>
#include "IEFunc.h"

BOOL GetHTMLDocument(HWND hwnd)
{
 HRESULT hr;
 LRESULT lRes;
 MSHTML::IHTMLDocument2Ptr spDoc,spChild;
 MSHTML::IHTMLWindow2Ptr spWin;
 
 UINT nMsg = ::RegisterWindowMessage( "WM_HTML_GETOBJECT");
 ::SendMessageTimeout( hwnd, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes ); 
 if(FAILED(hr = ObjectFromLresult( lRes, __uuidof(IHTMLDocument2), 0, (void**)&spDoc )))
  return FALSE;
 spWin=spDoc->GetparentWindow();
 spChild=spWin->Getdocument();
 return TRUE;
}

BOOL CALLBACK EnumProc(
  HWND hwnd,      // handle to parent window
  LPARAM lParam   // application-defined value
)
{
 HWND* phwnd=(HWND*)lParam;
 char pszClassName[255];
 GetClassName(hwnd,pszClassName,255);
 OutputDebugString(pszClassName);
 OutputDebugString("/r/n");
 if(!strcmp(pszClassName,"IEFrame"))
 {
  *phwnd=hwnd; 
  return FALSE;
 }
 else if(!strcmp(pszClassName,"Internet Explorer_Server"))
 {
  *phwnd=hwnd;
  return FALSE;
 }
 return TRUE;
}

void EnumIEFrame()
{
 HWND hwnd=NULL,hIE=NULL;
 EnumDesktopWindows(NULL,EnumProc,(LPARAM)&hwnd); 
 if(hwnd==NULL) return ;
 EnumChildWindows(hwnd,EnumProc,(LPARAM)&hIE);
 if(hIE==NULL) return ;
 GetHTMLDocument(hIE);
 return ;
}

Ahttp://www.csdn.net/expert/topic/783/783799.xml
Q如何动态的改变ListCtrl 中的的项的图标??
T我向ListCtrl中添加项的时候可以指定图标,但是当我改变某一项的内容的同时也需要改变图标,我该怎样做呢??(report方式下)
A
直接/间接发送LVM_SETITEM,在传递的LVITEM结构中设置iItem,iSubItem,iImage和iMask(LVIF_IMAGE)
如果iImage在插入的时候设置为I_IMAGECALLBACK,则需要捕获LVN_GETDISPINFO
参见
HOWTO: Change Icon or Bitmap of CListCtrl Item When Selected

Q141834
QMFC 把我的timer 杀掉了吗??
T
我建立了一个单文档的工程,其中 View 从CListView 继承,我在CxxxView::OnInitialUpdate()  设置了 定时器 SetTimer(1,1000,NULL);
仅仅如此而已,但出了问题 
CxxxView::OnTimer(UINT nIDEvent)仅收到了大概20个 timer 消息,其中还有nIDEvent=45(2个),就再也没有了WM_TIMER消息了,这是什么问题??是MFC 把我的定时器杀掉了吗?
A
PRB: OnTimer() Is Not Called Repeatedly for a List Control

Q200054
SYMPTOMS
If you call the SetTimer function to send periodic WM_TIMER messages to a list control, you may find that the WM_TIMER message handler (the OnTimer function) for a list control is called only twice.



CAUSE
The WM_TIMER handler in the list control calls the KillTimer function.

RESOLUTION
If you define the timer ID in the SetTimer call, do not call the default handler for WM_TIMER.



STATUS
This behavior is by design.



MORE INFORMATION
The list control uses the timer for editing labels, and for scrolling. When you handle the timer message, if the timer ID is your own timer, don't call the default handler (CListCtrl::OnTimer).

In the sample code below, without the if clause in the CMyListCtrl::OnTimer function, the default WM_TIMER handler is always called, which destroys both the control's timer and your own timer. As a result, you should see a trace statement for each timer.


void CGensdiView::OnInitialUpdate()
{
   CView::OnInitialUpdate();
 
   m_pCtrl = new CMyListCtrl;
   m_pCtrl->Create(WS_VISIBLE | WS_CHILD | WS_BORDER
                   | LVS_REPORT | LVS_EDITLABELS,
                   CRect(0, 0, 100, 150), this, 2134);

   m_pCtrl->InsertColumn(0, "one");
   m_pCtrl->InsertItem(0, "0 0 0 0 0 0 0 0 0 0 0");
   m_pCtrl->InsertItem(1, "1 1 1 1 1 1 1 1 1 1 1");
   m_pCtrl->InsertItem(2, "2 2 2 2 2 2 2 2 2 2 2");
}

void CGensdiView::OnLButtonDown(UINT nFlags, CPoint point)
{
   m_pCtrl->m_timerID = m_pCtrl->SetTimer(14, 500, NULL);
   TRACE("timer %d is set/n", m_pCtrl->m_timerID);
}

CMyListCtrl::CMyListCtrl()
{
   m_timerID = -1;
}

void CMyListCtrl::OnTimer(UINT nIDEvent)
{
   if (nIDEvent != m_timerID)
      CListCtrl::OnTimer(nIDEvent);
   TRACE("OnTimer %d/n", nIDEvent);
}

Q我想在DoDataExchange中检查输入的参数,不知道DDX_Text是怎么搞的
T我想跟DDV_MinMaxInt做的一样的,不知道如何实现
AMSDN TN026: DDX and DDV Routines
Q一个属性页domodal时产生的异常!!!!!在线等待!
T
First-chance exception in project.exe (COMCTL32.DLL): 0xC0000005: Access Violation.

我看了很多属性页的源代码,觉得我的用法没什么问题阿,就是三个page,自己从cpropertysheet派生勒一个子类,在他的构造函数里添加三个页面,现在我已经给这个属性页加上应用逻辑的代码勒,工作也正常,就是程序运行后第一次domodal的时候有这个异常,以后在domodal就没有勒,我的os是win2000,vc6,希望大家能帮我解决.
A
SYMPTOMS
Calling CPropertySheet::DoModal() or CPropertySheet::Create() in Windows 95 may cause an exception. The Output window displays a message that says the following:

First-chance exception in <program.exe> (Comctl32.dll): 0xC0000005:
Access Violation.
Newer versions (version 4.70) of the Comctl32.dll do not have this problem.



CAUSE
The CommCtl32.dll tries to modify the resources for the pages. Since the resources are normally in read-only sections this throws an Exception that can be caught in the application. However, if the application does not catch this exception then the OS will handle this exception correctly.



RESOLUTION
The first-chance exception can be ignored because it is safely handled by the operating system.

One way to prevent the exception from being thrown is to make the resources read/write. You can do this by adding a linker setting of "/SECTION:.rsrc,rw."

A second way to prevent the exception being thrown is to change the font of the pages so they are not "MS Sans Serif". MFC checks the dialog template font for the page. If it is not "MS Sans Serif" then it makes a copy of the resource in read/write memory, modifies the font and passes this to the C mCtl32.dll. So when the dll writes to the template for the page it is writing to read/write memory and hence exception is not thrown.

Another way to prevent the exception from affecting your application is not to have the call for creating the property sheet in a try/catch(...) block. Instead catch particular exceptions in the catch block.

If the property sheet is part of an OLE Automation Server that can be invoked through a method of the server then you have to make the resources read/write, using either of the first two methods described above, since OLE catches the exception.

NOTE: Making the resources Read/Write can cause the resources to be written to a page file.

STATUS
This behavior is by design.



MORE INFORMATION

Sample Code

   /* Compile options needed: default
   */

   /***** this code will cause unpredictable results *****/
   try
   {
       sheet.DoModal();
   }
   catch(...)
   {
   }

   /***** this code is OK *****/
   try
   {
       if (0 == sheet.DoModal())
           throw "DoModal() failed!";
   }
   catch(char * str)
   {
       TRACE ("Exception thrown: %s/n", str);
   }


©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值