Ok, Im trying to set up a class that wraps up dialog creation. I want to be able to pass the this pointer so I thought I could use CreateDialogParam but I cant get it to work right. Does any idea how to do this? Or know of any tutorials?
Printable View
Ok, Im trying to set up a class that wraps up dialog creation. I want to be able to pass the this pointer so I thought I could use CreateDialogParam but I cant get it to work right. Does any idea how to do this? Or know of any tutorials?
Where is it failing?
You should be able to:
hDlg=CreateDialogParam(hInst,MAKEINTRESOURCE(IDD_D IALOG),hParent,(DLGPROC)WndProc,(LPARAM)this);
where hInst is app instance, IDD_DIALOG is resource id of dlg, hParent is parent wnd handle, WndProc is static/global wndproc (dlgproc). The this ptr ends up as the lParam passed to WM_INITDIALOG
If you're using a static wndproc, trap WM_INITDIALOG to get the ptr and use SetWindowLong with the DWL_USER flag to store this; for all other msgs use GetWindowLong with the DWL_USER to retrieve this.
This is analagous, but easier, to the process for a 'normal' wnd.
Haha, thats what I was trying to do but it keeps crashing b/c its not getting the this pointer out. I didnt hvae this problem setting up my window class haha. Oh well ill figure this out.
Ok, I dont know what happened but for some reason now the creation of the dialog box fails no matter what! can someone look at this and offer any suggestions:
Code:CModeless::CModeless(const HINSTANCE& hInstance, const HWND& hParent, const int& iDLGID)
: hInst(hInstance), hDlg(NULL), hParentWnd(hParent), iDLGIDNUM(iDLGID), bCreateFailed(false)
{
}
bool CModeless::Create()
{ if(!bCreateFailed)
{ hDlg = ::CreateDialogParam(hInst,
MAKEINTRESOURCE(iDLGIDNUM),
hParentWnd,
&this->DialogProc,
(LPARAM)this);
if(!hDlg)
{ int x = GetLastError();
char array[33];
itoa(x,array,10);
::MessageBox(NULL,array, "LAST ERROR", MB_OK);
bCreateFailed = true;
}
}
return(!bCreateFailed);
// B/C we return false it failed, but bCrateFailed is true if it failed
}
void CModeless::Show(int nShow)
{ ::ShowWindow(hDlg,nShow);
}
Well, I hate replying to this thread again b/c some of u might think im bumping it but im not, i just want to share this info. I dont know why but for some reason the installation of windows im doing this development on is very stubborn, and for some reason, this wouldnt work. Well I got it to all work right by just calling SetLastError(0), and magically it all works now. I wouldnt doubt it if it was a OS problem b/c of all the patches MS releaases that cause more problems with other things.