1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Using ActiveX from Win32/Atl

Discussion in 'Win32' started by DarkSun23, Feb 25, 2007.

  1. DarkSun23

    DarkSun23 New Member

    Feb 25, 2007
    Likes Received:
    Trophy Points:
    Hey there!
    I am trying to do something a bit difficult and need you help...

    I have an MFC form containing a VB control, called the MS Flex Grid (C:\WINDOWS\system32\MSFLXGRD.OCX) ActiveX Control and some legacy code.

    Unfortunately I am not allowed to change this code or use MFC, But I still want to access and manipulate the control using from a Win32 function (and since needed, using ATL as well).

    I tried several attitudes, the first was obtaining a handle (HWND) to the control and passing messages (via SendMessage) to it in order to command it... Unfortunately it seems SendMessage only works for the basic Win32 controls (ListBox/Label etc.) and it let's me manipulate their basic functionality only, so it's no good....

    Looking around I've noticed that a function called: GetDlgControl is mentioned in some places and might be of use, but I have found no such function. All I found was the ATL CWindow::GetDlgControl function, So I tried something like this:

    _Module.Init(NULL, AfxGetInstanceHandle(), &LIBID_ATLLib);
    CWnd *cwnd = GetDlgItem(IDC_MSFLEXGRID1);
    HWND hWnd = *cwnd;
    MSFlexGridLib::IMSFlexGridPtr pFlexGrid = NULL;
    CWindow wnd(hWnd);
    HRESULT hr = wnd.GetDlgControl(IDC_MSFLEXGRID1,
    But hr is equal E_FAIL (MSDN = "the function returns E_FAIL if the control specified by nID (first parameter) cannot be found"). But this -is- the right resource ID.

    Then I tried something else instead:
    _Module.Init(NULL, AfxGetInstanceHandle(), &LIBID_ATLLib);
    HWND hWnd2 = (HWND)m_mfcFlexGridControl;
    HWND hWnd = (HWND)GetDlgItem(IDC_MSFLEXGRID1);
    MSFlexGridLib::IMSFlexGridPtr pFlexGrid = NULL;
    CWindow wnd(hWnd2);
    HRESULT hr = wnd.GetDlgControl(IDC_MSFLEXGRID1,
    But got the same result....

    As it didn't work, I also tried several other combinations such as:
    #import "C:\WINNT\System32\msflxgrd.ocx" raw_interfaces_only,
    raw_native_types, no_namespace, named_guids
    I even (with some despair...) tried in a loop all the IDs from 0 to 50000 in a loop....But Too no avail...

    What am I missing here?

    Many thanks!

Share This Page