我用atl创建一个fullcontrol控件支持mfc的。我想在里面调用一个vc做的ocx。我用add to project把控件导入,定义一个成员变量,直接通过这个成员变量访问控件的方法.我知道这是不行的。执行的时候就报错。我知道用Create方法是可以的。但是参数应该怎么设置。
如果用不支持mfc的那ocx怎么倒入?
如果用不支持mfc的那ocx怎么倒入?
解决方案 »
- MFC发布版编译出错
- 网页POST数据不成功
- 1、设置VC编译链接选项 2、NC访问FTP服务器
- 打算做一个代码管理软件,给点意见!
- 为什么我不能删除帖子呢?
- vc中的CArray,CList,和CMap和C++的list,verct,map,set等容器类有什么区别了!!
- 请问 afoolboy 在吗? 帮帮我啊,我快要死了
- 请教,VC中Build->Start Debug->Attach to Process为什么是空的,该怎么办?急!!
- 程序加断点执行成功, 但是不加断点就失败
- 求大神讲解一下哪错了,这两个错误,这样能看出错误来吗?
- 在连续打开多个模式对话框后,点击某一按钮后,关闭所有的对话框
- 如何在 win XP 中添加自己做的输入法?
CComQIPtr<IWebBrowser2> m_spBrowser;
CAxWindow content_wnd;
......
if( _tcslen(m_tcHtmlFileName) > 0 )
{
RECT rc;
GetClientRect( &rc );
if(m_spBrowser==NULL)
{
LPOLESTR pstrbrowserid;
StringFromCLSID(IID_IWebBrowser2,&pstrbrowserid);
_bstr_t bstrbrowser(pstrbrowserid);
CoTaskMemFree(pstrbrowserid);
if(content_wnd.IsWindow())
content_wnd.DestroyWindow();
content_wnd.Create( m_hWnd, rc, LPCTSTR(bstrbrowser), WS_CHILD¦WS_VISIBLE¦WS_HSCROLL¦WS_VSCROLL );//create a browser control
HRESULT hrbrowser;
hrbrowser = content_wnd.QueryControl( IID_IWebBrowser2, reinterpret_cast<void**>(&m_spBrowser) );
}#import "c:\winnt\system32\mswinsck.ocx" no_namespace
...
IMSWinsockControlPtr pWinsock;
_bstr_t pstr("mswinsock.winsock");
CLSID clsidwinsock;
CLSIDFromProgID(pstr,&clsidwinsock);
pWinsock.CreateInstance(clsidwinsock);
if(pWinsock)
{
pWinsock->RemotePort=13;
pWinsock->RemoteHost=_bstr_t("time-a.nist.gov");
_variant_t varoptional((long)DISP_E_PARAMNOTFOUND,VT_ERROR);
HRESULT hr= pWinsock->Connect();
if(FAILED(hr))
MessageBox(NULL,"failed","failed",MB_OK);
......pWinsock->Close();
}
else
MessageBox(NULL,"can not create winsock","error",MB_OK); ////////////////////////////////////////////////////////////////////////////////
// Use swflash.ocx to play flash
// if it works, it is written by masterz, otherwise I don't know who writes it(*_*)
////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#define MAX_LOADSTRING 100
#include <atlbase.h>
CComModule _Module;
#include <atlcom.h>
#include <atlwin.h>
#pragma comment(lib,"atl")
#import "c:\winnt\system32\macromed\flash\swflash.ocx"
using namespace ShockwaveFlashObjects;// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
CAxWindow m_container;// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
// Initialize global strings
wsprintf(szTitle,"use flash control in sdk exe");
wsprintf(szWindowClass,"flashinsdk");
MyRegisterClass(hInstance);
CoInitialize(NULL);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
CoUninitialize();
return msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage is only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;//(LPCSTR)IDC_FLSH;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION); return RegisterClassEx(&wcex);
}//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd; hInst = hInstance; // Store instance handle in our global variable
AtlAxWinInit(); hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd)
{
return FALSE;
} ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd); return TRUE;
}//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TCHAR szHello[MAX_LOADSTRING];
wsprintf(szHello,"use flash control in sdk");
IShockwaveFlash* shwaveflash;
HWND hbtnstart;
RECT rc;
switch (message)
{
case WM_CREATE:
GetClientRect(hWnd, &rc );
rc.top = (rc.bottom+rc.top)/2;
m_container.Create( hWnd, rc, LPCTSTR("ShockwaveFlash.ShockwaveFlash.1"), WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL );//create a browser control
hbtnstart=CreateWindow("BUTTON","play",WS_CHILD|WS_VISIBLE,0,0,120,30,hWnd,(HMENU)0x100,hInst,0);
break;
case WM_SIZING:
GetClientRect(hWnd, &rc );
rc.top = (rc.bottom+rc.top)/2;
m_container.MoveWindow(&rc,true);
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case 0x100:
m_container.QueryControl( __uuidof(IShockwaveFlash), reinterpret_cast<void**>(&shwaveflash) );
shwaveflash->put_Movie(_bstr_t("c:\\downloads\\radin\\flash\\2.1.swf")); // you have to change the path here
shwaveflash->Play();
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
RECT rt;
GetClientRect(hWnd, &rt);
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
content_wnd.Create( m_hWnd, rc, LPCTSTR(bstrbrowser), WS_CHILD¦WS_VISIBLE¦WS_HSCROLL¦WS_VSCROLL );//
brvbar
BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle,
const RECT& rect, CWnd* pParentWnd, UINT nID,
CFile* pPersist = NULL, BOOL bStorage = FALSE,
BSTR bstrLicKey = NULL)
里面的参数应该怎么生成怎么填。我的被调用控件生成的类叫CFrs_com.调用控件生成的类叫CMachineObj。谢谢 我是刚入门什么都不懂。
IShockwaveFlash* shwaveflash;
两个例子都有这个定义。但是我只有一个ocx的release版本 我怎么知道 它的类名是什么。
不过无论如何 我先给50分
LPCTSTR lpstrWndClass, -- 窗口类名
HWND hWndParent, -- 该窗口的父窗口
_U_RECT rect = NULL, -- 窗口的位置和尺寸信息
LPCTSTR szWindowName = NULL, -- 你要创建的窗口的窗口名
DWORD dwStyle = 0, -- 窗口的风格(这个地方你要是不懂我也没办法告诉你,你要进修进修)
DWORD dwExStyle = 0, -- 窗口的扩展风格
_U_MENUorID MenuOrID = 0U, -- 窗口的菜单或本窗口 ID (一般你就放 ID)
LPVOID lpCreateParam = NULL -- 存放 CREATESTRUCT 结构我觉得这些东西如果你都不懂的话,真的别人要给你解释很麻烦的,你最好先学学 SDK 编程
我刚看了createwindow的用法,下面是我的代码。
hWnd = CreateWindow("BUTTON", "hello", WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, NULL, NULL);
RECT rc;
::GetClientRect(hWnd, &rc );
if(m_container.IsWindow())
m_container.DestroyWindow();
m_container.Create( hWnd, rc, LPCTSTR("FRSCOM.FrscomCtrl.1"), WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL );//
m_container.QueryControl( __uuidof(_DFrs_com), reinterpret_cast<void**>(&m_FRS) m_FRS->IsOpen();
问题是m_frs在queryControl之后就变成了0x0000000.当执行m_FRS->IsOpen();它就报错了。
CreateWindow的窗口类名我填了BUTTON,,但我并不需要button,我应该填什么?那个错误是不是因为窗口类名引起的。
谢谢