2013-10-08 1 views
0

J'ai créé une fenêtre et incorporer un CAxWindow à l'intérieur de cette fenêtre parent. Lorsque je crée une fenêtre principale, je crée également une fenêtre CAxWindow. NOw problème est que j'ai ajouté le message WM_WINDOWPOSCHANGING dans ma fenêtre principale et son appel continuellement. Initialement, il est appelé avec des valeurs de coordonnées droites, mais après un certain temps il devient appelé wit x = 0, y = 0, width et height = 0.fenêtre est continuellement WM_WINDOWPOSCHANGING

Des idées pour lesquelles cela se passe?

Si je mets en OnWindowPosChanging point d'arrêt, je peux voir pwp-> x = 0, pwp-> y = 0, pwp-> cx = 0, pwp-> cy = 0

est ici le 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; 
} 
+0

Pouvez-vous nous indiquer le code? – 0x499602D2

+0

Sa partie de certains projets et je ne peux pas partager le code entier.Laissez-moi essayer de créer un échantillon. – anand

+0

Vérifiez le membre 'flags' de la structure' WINDOWPOS' - les autres membres comme 'x' et' y' ne sont pas toujours valides/définis. –

Répondre

1

Cette ligne

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

semble très suspect. WM_WINDOWPOSCHANGING vous est envoyé pour permettre à votre fenêtre d'opposer son veto aux mouvements possibles. La transmission du message provoquera presque certainement la disparition de la fenêtre IE de votre enfant.

MSDN a une description directe des drapeaux.

Questions connexes