ورود

View Full Version : عدم کار کردن SetDCPenColor در پروژه



ShahinRad97
دوشنبه 04 اسفند 1393, 07:38 صبح
سلام.
مشکل چیه که رنگ این خط همش مشکیه و تغییر نمیکنه؟


UpdateData(true);
CClientDC cd(this);
HDC hdc=cd.GetSafeHdc();
SetDCPenColor(hdc,RGB(255,0,0));

cd.MoveTo(30,70);
cd.LineTo(200,115);

UpdateData(false);

این کد رو داخل تابع OnPaint دیالگ نوشتم
یعنی الان به این صورت هست:

void CAdamakDlg::OnPaint()
{
UpdateData(true);
CClientDC cd(this);
HDC hdc=cd.GetSafeHdc();
SetDCPenColor(hdc,RGB(255,0,0));

cd.MoveTo(30,70);
cd.LineTo(200,115);

UpdateData(false);
if (IsIconic())
{

CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}

That feels so good
دوشنبه 14 اردیبهشت 1394, 12:18 عصر
به جای دو دستور


HDC hdc=cd.GetSafeHdc();
SetDCPenColor(hdc,RGB(255,0,0));


دو دستور زیر را اضافه کنید


CPen pen(PS_SOLID,1,RGB(255,0,0));
cd.SelectObject(&pen);