Loading...

Dynamic creation of control problems

Support for GdViewer OCX and GdViewer Pro ActiveX/SDK.

Dynamic creation of control problems

Postby justcode » Wed Jul 15, 2009 9:31 pm

I'm using Visual Studio 6, MFC. I compiled the C++ sample code. The viewer control worked fine on the dialog template. I then created a generic Cwnd derived class and replaced Cwnd with the wrapper class. Recompiled the project and the code worked fine. the derived class captured all the events of the control, like WM_SIZE and WM_SETFOCUS, etc... and the TRACE statements displayed in the debug window.

Here is the issue:
I remove the viewer control from the dialog template and put a static frame control in its place. I then dynamically create the control calling the create function and place it on the dialog in the same position as the frame. The control appears fine, except I do not get any events in my derived class like I did with the control on the dialog template. I can not figure out what is the problem.

The reason I need to dynamically create the control because I want to place the viewer in a splitter window with a Clistctrl with thumbs next to it. I was having all kinds of issues so I went back the the simple example code to see it was having issues too... If this control is too buggy, I may not be able to use it as a replacement for our legacy control. I am in the evaluation phase right now and all the features is promising if I can just get it to work with some stability...

// Snippet from my derived class:
Code: Select all
    class CGDViewerCtrl : public C_GdViewer

    ....
    void CGDViewerCtrl::OnSize(UINT nType, int cx, int cy)
    {
   C_GdViewer::OnSize(nType, cx, cy);   
   TRACE("CGDViewerCtrl::OnSize()... \n");   
    }
    void CGDViewerCtrl::OnLButtonDown(UINT nFlags, CPoint point)
    {
   TRACE("CGDViewerCtrl::OnLButtonDown()... \n");   
   C_GdViewer::OnLButtonDown(nFlags, point);
    }
    void CGDViewerCtrl::OnLButtonUp(UINT nFlags, CPoint point)
    {
   TRACE("CGDViewerCtrl::OnLButtonUp()... \n");   
   C_GdViewer::OnLButtonUp(nFlags, point);
    }


// your sample project:
    CSampleDlg::OnInitDialog()
   .....

    CRect rect;
    m_Frame.GetWindowRect(&rect);
    m_Frame.ShowWindow(SW_HIDE);
   
    ScreenToClient(&rect);
    m_viewer.Create(NULL, WS_VISIBLE | WS_TABSTOP, rect, (CWnd*)this, 500);

    //Please, replace XXXX by a valid demo or commercial license key.
    m_viewer.SetLicenseNumber("00*******************************00");

    return TRUE;  // return TRUE  unless you set the focus to a control
}


If the control gets placed on the dialog template, it gets the TRACE messages with the window events. If I dynamically create the control, as shown above, I get no TRACE messages?? (FYI, I did remove the DDX_Control references)

Can you help me?

2nd, separate issue:
I had to use the GdPicturePro5S.Imaging wrappers, cause the one without the 'S' was giving me parameters errors. Not sure if this is a bug... I was under the assumption to use the non 'S' for windows applications, but they don't work.
I am using the latest Version, GdPicture Pro Imaging SDK Ver. 5.11.17 (08 July 2009)

Thanks,
-Paul
Paul R. Rondeau
Sr. Software Engineer
MultiProcess Computer Corporation
User avatar
justcode
 
Posts: 24
Joined: Wed Jul 15, 2009 9:20 pm

Re: Dynamic creation of control problems

Postby Loïc » Thu Jul 16, 2009 1:01 am

Hi Paul,


It is too hard and too long for us to try to reproduce your problem in a short delay.

Please, if you can, make a tiny application reproducing this problem and send it to esupport (at) gdpicture (dot) com.

With best regards,

Loïc
Loïc Carrère, support team.
www.orpalis.com
User avatar
Loïc
Site Admin
 
Posts: 4441
Joined: Tue Oct 17, 2006 10:48 pm
Location: France

Re: Dynamic creation of control problems

Postby justcode » Fri Jul 17, 2009 2:09 pm

After searching for a few days I seemed to have found the answer here:
http://support.microsoft.com/kb/156051 :roll:

Microsoft reports the symptom as:
When you create ActiveX Controls dynamically via CWnd::CreateControl(), Windows messages are not sent to your CWnd-derived class. For example, if you create a handler for WM_KILLFOCUS, it is not called.

I tried it and it seemed to work correctly.

After solving that issue, I came across another. If I use SetWindowPos(), to resize the control, I loose the subclassing and stop receiving any more messages from Windows. After searching around, it was suggested to use MoveWindow() instead for ActiveX controls. After replacing the call, the control resized correctly and I still had the Subclassing and continued to get all of the Window messages.

After solving that issue, I came across another. Not sure if this is an MFC, ActiveX or other issue. I have the control in a splitter window. One pane is a listctrl and the other the viewer. When I click on the listctrl and the viewer looses focus and then I click back on the viewer, I do not seem to get the focus back. The focus seems to stay on the listctrl. I will try and figure this one out.

-Paul
Last edited by justcode on Fri Jul 17, 2009 5:54 pm, edited 1 time in total.
Paul R. Rondeau
Sr. Software Engineer
MultiProcess Computer Corporation
User avatar
justcode
 
Posts: 24
Joined: Wed Jul 15, 2009 9:20 pm

Re: Dynamic creation of control problems

Postby justcode » Fri Jul 17, 2009 5:50 pm

Not sure, but it seems that when you click on the control, it is being activated, but windows is not notified that focus should be set on the control window (CWnd wrapper) and it stays on another control. To solve this I overrode OnMouseActivate() in my derived class and added the following code:

Code: Select all
int CGDViewerCtrl::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)
{
    //TRACE("C_GdViewer::OnMouseActivate() called .... \n");
    int iResult = C_GdViewer::OnMouseActivate(pDesktopWnd, nHitTest, message);
   
    if(iResult == MA_ACTIVATE || iResult == MA_ACTIVATEANDEAT)
    {
        HWND hWndFocus = ::GetFocus();   
        if (hWndFocus != m_hWnd)
            ::SetFocus(m_hWnd);
    }
    return iResult;
}


This will tell Windows to set the keyboard and mouse focus to our wrapper CWnd. You must call the API ::SetFocus and do not call the CWnd::SetFocus(). The CWnd wrapper will just tell the control to activate and it does not notify to the containers window. Calling the Win32 API seems to work correctly. I'm not sure if this is an ActiveX issue or what, but the work around seems to work and I can continue evaluating the control.

-Paul
Paul R. Rondeau
Sr. Software Engineer
MultiProcess Computer Corporation
User avatar
justcode
 
Posts: 24
Joined: Wed Jul 15, 2009 9:20 pm


Return to GdViewer [Pro] ActiveX

Who is online

Users browsing this forum: Bing [Bot] and 1 guest