Example #1
0
//==============================================
int g_InitActX_Control( HWND hWnd) {
    IUnknown * pUnk;
    IUnknown * pUnkCont;
    HRESULT hRet;


    x_pIFactory = new CFactory();
    if( x_pIFactory == NULL) return 2;

    hRet = CoRegisterClassObject( CLSID_CP_TimeSyncClass,     //Class identifier (CLSID) to be registered
                                  x_pIFactory,     //Pointer to the class object
                                  CLSCTX_LOCAL_SERVER,  //Context for running executable code
                                  REGCLS_MULTIPLEUSE,  // multiple clients for the same server, we do not start a new server for each client
                                  &x_dwRegister ); //Save registered object info, for future release by CoRevokeClassObject()
    if( hRet != S_OK)  return 3;


    // Initialize ATL control containment code.
    AtlAxWinInit();
    // Create ActiveX control using the window handle
    // and get the IUnknown interface of this control
    hRet = AtlAxCreateControlEx( OLESTR("RPco.X"), hWnd, NULL,
                                 &pUnkCont, &pUnk, IID_NULL, NULL );

    // Obtain smart pointer to TDevAccX using IUnknown of the control
    g_pRPcoX = pUnk;
    pUnk->Release();

    return 0;
}
Example #2
0
/**********************************************************************
 * AtlAxWin class window procedure
 */
static LRESULT CALLBACK AtlAxWin_wndproc( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam )
{
    if ( wMsg == WM_CREATE )
    {
            DWORD len = GetWindowTextLengthW( hWnd ) + 1;
            WCHAR *ptr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
            if (!ptr)
                return 1;
            GetWindowTextW( hWnd, ptr, len );
            AtlAxCreateControlEx( ptr, hWnd, NULL, NULL, NULL, NULL, NULL );
            HeapFree( GetProcessHeap(), 0, ptr );
            return 0;
    }
    return DefWindowProcW( hWnd, wMsg, wParam, lParam );
}
Example #3
0
//==============================================================================
int CTimeSync::Initialize( HWND hWnd ){

  IUnknown * pUnk;
  IUnknown * pUnkCont;
  HRESULT hRet;

  // Initialize ATL control containment code.
  AtlAxWinInit(); 
  // Create ActiveX control using the window handle 
  // and get the IUnknown interface of this control
  hRet = AtlAxCreateControlEx( OLESTR("RPco.X"), hWnd, NULL, 
                                      &pUnkCont, &pUnk, IID_NULL, NULL );

  // Obtain smart pointer to TDevAccX using IUnknown of the control
  m_pTDev = pUnk;
  pUnk->Release();
//  m_InitTimerThread();
  m_iState = ecInitialized;
  return 0;
}
Example #4
0
/***********************************************************************
 *           AtlAxCreateControl           [atl100.@]
 */
HRESULT WINAPI AtlAxCreateControl(LPCOLESTR lpszName, HWND hWnd,
        IStream *pStream, IUnknown **ppUnkContainer)
{
    return AtlAxCreateControlEx( lpszName, hWnd, pStream, ppUnkContainer,
            NULL, NULL, NULL );
}
Example #5
0
/*----------------------------------------------------------------------------------------------
	The hwnd has been attached.
----------------------------------------------------------------------------------------------*/
void HwMainWnd::PostAttach(void)
{
	StrAppBuf strbT; // Holds temp string

	// Set the default caption text.
	strbT.Load(kstidHelloWorld);
	::SendMessage(m_hwnd, WM_SETTEXT, 0, (LPARAM)strbT.Chars());

	// This creates the main frame window and sets it as the current window. It also
	// creates the rebar and status bar.
	SuperClass::PostAttach();

	const int rgrid[] =
	{
		kridTBarStd,
		kridHwTBarIns,
		kridHwTBarTools,
		kridHwTBarWnd,
	};

	GetMenuMgr()->LoadToolBars(rgrid, SizeOfArray(rgrid));

	// Create the menu bar.
	AfMenuBarPtr qmnbr;
	qmnbr.Create();
	qmnbr->Initialize(m_hwnd, kridAppMenu, kridAppMenu, "Menu Bar");
	m_vqtlbr.Push(qmnbr.Ptr());

	// Create the toolbars.
	AfToolBarPtr qtlbr;

	qtlbr.Create();
	qtlbr->Initialize(kridTBarStd, kridTBarStd, "Standard");
	m_vqtlbr.Push(qtlbr);

	qtlbr.Create();
	qtlbr->Initialize(kridHwTBarIns, kridHwTBarIns, "Insert");
	m_vqtlbr.Push(qtlbr);

	qtlbr.Create();
	qtlbr->Initialize(kridHwTBarTools, kridHwTBarTools, "Tools");
	m_vqtlbr.Push(qtlbr);

	qtlbr.Create();
	qtlbr->Initialize(kridHwTBarWnd, kridHwTBarWnd, "Window");
	m_vqtlbr.Push(qtlbr);

	// Load window settings.
	LoadSettings(NULL, false);

	g_app.AddCmdHandler(this, 1);
	m_qstbr->RestoreStatusText();

	// Create the client window.
	const int kwidChild = 1000;
	WndCreateStruct wcs;
	wcs.InitChild("STATIC", m_hwnd, kwidChild);
	m_qwndHost.Create();
	m_qwndHost->CreateAndSubclassHwnd(wcs);

	Assert(memcmp(&CLSID_SaCtrlEvent, &DIID__DSAEvents, isizeof(GUID)) == 0);

	CComCoClass<SaCtrlEvent>::CreateInstance(&m_qsce);
	IUnknownPtr qunk;
	CheckHr(AtlAxCreateControlEx(L"SA.SACtrl.1", m_qwndHost->Hwnd(), NULL, NULL, &qunk,
		DIID__DSAEvents, (IUnknown *)m_qsce.Ptr()));
	CheckHr(qunk->QueryInterface(DIID__DSA, (void **)&m_qctrl));
	m_qsce->Init(this, m_qctrl);
	StrUni stu(L"baluchi.wav");
	CheckHr(m_qctrl->put_WaveFile(stu.Bstr()));
	CheckHr(m_qctrl->raw_SetGraphs(GRAPH_MAGNITUDE, GRAPH_MAGNITUDE));
	CheckHr(m_qctrl->put_ShowContextMenu(false));
	CheckHr(m_qctrl->put_ShowCursorContextMenu(false));

	::ShowWindow(m_qwndHost->Hwnd(), SW_SHOW);

	g_app.AddCmdHandler(this, 1);
}
Example #6
0
static void test_AtlAxCreateControl(void)
{
    HWND hwnd;
    IUnknown *control, *container;
    HRESULT hr;
    DWORD ret, ret_size;
    HANDLE hfile;
    WCHAR file_uri1W[MAX_PATH], pathW[MAX_PATH];

    container = NULL;
    control = (IUnknown *)0xdeadbeef;
    hr = AtlAxCreateControlEx(NULL, NULL, NULL, &container, &control, NULL, NULL);
    todo_wine ok(hr == S_FALSE, "got 0x%08x\n", hr);
    todo_wine ok(container != NULL, "returned %p\n", container);
    ok(!control, "returned %p\n", control);

    container = NULL;
    control = (IUnknown *)0xdeadbeef;
    hwnd = create_container_window();
    ok(hwnd != NULL, "create window failed!\n");
    hr = AtlAxCreateControlEx(NULL, hwnd, NULL, &container, &control, &IID_NULL, NULL);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    todo_wine ok(container != NULL, "returned %p!\n", container);
    ok(!control, "returned %p\n", control);
    DestroyWindow(hwnd);

    container = NULL;
    control = (IUnknown *)0xdeadbeef;
    hwnd = create_container_window();
    ok(hwnd != NULL, "create window failed!\n");
    hr = AtlAxCreateControlEx(emptyW, hwnd, NULL, &container, &control, &IID_NULL, NULL);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    todo_wine ok(container != NULL, "returned %p!\n", container);
    ok(!control, "returned %p\n", control);
    DestroyWindow(hwnd);

    container = (IUnknown *)0xdeadbeef;
    control = (IUnknown *)0xdeadbeef;
    hwnd = create_container_window();
    ok(hwnd != NULL, "create window failed!\n");
    hr = AtlAxCreateControlEx(randomW, hwnd, NULL, &container, &control, &IID_NULL, NULL);
    ok(hr == CO_E_CLASSSTRING, "got 0x%08x\n", hr);
    ok(!container, "returned %p!\n", container);
    ok(!control, "returned %p\n", control);
    DestroyWindow(hwnd);

    container = NULL;
    control = NULL;
    hwnd = create_container_window();
    ok(hwnd != NULL, "create window failed!\n");
    hr = AtlAxCreateControlEx(progid1W, hwnd, NULL, &container, &control, &IID_NULL, NULL);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    ok(container != NULL, "returned %p!\n", container);
    ok(control != NULL, "returned %p\n", control);
    DestroyWindow(hwnd);

    container = NULL;
    control = NULL;
    hwnd = create_container_window();
    ok(hwnd != NULL, "create window failed!\n");
    hr = AtlAxCreateControlEx(clsid1W, hwnd, NULL, &container, &control, &IID_NULL, NULL);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    ok(container != NULL, "returned %p!\n", container);
    ok(control != NULL, "returned %p\n", control);
    IUnknown_Release(container);
    IUnknown_Release(control);
    DestroyWindow(hwnd);

    container = NULL;
    control = NULL;
    hwnd = create_container_window();
    ok(hwnd != NULL, "create window failed!\n");
    hr = AtlAxCreateControlEx(url1W, hwnd, NULL, &container, &control, &IID_NULL, NULL);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    ok(container != NULL, "returned %p!\n", container);
    ok(control != NULL, "returned %p\n", control);
    IUnknown_Release(container);
    IUnknown_Release(control);
    DestroyWindow(hwnd);

    container = NULL;
    control = NULL;
    hwnd = create_container_window();
    ok(hwnd != NULL, "create window failed!\n");
    hr = AtlAxCreateControlEx(mshtml1W, hwnd, NULL, &container, &control, &IID_NULL, NULL);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    ok(container != NULL, "returned %p!\n", container);
    ok(control != NULL, "returned %p\n", control);
    IUnknown_Release(container);
    IUnknown_Release(control);
    DestroyWindow(hwnd);

    container = NULL;
    control = NULL;
    hwnd = create_container_window();
    ok(hwnd != NULL, "create window failed!\n");
    hr = AtlAxCreateControlEx(mshtml2W, hwnd, NULL, &container, &control, &IID_NULL, NULL);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    ok(container != NULL, "returned %p!\n", container);
    ok(control != NULL, "returned %p\n", control);
    IUnknown_Release(container);
    IUnknown_Release(control);
    DestroyWindow(hwnd);

    container = (IUnknown *)0xdeadbeef;
    control = (IUnknown *)0xdeadbeef;
    hwnd = create_container_window();
    ok(hwnd != NULL, "create window failed!\n");
    hr = AtlAxCreateControlEx(mshtml3W, hwnd, NULL, &container, &control, &IID_NULL, NULL);
    ok(hr == CO_E_CLASSSTRING, "got 0x%08x\n", hr);
    ok(!container, "returned %p!\n", container);
    ok(!control, "returned %p\n", control);
    DestroyWindow(hwnd);

    ret = GetTempPathW(MAX_PATH, pathW);
    ok(ret, "GetTempPath failed!\n");
    lstrcatW(pathW, html_fileW);
    hfile = CreateFileW(pathW, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, 0);
    ok(hfile != INVALID_HANDLE_VALUE, "failed to create file\n");
    ret = WriteFile(hfile, html_str, sizeof(html_str), &ret_size, NULL);
    ok(ret, "WriteFile failed\n");
    CloseHandle(hfile);

    /* test C:// scheme */
    container = NULL;
    control = NULL;
    hwnd = create_container_window();
    ok(hwnd != NULL, "create window failed!\n");
    hr = AtlAxCreateControlEx(pathW, hwnd, NULL, &container, &control, &IID_NULL, NULL);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    ok(container != NULL, "returned %p!\n", container);
    ok(control != NULL, "returned %p\n", control);
    IUnknown_Release(container);
    IUnknown_Release(control);
    DestroyWindow(hwnd);

    /* test file:// scheme */
    lstrcpyW(file_uri1W, fileW);
    lstrcatW(file_uri1W, pathW);
    container = NULL;
    control = NULL;
    hwnd = create_container_window();
    ok(hwnd != NULL, "create window failed!\n");
    hr = AtlAxCreateControlEx(file_uri1W, hwnd, NULL, &container, &control, &IID_NULL, NULL);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    ok(container != NULL, "returned %p!\n", container);
    ok(control != NULL, "returned %p\n", control);
    IUnknown_Release(container);
    IUnknown_Release(control);
    DestroyWindow(hwnd);

    /* test file:// scheme on non-existent file. */
    ret = DeleteFileW(pathW);
    ok(ret, "DeleteFile failed!\n");
    container = NULL;
    control = NULL;
    hwnd = create_container_window();
    ok(hwnd != NULL, "create window failed!\n");
    hr = AtlAxCreateControlEx(file_uri1W, hwnd, NULL, &container, &control, &IID_NULL, NULL);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    ok(container != NULL, "returned %p!\n", container);
    ok(control != NULL, "returned %p\n", control);
    IUnknown_Release(container);
    IUnknown_Release(control);
    DestroyWindow(hwnd);
}