Thread: Problems With CreateDialogParam

  1. #1
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630

    Problems With CreateDialogParam

    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?

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    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.

  3. #3
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    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.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  4. #4
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    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);
    }
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

  5. #5
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    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.
    "only two things are infinite, the universe and human stupidity, and im not sure about the former." - albert einstein

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  4. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 12:17 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 04:35 PM