cjustas
asked on
Create new control from MFC dll
I have application (MFC based) that loads dlls and calls specific methods. In one of those methods, I want to create CEdit control on that applications one of windows.
1) I'm getting handle of parent window
2) Create new CEdit object and call CreateEx with obtained parent CWnd
3) At this point control is visible in application it self but then application freezes and do not accept any input.
I'm thinking its something to do with message handle on parent window, as I create control at runtime from dll. Is there any way to solve this?
Pseudo code of one of external dll methods:
Long story short, I would like to inject/create completely new MFC control (CEdit) in to application (which I don't have control of) from my custom DLL without crashing application and receiving and handling messages as normal CEdit control.
Thank you.
1) I'm getting handle of parent window
2) Create new CEdit object and call CreateEx with obtained parent CWnd
3) At this point control is visible in application it self but then application freezes and do not accept any input.
I'm thinking its something to do with message handle on parent window, as I create control at runtime from dll. Is there any way to solve this?
Pseudo code of one of external dll methods:
extern "C" VOID PASCAL EXPORT AddEditBox(HWND hWnd)
{
CWnd *hmain = CWnd::FromHandle(hWnd); //I've checked and hmain is CORRECT CWnd Object, I can do other manipulations with it (like resizing etc.)
if(hmain != NULL) {
m_edit = new CEdit;
m_edit->CreateEx(WS_EX_CLIENTEDGE, _T("EDIT"), _T(""),
WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER,
CRect(0, 0, 60, 20), hmain, 1);
}
}
Long story short, I would like to inject/create completely new MFC control (CEdit) in to application (which I don't have control of) from my custom DLL without crashing application and receiving and handling messages as normal CEdit control.
Thank you.
ASKER
I'm sorry I forgot to add this, but in my code this line is already there, I just cleaned it out when I was removing unrelated code from pseudo code example. With this line is behaving same as described in initial post.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window