Jump to content
  • Advertisement
Sign in to follow this  
MindWipe

Setting the window long in a static winproc for the MDI Child?

This topic is 5473 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hope the subject didn't scare you away. So I have a class for my child in using MDI. But I have no idea where to register the class pointer. In a regual window you casted the 'this' pointer to (void*) and set that to the last variable in CreateWindow. How do I do it for the child!? This doesn't work:

void EMapChildWindow::Create( HINSTANCE hInstance, HWND hWndFrame, HWND hWndMain )
{
	static bool bClassRegistered = false;

	m_hInst = hInstance;
    m_hWndFrame = hWndFrame;
	m_hWndMain = hWndMain;

	if(!bClassRegistered)
	{
		WNDCLASSEX wcex;

		wcex.cbSize			= sizeof(WNDCLASSEX); 

		wcex.style			= CS_HREDRAW | CS_VREDRAW;
		wcex.lpfnWndProc	= (WNDPROC)StaticProc;
		wcex.cbClsExtra		= 0;
		wcex.cbWndExtra		= 0;
		wcex.hInstance		= m_hInst;
		wcex.hIcon			= LoadIcon(m_hInst, /*(LPCTSTR)IDI_MAIN*/NULL);
		wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
		wcex.hbrBackground	= (HBRUSH)(COLOR_3DFACE+1);
		wcex.lpszMenuName	= TITLE;
		wcex.lpszClassName	= CHILDWND_CLASS_NAME;
		wcex.hIconSm		= LoadIcon(wcex.hInstance, /*(LPCTSTR)IDI_SMALL*/NULL);

		RegisterClassEx(&wcex);
		bClassRegistered = true;
	}



	m_hWnd = CreateMDIWindow(CHILDWND_CLASS_NAME,"[Untitled]",MDIS_ALLCHILDSTYLES,
								CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
								m_hWndFrame,m_hInst,(LPARAM)this);


	
	if(!m_hWnd)
	{
		MessageBox(m_hWndFrame, "MDI Child creation failed.", "Error!",
			MB_ICONEXCLAMATION | MB_OK);
	}

	ShowWindow(m_hWnd,SW_SHOWDEFAULT);



}


LRESULT CALLBACK EMapChildWindow::StaticProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static EMapChildWindow* pThis = NULL;
	


    if (message == WM_NCCREATE) 
    {
        LPCREATESTRUCT Cs;
        Cs = (LPCREATESTRUCT)lParam;
        pThis = (EMapChildWindow *)Cs->lpCreateParams;
        SetWindowLong(hWnd, GWL_USERDATA, reinterpret_cast<LONG>(pThis));
    }


	pThis = (EMapChildWindow *)GetWindowLong( hWnd, GWL_USERDATA );


	if (pThis != NULL)
		return pThis->Proc(hWnd, message, wParam, lParam);
	
	
	return DefMDIChildProc(hWnd, message, wParam, lParam);
	
}

I thought I could do SetWindowLong just after the MDI Child window's creation, but I heard you shouldn't!? /MindWipe

Share this post


Link to post
Share on other sites
Advertisement
Hello,

Do CreateMDIWindow() generates a WM_CREATE or a WM_MDICREATE message ? if it generates both or only the later then you should consider using it (because your casted "this" pointer is probably lying in the MDICREATESTRUCT structure, not in the CREATESTRUCT).

HTH,

Share this post


Link to post
Share on other sites
Quote:
Original post by Emmanuel Deloget
Hello,

Do CreateMDIWindow() generates a WM_CREATE or a WM_MDICREATE message ? if it generates both or only the later then you should consider using it (because your casted "this" pointer is probably lying in the MDICREATESTRUCT structure, not in the CREATESTRUCT).

HTH,


Oh, good point. Gotta look into that. Thanks!

You_Sir.ratings++;

/MindWipe

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!