[ [ e / p / m / re / hw / sw / hm / r ] b ]

/p/ - Programming

Board zaměřený na programování. Pozor - vyrazím každého kdo tady bude probírat nečisté programovací jazyky :-)
Name
Email
Subject
Comment
File
Embed
Password (For file deletion.)

bc645630 No.4

typedef struct
{
BYTE lv;
WORD w;
WORD h;
HBITMAP* phbmp;
WORD iw;
WORD ih;
WORD ix;
WORD iy;
DWORD id;
DWORD opt;
WCHAR* t;
} CUSTOMMENUITEM, *PCUSTOMMENUITEM, *LPCUSTOMMENUITEM;

HMENU CreateCustomMenu(CUSTOMMENUITEM* cm, WORD n)
{
HMENU hm[CMI_MAXLVL];
hm[0] = CreateMenu();
for(WORD i = 0; i < n; i ++)
{
DWORD s = cm[i].opt | (i + 1 < n && cm[i].lv < cm[i + 1].lv ? MF_POPUP : 0) | (!cm[i].lv || cm[i].opt & CMI_SEPARATOR ? 0 : MF_OWNERDRAW);
if(s & MF_POPUP) hm[cm[i + 1].lv] = CreateMenu(); // vytvorit novou nabidku pri kazdem zvyseni levelu
AppendMenuW(hm[cm[i].lv], s, s & MF_POPUP ? (DWORD)hm[cm[i + 1].lv] : cm[i].id, s & MF_OWNERDRAW ? (WCHAR*)&cm[i] : cm[i].t);
}
return hm[0];
}

INT_PTR CALLBACK MainDlgProc(HWND hdlg, UINT msg, WPARAM wp, LPARAM lp)
{
switch(msg)
{
...
case WM_DRAWITEM:
{ DRAWITEMSTRUCT* pdis = (DRAWITEMSTRUCT*)lp;
CUSTOMMENUITEM* pcmi = (CUSTOMMENUITEM*)(pdis->itemData);
RECT r = pdis->rcItem;
SelectObject(pdis->hDC, GetStockObject(DEFAULT_GUI_FONT));
SetBkMode(pdis->hDC, TRANSPARENT);
FillRect(pdis->hDC, &r, GetSysColorBrush(pdis->itemState & ODS_SELECTED ? COLOR_HIGHLIGHT : COLOR_3DFACE));
SetTextColor(pdis->hDC, GetSysColor(pdis->itemState & ODS_GRAYED ? COLOR_GRAYTEXT : pdis->itemState & ODS_SELECTED ? COLOR_HIGHLIGHTTEXT : COLOR_BTNTEXT));
SetBkColor(pdis->hDC, GetSysColor(pdis->itemState & ODS_SELECTED ? COLOR_HIGHLIGHT : COLOR_3DFACE));

HDC cdc = CreateCompatibleDC(pdis->hDC);
SelectObject(cdc, *pcmi->phbmp);
TransparentBlt(pdis->hDC, cmi->iw / 8, r.top + (r.bottom - r.top - cmi->ih + 1) / 2, pcmi->iw, pcmi->ih, cdc, pcmi->ix, pcmi->iy, pcmi->iw, pcmi->ih, 0x0FF00FF);
DeleteDC(cdc);

r.left += cmi->iw + cmi->iw / 4;
if(pcmi->opt & (CMI_CHECKBOX | CMI_RADIOBTN))
{
RECT rgly = {0, 0, GetSystemMetrics(SM_CXMENUCHECK), GetSystemMetrics(SM_CYMENUCHECK)};
if(pdis->itemState & ODS_CHECKED)
{
HDC cdc = CreateCompatibleDC(pdis->hDC);
HBITMAP bmp = CreateCompatibleBitmap(cdc, rgly.right, rgly.bottom);
SelectObject(cdc, bmp);
DrawFrameControl(cdc, &rgly, DFC_MENU, pcmi->opt & CMI_RADIOBTN ? DFCS_MENUBULLET : DFCS_MENUCHECK);
BitBlt(pdis->hDC, r.left, r.top + (r.bottom - r.top - rgly.bottom + 1) / 2, r.right, r.bottom, cdc, 0, 0, SRCCOPY);
DeleteObject(bmp);
DeleteDC(cdc);
}
r.left += rgly.right + rgly.right / 4;
}
if(pcmi->t)
{
TEXTMETRICA tm;
GetTextMetricsA(pdis->hDC, &tm);
r.top += (r.bottom - r.top - tm.tmHeight) / 2;
DrawTextW(pdis->hDC, pcmi->t, -1, &r, DT_LEFT);
}
break;
} default:
return 0;
}
return 1;
}

bc645630 No.6

>>4
test



[Return][Go to top] [Catalog] [Post a Reply]
[ [ e / p / m / re / hw / sw / hm / r ] b ]