我创建了一个窗口并在该父窗口中嵌入了一个 CAxWindow。
当我创建主窗口时,我还创建 CAxWindow window 。现在的问题是我在我的主窗口中添加了 WM_WINDOWPOSCHANGING 消息并且它被连续调用。最初它以正确的坐标值被调用,但一段时间后它被称为机智 x=0,y=0 ,宽度和高度=0。
任何想法为什么会发生这种情况?
如果我在 OnWindowPosChanging 中设置断点,我可以看到 pwp->x=0,pwp->y=0,pwp->cx=0,pwp->cy=0
这是代码
#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;
}