Visual C++

Control  button

kreirati Dialog based aplikaciju i dodati jedno dugme (button), kao na slici:

dugme1  dugme6

klasi:CkontroladugmeDlg dodati dvije promjenjive:

dugme2      dugme3    1. bool  dugme   i druga    2. UINT  vreme

Koristeci Class Wizard dodati tri poruke: WM_DRAWITEM, WM_MOUSEMOVE  i  WM_TIMER

dugme4   dugme5   svakoj funkciji dopisati kod:

void CkontroladugmeDlg::OnMouseMove(UINT nFlags, CPoint point)
{
if (!dugme)
{
TRACE0(“Entering control\n”);
dugme = TRUE;
Invalidate();
SetTimer(vreme, 100, NULL);
}

void CkontroladugmeDlg::OnTimer(UINT_PTR nIDEvent)
{
CPoint s1(GetMessagePos());
ScreenToClient(&s1);
CRect rect;
GetClientRect(rect);
if (!rect.PtInRect(s1))
{
TRACE0(“Leaving control\n”);
dugme = FALSE;
KillTimer(vreme);
Invalidate();
}

void CkontroladugmeDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
CRect rect = lpDrawItemStruct->rcItem;
UINT state = lpDrawItemStruct->itemState;

CString strText;
GetWindowText(strText);
if (state & ODS_SELECTED)
pDC->DrawFrameControl(rect, DFC_BUTTON, DFCS_BUTTONPUSH | DFCS_PUSHED);
else
pDC->DrawFrameControl(rect, DFC_BUTTON, DFCS_BUTTONPUSH);
rect.DeflateRect( CSize(GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE)));
if (dugme)
pDC->FillSolidRect(rect, RGB(0, 255, 255));
if (!strText.IsEmpty())
{
CSize Extent = pDC->GetTextExtent(strText);
CPoint pt( rect.CenterPoint().x – Extent.cx/2,
rect.CenterPoint().y – Extent.cy/2 );
if((state & ODS_SELECTED))
{
pDC->DrawEdge(&rect,EDGE_SUNKEN,BF_RECT);
pt.Offset(1,1);

}
else
{
pDC->DrawEdge(&rect,EDGE_RAISED,BF_RECT);
pt.Offset(1,1);
}
}
TCHAR buffer[MAX_PATH];
ZeroMemory(buffer,MAX_PATH );
::GetWindowText(lpDrawItemStruct->hwndItem,buffer,MAX_PATH);
pDC->DrawText(buffer,&rect,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
pDC->Detach();
CDialogEx::OnDrawItem(nIDCtl, lpDrawItemStruct);
}

rezultat izvrsenja programa je:

dugme7 a kada misem predjemo preko aplikacije:dugme8       exe primer

 

 

Upotreba kontrole: SysLink control         link kontrola sl   u visual c++ 

U kreiranu dialog based aplikaciju dodati kontrolu SysLink:

sl link1 kontroli SysLink dodati kontrolnu promjenjivu : m_link

funkciji OnInitDialog() dodati sledeci kod:

m_link.SetWindowTextW(L”Na ovoj stranici je detaljan prikaz: <a href=\”https://dragana7591.wordpress.com/\”> ocjena za skol.2014/2015</a>”);

kontroli SysLink dodati funkciju:

void CkontrolalinkDlg::OnNMClickSyslink1(NMHDR *pNMHDR, LRESULT *pResult)
{
PNMLINK pNMLink = (PNMLINK) pNMHDR;

if (wcscmp(pNMLink->item.szUrl, _T(“https://dragana7591.wordpress.com/&#8221;)) == 0)
{
ShellExecuteW(NULL, L”open”, pNMLink->item.szUrl, NULL, NULL, SW_SHOWNORMAL);
}
*pResult = 0;

}

sl link2      video primjer  sl link3

 

 

 

Vježbe

vjezbe

 

kontrola dugme

dugme

Upotreba kontrole Rich Edit u SDI, MDI ili Dialog based aplikacijama

richedit

radno okruženje

okruzenje

Upotreba Scroll Bar kontrole

Picture1

Komentariši

Upišite vaše podatke ispod ili kliknite na jednu od ikona da se prijavite:

WordPress.com logo

You are commenting using your WordPress.com account. Odjava / Promijeni )

Twitter slika

You are commenting using your Twitter account. Odjava / Promijeni )

Facebook fotografija

You are commenting using your Facebook account. Odjava / Promijeni )

Google+ photo

You are commenting using your Google+ account. Odjava / Promijeni )

Povezivanje na %s