用DLL中的函数在主对话框的控件上绘图,如按钮或Static


用DLL中的函数在主对话框的控件上绘图,如按钮或Static
 
对话框按钮响应:

void CTest2Dlg::OnButton4() 
{
typedef void(*pDrawLinePP)(CDC *pDC,CWnd *pWnd,CPoint pt1,CPoint pt2); 
HINSTANCE hDLL; 
pDrawLinePP DrawLine1;

hDLL=LoadLibrary("WBDLL.dll");//加载动态链接库MyDll.dll文件; 

DrawLine1 = (pDrawLinePP)GetProcAddress(hDLL,"DrawLinePP"); 

CDC *pDC;
pDC = GetDlgItem(IDC_BUTTON4)->GetDC();
CPoint pt1,pt2,pt3;

pt1.x = 20;
pt1.y = 0;
pt2.x = 20;
pt2.y = 50;
pt3.x = 60;
pt3.y = 50;

DrawLine1(pDC,this,pt1,pt2);
DrawLine1(pDC,this,pt1,pt3);

pDC = GetDlgItem(IDC_STATIC_FRAME)->GetDC();
DrawLine1(pDC,GetDlgItem(IDC_STATIC_FRAME),pt1,pt2);
DrawLine1(pDC,GetDlgItem(IDC_STATIC_FRAME),pt1,pt3);

FreeLibrary(hDLL);//卸载MyDll.dll文件;
}

用DLL中的函数在主对话框的控件上绘图,如按钮或Static
 
DLL

extern "C" __declspec(dllexport) int TextFun1(int a, int b);
extern "C" __declspec(dllexport) void FunStr(CString str1,CString str2,char * chr);
extern "C" __declspec(dllexport) void DrawLine(CDC *pDC,CDialog *pDlg);
extern "C" __declspec(dllexport) void DrawLinePointToPoint(CDC *pDC,CDialog *pDlg,CPoint pt1,CPoint pt2);
extern "C" __declspec(dllexport) void DrawLinePP(CDC *pDC,CWnd *pWnd,CPoint pt1,CPoint pt2);



void DrawLinePointToPoint(CDC *pDC,CDialog *pDlg,CPoint pt1,CPoint pt2)
{
pDC->MoveTo(pt1);
pDC->LineTo(pt2);
}
//在CWnd对象上绘图
void DrawLinePP(CDC *pDC,CWnd *pWnd,CPoint pt1,CPoint pt2)
{
pDC->MoveTo(pt1);
pDC->LineTo(pt2);
}