Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Having trouble dynamically creating a new CDialog object.

FlackFlack Member Posts: 88
[b][red]This message was edited by Flack at 2003-4-25 12:30:15[/red][/b][hr]
Hello,

I have a MFC dialog app that I created with VC++ AppWizard.
Now, from my original dialog box, I want to create a new one, which appears as a separate popup. However, the code I have does not work (probably because it's totally wrong).

Anyway, here is the code (this code is in a function I call when a button is pushed):
[code]
DLGTEMPLATE myTemplate;
myTemplate.style = WS_POPUP|WS_VISIBLE|LBS_STANDARD;
myTemplate.dwExtendedStyle = NULL,
myTemplate.cdit = 0;
myTemplate.x = 10;
myTemplate.y = 10;
myTemplate.cx = 100;
myTemplate.cy = 100;

int nBufferSize = sizeof(DLGTEMPLATE);
HLOCAL hLocal = LocalAlloc(LHND, nBufferSize);
BYTE* pBuffer = (BYTE*)LocalLock(hLocal);
BYTE* pdest = pBuffer;

// transfer DLGTEMPLATE structure to the buffer
memcpy(pdest, &myTemplate, sizeof(DLGTEMPLATE));

CDialog myDialog;
myDialog.InitModalIndirect((DLGTEMPLATE*)pbuffer);
[red]myDialog.DoModal();[/red]

LocalUnlock(hLocal);
LocalFree(hLocal);
[/code]

Now, the InitModalIndirect returns a nonzero value,indicating that the dialog object was created and initialized successfully. However, the line myDialog.DoModal()(red line) returns a -1 indicating failure. Does anyone know what I am doing wrong?

My goal is to eventually have a separate dialog popup that contains a list box but I can't even get an empty dialog window to appear.

Thanx for the help,
-Flack


Comments

  • goodbettgoodbett Member Posts: 6

    the key error is located in this function
    myDialog.InitModalIndirect((DLGTEMPLATE*)pbuffer);
    the first argument of this function should be the type of HGlOBAL(a handle),but you put a pointer there,So it should be like this:
    myDialog.InitModalIndirect(hLocal);

Sign In or Register to comment.