tags:

views:

642

answers:

3

Hello guyz,

I just wonder how to do it. I write :

CEdit m_wndEdit;

and in the button event handler (dialog app), I write :

m_wndEdit.Create(//with params);

but I still don't see the control appear in the UI.

help.

I actually wrote this in the button handler :

CWnd* pWnd = GetDlgItem(IDC_LIST1);
CRect rect;

pWnd->GetClientRect(&rect);

//pWnd->CalcWindowRect(rect,CWnd::adjustBorder);

wnd_Edit.Create(ES_MULTILINE | ES_NOHIDESEL | ES_READONLY,rect,this,105);

wnd_Edit.ShowWindow(SW_SHOW);

this->Invalidate();

id 105 doesn't exist. (I used it in the Create member function of CEdit). I just put it in there. isn't it supposed to be the id you want to give to the new control ? should it already exist ?

+3  A: 

Check with the following set of flags as the example mentioned in MSDN:

   pEdit->Create(ES_MULTILINE | WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_NOHIDESEL | ES_READONLY,
      rect, this, 105);
Naveen
A: 

What is wnd_Edit exactly? If it's a local variable in that function, that is likely the problem. The CWnd destructor destroys the window associated with the CWnd. So when wnd_Edit goes out of scope, the edit box is destroyed too. If that's not it, check the return value of Create(). Is it NULL? If it is, check the value of GetLastError().

Michael Dunn
+2  A: 
  • The Invalidate() is not necessary

  • Add the WS_VISIBLE flag to your create flags, you don't need the ShowWindow

  • You are creating the button on the location where IDC_LIST1 is - you probably want to do pWdn->Destroy() after the GetClientRect()

  • The id you pass to Create() can be anything, of course if you want to handle messages from this button later you'll need to use the correct id. In that case it's easiest to manually add an entry to resource.h.

  • What do you mean with 'I put this code in the button event handler' - which button? A different one from the one you're trying to create, I may hope? Does your code get called at all, does it stop when you put a breakpoint in? What's the value of wnd_Edit->m_hWnd after the call to Create()?

  • wnd_Edit is a member of your dialog, right, and not a a function local variable?

Roel
One more thing, you're missing the WS_CHILD flag. Try with only WS_CHILD | WS_VISIBLE, those are the only two flags you really need for any control.
Roel