问了多位c++程序员,win32群里的朋友如何在Win32中调用Atl控件,也游了开源网站一回,均无结果,按照微软msdn给出的步骤也没有搞定。搜索引擎找了无数篇文件,终于找到可行的方法,故记录于此。
第一步、创建Win32 Project项目,Application Settings窗口中勾选“ATL”
第二步、添加引用
#pragma comment(lib, "atl.lib") //#include <atldef.h> //#include <atliface.h> //#define _ATL_DLL_IMPL //using namespace ATL
第三步、调用ATL
//“{}”中为被调用Atl控件的guid
CComModule _Module; _Module.Init(NULL, hInst); HWND hWnd1 = CreateWindow("AtlAxWin", "",WS_CHILD|WS_VISIBLE|WS_OVERLAPPEDWINDOW, 10, 10,300, 300, hWnd, NULL, hInst, NULL ); USES_CONVERSION; CComPtr<IUnknown> spUnk; CoInitialize(spUnk); HRESULT hRet = AtlAxCreateControl(T2COLE("{FCB4D80C-E22E-41AB-8C0F-0E7B9377B6F8}"), hWnd, NULL, &spUnk); //if(FAILED(hRet)) // return -1; //_Module.Terminate(); _Module.Term();
其它方式(调用未成功)
#include <atlbase.h> #include <atlwin.h> CAxWindow wnd; RECT rect = {240,240,240,240}; HWND hh= wnd.Create(hWnd, rect, "{FCB4D80C-E22E-41AB-8C0F-0E7B9377B6F8}",WS_CHILD|WS_VISIBLE,NULL,0U,NULL);
其它方式(调用未成功)
CreateAxControl
参考资料
http://support.microsoft.com/kb/218442/EN-US
http://www.codeguru.com/cpp/com-tech/atl/activex/article.php/c69
http://support.microsoft.com/kb/192560
http://social.msdn.microsoft.com/Forums/zh-CN/windowssdk/thread/88a981ea-8125-4917-a45e-87cfbc7fd1dd