0

I have created a window and embedding a CAxWindow inside that parent window.

When I create main window I also create CAxWindow window . NOw issue is that I have added WM_WINDOWPOSCHANGING message in my main window and its getting called continuously. Initially its getting called with right coordinate vales but after some time its getting called wit x=0,y=0 , width and height=0.

Any ideas why this is happening?

If I put breakpoint in OnWindowPosChanging, I can see pwp->x=0,pwp->y=0,pwp->cx=0,pwp->cy=0

Here is code

#include <atlbase.h>
#include <atlwin.h>
#include <atlcom.h>
CComModule _Module;

// To create an ATL window, begin by deriving from CWindowImpl<>.
class CMainWindow : public CWindowImpl<CMainWindow, CWindow,
     CWinTraits<WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE, 0 > >
{
public:
     CMainWindow(const RECT rect);
     virtual ~CMainWindow();
     // Enable a table driven WndProc.
     BEGIN_MSG_MAP(CMainWindow)
         MESSAGE_HANDLER(WM_PAINT, OnPaint)
         MESSAGE_HANDLER(WM_MOUSEMOVE,OnMouseMove)
         MESSAGE_HANDLER(WM_SETFOCUS,OnSetFocus)
         MESSAGE_HANDLER(WM_KILLFOCUS,OnKillFocus)
         MESSAGE_HANDLER(WM_CREATE,OnCreate)
         MESSAGE_HANDLER(WM_WINDOWPOSCHANGING, OnWindowPosChanging)
     END_MSG_MAP()
       LRESULT OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
       LRESULT OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
       LRESULT OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
       LRESULT OnKillFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
       LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
       LRESULT OnWindowPosChanging(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);


private:
    CAxWindow m_wndIE;
    RECT m_Rect;
};
LRESULT CMainWindow ::OnWindowPosChanging(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
    WINDOWPOS* pwp= (WINDOWPOS*)lParam;
    if (pwp)
    {
        m_wndIE.SetWindowPos(NULL, pwp->x, pwp->y, pwp->cx, pwp->cy, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOZORDER |SWP_NOCOPYBITS);
    }

    bHandled= FALSE;
    return 0;
}

LRESULT CMainWindow::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
    m_wndIE.Create(m_hWnd, m_Rect, NULL, WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_TABSTOP |WS_BORDER);
    m_wndIE.CreateControl(L"{8856F961-340A-11D0-A96B-00C04FD705A2}", NULL, NULL);


    bHandled = false;
    return 0;
}

// Paint some centered text into the client area.
LRESULT CMainWindow:: OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{

    bHandled = false;
    return 0;
}
// Paint some centered text into the client area.
LRESULT CMainWindow:: OnKillFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{

    bHandled = false;
    return 0;
}
// Paint some centered text into the client area.
LRESULT CMainWindow:: OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
    //MessageBox("OnMouseMove","",MB_OK);
    bHandled = false;
    return 0;
}

// Paint some centered text into the client area.
LRESULT CMainWindow:: OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
     // This example makes use of a number of Win32 API calls.
     // See online help (if necessary).
     PAINTSTRUCT ps;
     BeginPaint(&ps);
     HDC hDC = GetDC();
     RECT r;
     GetClientRect(&r);
     DrawText(hDC, "My ATL Window", -1, &r, DT_SINGLELINE |
             DT_VCENTER | DT_CENTER);
     EndPaint(&ps);
     ReleaseDC(hDC);
     return 0;
}

// Create and destroy this window.
CMainWindow::CMainWindow(const RECT rect)
{
    CopyRect(&m_Rect,&rect);
 //    // Create my window.
    //RECT rc= {10, 10, 200, 200};
 //    Create(NULL, rc, "My ATL Window");
 //    ShowWindow(SW_SHOWNORMAL);
}


CMainWindow::~CMainWindow()
{
    /* if(m_hWnd)
          DestroyWindow();*/
}
//CMainWindow theWind;

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
                PSTR szCommand, int iShow)
{
    _Module.Init(NULL,hInst);
    RECT rect={ 200,200,300,300};
    CMainWindow mw(rect);
    mw.Create(NULL,rect,_T("MyWindow"),
        WS_OVERLAPPEDWINDOW | WS_VISIBLE);

    MSG msg;
    while(GetMessage(&msg,NULL,0,0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }


    _Module.Term();
return 0;
}
anand
  • 11,071
  • 28
  • 101
  • 159
  • Can you show us the code? – David G Oct 08 '13 at 10:53
  • Its part of some project and I cannt share whole code.Let me try to create some sample . – anand Oct 08 '13 at 10:56
  • Check the `flags` member of the `WINDOWPOS` structure - the other members like `x` and `y` aren't always valid/defined. – Jonathan Potter Oct 08 '13 at 11:07
  • It's hard to tell whether you have it right or wrong. You are supposed to keep getting messages as the window is being moved. Infinite messaging would freeze the window, the posted code should however not do that. You are also using wrong HDC in your paint handler. WTL's `CPaintDC` is what you need, not `GetDC()`. – Roman R. Oct 08 '13 at 11:37
  • @Jonatham : how to check validity of flags , I am getting flag value as 67 – anand Oct 08 '13 at 16:21
  • 2
    @Alien01: 67 is equivalent to `SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE` which means `x`/`y`/`width`/`height` are invalid. – Jonathan Potter Oct 08 '13 at 18:33

1 Answers1

1

This line

m_wndIE.SetWindowPos(NULL, pwp->x, pwp->y, pwp->cx, pwp->cy, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOZORDER |SWP_NOCOPYBITS);

looks very suspicious. WM_WINDOWPOSCHANGING is sent to you to allow your window to veto possible moves. Forwarding the message will almost certainly cause your child IE window to move out of the frame.

MSDN has a straightforward description of the flags.

Eric Brown
  • 13,774
  • 7
  • 30
  • 71