ウィンドウを作成し、その親ウィンドウ内に 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;
}