Generate Program Code Using MFC

I'm just wondering how to do this. I write:

CEdit m_wndEdit; 

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

 m_wndEdit.Create(//with params); 

but I still don’t see the control appearing in the user interface.

I wrote this in a 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 does not exist. (I used it in the Create function of the CEdit member). I just put it there. shouldn't it be the identifier you want to give to the new control? Should it already exist?

+6
c ++ mfc
source share
3 answers

Take a look at the following set of flags as an example mentioned on MSDN :

  pEdit->Create(ES_MULTILINE | WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_NOHIDESEL | ES_READONLY, rect, this, 105); 
+4
source share
  • Invalidate () is not required

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

  • You create a button in the place where IDC_LIST1 is - you probably want to do pWdn-> Destroy () after GetClientRect ()

  • The identifier that you pass Create () can be anything, of course, if you want to process messages from this button later, you will need to use the correct identifier. In this case, the easiest way is to manually add the entry to the .h resource.

  • What do you mean by β€œI put this code in the button's event handler” - which button? Hope this is different from the one you are trying to create? Does your code get called at all, does it stop when you set a breakpoint? What is the value of wnd_Edit-> m_hWnd after calling Create ()?

  • Is wnd_Edit a member of your dialog, not a local variable of a function?

+4
source share

What is wnd_Edit exactly? If this is a local variable in this function, this is most likely a problem. The CWnd destructor destroys the window associated with CWnd. Therefore, when wnd_Edit goes out of scope, the edit window is also destroyed. If not, check the return value of Create (). Is it null? If so, check the value of GetLastError ().

0
source share

All Articles