我在界面相隔挺远的位置添加2个mfc控件,
需要添加:
1. 添加 CMfcWndUI 类,这是为了调用mfc控件用的
2. 添加 duilib界面 CDuiFrameWnd
3.重写 2中界面的virtual CControlUI* CreateControl(LPCTSTR pstrClassName); 函数
需要注意的地方:
1. 需要先在xlm上有对应的控件 MyWin32Wnd MyMfcWnd为对应的类名
<MyWin32Wnd name="btnMfc" text="MFC Button" float="true" pos="39,202,199,232" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file='button_nor.bmp' corner='4,2,4,2' fade='200' hsl='true'" hotimage="file='button_over.bmp' corner='4,2,4,2' fade='200' hsl='true'" pushedimage="file='button_down.bmp' corner='4,2,4,2' fade='200' hsl='true' " />
<MyMfcWnd name="btnMfc" text="MFC Button" float="true" pos="200,202,350,232" textcolor="#FF000000" disabledtextcolor="#FFA7A6AA" align="center" normalimage="file='button_nor.bmp' corner='4,2,4,2' fade='200' hsl='true'" hotimage="file='button_over.bmp' corner='4,2,4,2' fade='200' hsl='true'" pushedimage="file='button_down.bmp' corner='4,2,4,2' fade='200' hsl='true' " />
2.CControlUI* CDuiFrameWnd::CreateControl(LPCTSTR pstrClassName)中
pstrClassName 为xml中类名
3.m_pButton->Create( WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, CRect(0, 0, 0, 0), CWnd::FromHandle(m_PaintManager.GetPaintWindow()), MFC_BUTTON_ID);
中create中 CRect的参数为 左上右下,不同控件,修改CRect的位置。
4. #define MFC_BUTTON_ID 8001
添加宏定义
参考:MFC与duilib之间控件相互调用_mfc程序调用duilib_byxdaz的博客-CSDN博客https://blog.csdn.net/byxdaz/article/details/72862013?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522168550959016782425133423%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=168550959016782425133423&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-6-72862013-null-null.142%5Ev88%5Econtrol_2,239%5Ev2%5Einsert_chatgpt&utm_term=duilib%E4%B8%AD%E4%BD%BF%E7%94%A8%20mfc%20%20%E6%8E%A7%E4%BB%B6&spm=1018.2226.3001.4187