I had hoped to do it without using DialogBox(), because it would mean I needed to redo most of my SearchDialog class :/. Ah well, it needs to be a child because the dialog needs to bedestroyed/hidden/shown depending on what messages it was sent by the main window, which I assume means it needs to be considered a child window.
How would I retrieve the handle from a dialog box? From what I have been reading on msdn, DialogBox returns the result of the dialog rather than a HWND.
EDIT: Is there any functional difference between WM_CREATE and WM_INITDIALOG? From what I have seen some people use one in the place of the other.
EDIT 2 : Bah! Can't get it working, I decided to use CreateDialogParam() since I need the dialog to be modeless and DialogBox() only creates Modal. However it seems that I can't convert the this pointer from my class to the special type of LPARAM that CreateDialogParam() requires (Despite the fact that it works for CreateWindowEx, when it is passed a the LPARAM).
It seems half of the problem is that even when I typecast the this pointer as an LPARAM it doens't actually send anything (The lParam argument of my static DialogProc is 0) and I can't use CREATESTRUCT's to store the pointer since it's no longer a normal window.
EDIT 3 : It seems that what happens is, while running through it's message loop it comes across a piece of data that
looks like the SearchDialog class, so it tries to call the classes DialogProc function.... Only for a read/write error to pop up crashing the program.
I have no clue how to fix this at this point, I was using a snippit of code from a website
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
LRESULT CALLBACK CWindow::StaticWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
CWindow* pParent;
// Get pointer to window
if(uMsg == WM_CREATE)
{
pParent = (CWindow*)((LPCREATESTRUCT)lParam)->lpCreateParams;
SetWindowLongPtr(hWnd,GWL_USERDATA,(LONG_PTR)pParent);
}
else
{
pParent = (CWindow*)GetWindowLongPtr(hWnd,GWL_USERDATA);
if(!pParent) return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
pParent->m_hWnd = hWnd;
return pParent->WndProc(uMsg,wParam,lParam);
}
LRESULT CWindow::WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
// Normal code here
}
// Call default window proc if we haven't handled the message
return DefWindowProc(m_hWnd,uMsg,wParam,lParam);
}
|
(From
http://www.gamedev.net/community/forums/topic.asp?topic_id=303854 )
And I will admit that I have little to no idea how exactly it works. For example, I have no idea how it gets the this pointer by just type casting a LPCREATESTRUCT into a pointer to the class.
I understand the SetWindowLong() which is what I think may be one of the things causing the problem, since LPARAM's are only 16 bits long, because I am having to type cast the this pointer to an LPARAM I am cutting off half of the pointer(I think). No idea how to fix it however.