#include <Windows.h>
#include <hbapi.h>
BOOL bStrAt( BYTE bChar, LPSTR szText );
HBITMAP CreateMemBitmap( HDC hDC, LPSTR cBitmap );
void pascal DelResource( HANDLE hResource );
void DrawGrayed( HDC, HBITMAP, int, int );
void DrawMasked( HDC, HBITMAP, WORD, WORD );
void Gradient( HDC hDC, RECT * rct, COLORREF crStart, COLORREF crEnd, BOOL bVertical );
BOOL HB_ISDIBitmap( LPDRAWITEMSTRUCT lpdis );
long RoundBox( HDC hDC, int iLeft, int iTop, int iRight,
int iBottom, int iRound1, int iRound2, COLORREF lColor, long lPenSize );
void RegisterResource( HANDLE hResource, LPSTR szType );
LPSTR StrToken( LPSTR szText, WORD wOcurrence, BYTE bSeparator, LPWORD pwLen );
typedef struct _SKIN_MENU
{
long clr_gradBar1_1; //first gradient bar colors
long clr_gradBar1_2; //second gradient bar colors
long clr_gradBar2_1; //first gradient bar colors
long clr_gradBar2_2; //second gradient bar colors
long clr_leftSide; // left side color
long clr_rightSide; // right side color
long clr_vertical1;
long clr_vertical2;
long clr_box;
long clr_gradSelected1_1;
long clr_gradSelected1_2;
long clr_gradSelected2_1;
long clr_gradSelected2_2;
long clr_textGrayed;
long clr_gradGrayed1_1;
long clr_gradGrayed1_2;
long clr_gradGrayed2_1;
long clr_gradGrayed2_2;
long clr_boxGrayed;
BYTE * byteChecked;
enum fw_SKIN skin;
int roundSize;
BOOL bdrawGrayed;
} SKIN_MENU;
static HBITMAP hBmpCheck2015 = NULL;
static SKIN_MENU skinMenu;
HBITMAP Check2015( HDC hDC, BYTE * byteImg ) // ( hDC ) --> hBitmap
{
if( hBmpCheck2015 == NULL )
hBmpCheck2015 = CreateMemBitmap( hDC, ( LPSTR ) byteImg );
return hBmpCheck2015;
}
void DelCheck2015( void )
{
if( hBmpCheck2015 != NULL )
{
DelResource( hBmpCheck2015 );
DeleteObject( hBmpCheck2015 );
DelResource( hBmpCheck2015 );
hBmpCheck2015 = NULL;
}
}
HB_FUNC( DELCHECK2015 )
{
DelCheck2015();
}
HB_FUNC( MENUDRAW2015 ) // ( pDrawItemStruct, cPrompt, hTopMenu, hBitmap, hWnd )
{
#ifndef _WIN64
HMENU hTopMenu = ( HMENU ) hb_parnl( 3 );
HBITMAP hBmp = ( HBITMAP ) hb_parnl( 4 );
HWND hWnd = ( HWND ) hb_parnl( 5 );
LPDRAWITEMSTRUCT lpdis = ( LPDRAWITEMSTRUCT ) hb_parnl( 1 );
#else
HMENU hTopMenu = ( HMENU ) hb_parnll( 3 );
HBITMAP hBmp = ( HBITMAP ) hb_parnll( 4 );
HWND hWnd = ( HWND ) hb_parnll( 5 );
LPDRAWITEMSTRUCT lpdis = ( LPDRAWITEMSTRUCT ) hb_parnll( 1 );
#endif
LPSTR szPrompt = ( LPSTR ) hb_parc( 2 );
BOOL bTab = bStrAt( 9, szPrompt );
WORD wLen;
HPEN hNormal;
HBRUSH hBrush, holdBrush;
LOGBRUSH lb;
RECT rct;
UINT uFormat;
LONG top, left, bottom, right;
HRGN hReg;
HDC hdcMem;
HBITMAP hbmp, holdBmp;
static BOOL bVista = FALSE;
if( ! hBmpCheck2015 )
{
OSVERSIONINFO vi;
Check2015( lpdis->hDC, skinMenu.byteChecked );
ZeroMemory( &vi, sizeof( OSVERSIONINFO ) );
vi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
GetVersionEx( &vi );
if( vi.dwMajorVersion == 6 ) // Vista
bVista = TRUE;
}
hReg = CreateRoundRectRgn( lpdis->rcItem.left, lpdis->rcItem.top, lpdis->rcItem.right, lpdis->rcItem.bottom, skinMenu.roundSize, skinMenu.roundSize );
SetWindowRgn( lpdis->hwndItem, hReg, FALSE );
DeleteObject( hReg );
switch( lpdis->itemAction )
{
case ODA_DRAWENTIRE:
case ODA_SELECT:
if( hTopMenu == ( HMENU ) lpdis->hwndItem && ! ( lpdis->itemState & ODS_SELECTED ) )
{
POINT pt;
GetClientRect( ( HWND ) hWnd, &rct );
// Gradient for top menu
top = lpdis->rcItem.top;
bottom = lpdis->rcItem.bottom;
right = lpdis->rcItem.right;
if( GetPixel( lpdis->hDC, lpdis->rcItem.right + 2, lpdis->rcItem.top ) != RGB( 254, 254, 255 ) &&
GetPixel( lpdis->hDC, lpdis->rcItem.right + 2, lpdis->rcItem.top ) != RGB( 255, 255, 255 ) &&
GetPixel( lpdis->hDC, lpdis->rcItem.right + 2, lpdis->rcItem.top ) != RGB( 255, 248, 255 ) &&
GetPixel( lpdis->hDC, lpdis->rcItem.right + 2, lpdis->rcItem.top ) != RGB( 239, 240, 240 ) &&
GetPixel( lpdis->hDC, lpdis->rcItem.right + 2, lpdis->rcItem.top ) != RGB( 245, 254, 255 ) )
lpdis->rcItem.right = rct.right + 3 + ( bVista ? 5 : 0 );
lpdis->rcItem.bottom = lpdis->rcItem.top + 8;
Gradient( lpdis->hDC, &lpdis->rcItem, skinMenu.clr_gradBar1_1, skinMenu.clr_gradBar1_2, TRUE );
lpdis->rcItem.top = lpdis->rcItem.bottom + 1;
lpdis->rcItem.bottom = bottom;
Gradient( lpdis->hDC, &lpdis->rcItem, RGB( 212, 219, 237 ), RGB( 225, 230, 246 ), TRUE );
lpdis->rcItem.top = top;
// bottom lines
lb.lbStyle = BS_SOLID;
lb.lbColor = RGB( 182, 188, 204 );
hBrush = CreateBrushIndirect( &lb );
rct.top = lpdis->rcItem.bottom - 1;
rct.left = lpdis->rcItem.left;
rct.bottom = lpdis->rcItem.bottom;
rct.right = lpdis->rcItem.right;
FillRect( lpdis->hDC, &rct, hBrush );
DeleteObject( hBrush );
lb.lbStyle = BS_SOLID;
lb.lbColor = bVista ? RGB( 240, 240, 240 ) : RGB( 255, 255, 255 );
hBrush = CreateBrushIndirect( &lb );
rct.top = lpdis->rcItem.bottom;
rct.bottom = lpdis->rcItem.bottom + 1;
FillRect( lpdis->hDC, &rct, hBrush );
DeleteObject( hBrush );
lpdis->rcItem.right = right;
}
if( lpdis->itemState & ODS_SELECTED )
{
if( ! ( lpdis->itemState & ODS_GRAYED ) || skinMenu.bdrawGrayed )
{
int iWidth, iHeight;
long lGrad1_1;
long lGrad1_2;
long lGrad2_1;
long lGrad2_2;
long lbox;
if( skinMenu.bdrawGrayed && ( lpdis->itemState & ODS_GRAYED ) ){
lGrad1_1 = skinMenu.clr_gradGrayed1_1;
lGrad1_2 = skinMenu.clr_gradGrayed1_2;
lGrad2_1 = skinMenu.clr_gradGrayed2_1;
lGrad2_2 = skinMenu.clr_gradGrayed2_2;
lbox = skinMenu.clr_boxGrayed;
}else {
lGrad1_1 = skinMenu.clr_gradSelected1_1;
lGrad1_2 = skinMenu.clr_gradSelected1_2;
lGrad2_1 = skinMenu.clr_gradSelected2_1;
lGrad2_2 = skinMenu.clr_gradSelected2_2;
lbox = skinMenu.clr_box;
}
iWidth = lpdis->rcItem.right - lpdis->rcItem.left;
iHeight = lpdis->rcItem.bottom - lpdis->rcItem.top;
rct.top = 0;
rct.left = 0;
rct.bottom = iHeight;
rct.right = iWidth;
hdcMem = CreateCompatibleDC( lpdis->hDC );
hbmp = CreateCompatibleBitmap( lpdis->hDC, iWidth, iHeight );
holdBmp = ( HBITMAP ) SelectObject( hdcMem, hbmp );
bottom = rct.bottom;
rct.bottom = iHeight / 2;
Gradient( hdcMem, &rct, lGrad1_1, lGrad1_2, TRUE );
top = rct.top;
rct.top = rct.bottom + 1;
rct.bottom = bottom;
rct.bottom--;
Gradient( hdcMem, &rct, lGrad2_1, lGrad2_2, TRUE );
rct.top = top;
rct.bottom++;
lb.lbStyle = BS_PATTERN;
lb.lbHatch = ( ULONG_PTR ) hbmp;
hBrush = CreateBrushIndirect( &lb );
SetBrushOrgEx( lpdis->hDC, 0, lpdis->rcItem.top, NULL );
holdBrush = ( HBRUSH ) SelectObject( lpdis->hDC, hBrush );
BeginPath( lpdis->hDC );
RoundBox( lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top, lpdis->rcItem.right,
lpdis->rcItem.bottom, skinMenu.roundSize, skinMenu.roundSize, lbox, 1 );
EndPath( lpdis->hDC );
FillPath( lpdis->hDC );
RoundBox( lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top, lpdis->rcItem.right,
lpdis->rcItem.bottom, skinMenu.roundSize, skinMenu.roundSize, lbox, 1 );
SelectObject( lpdis->hDC, holdBrush );
SelectObject( hdcMem, holdBmp );
DeleteObject( hBrush );
DeleteObject( hbmp );
DeleteDC( hdcMem );
}
}
else
{
if( hTopMenu != ( HMENU ) lpdis->hwndItem )
{
// Draw left side
lb.lbStyle = BS_SOLID;
lb.lbColor = skinMenu.clr_leftSide;
hBrush = CreateBrushIndirect( &lb );
right = lpdis->rcItem.right;
lpdis->rcItem.right = lpdis->rcItem.left + 24;
FillRect( lpdis->hDC, &lpdis->rcItem, hBrush );
lpdis->rcItem.right = right;
DeleteObject( hBrush );
// Clean right side
lb.lbColor = skinMenu.clr_rightSide;
hBrush = CreateBrushIndirect( &lb );
left = lpdis->rcItem.left;
if( hTopMenu != ( HMENU ) lpdis->hwndItem )
lpdis->rcItem.left += 25;
FillRect( lpdis->hDC, &lpdis->rcItem, hBrush );
lpdis->rcItem.left = left;
DeleteObject( hBrush );
// Draw vertical line1
lb.lbStyle = BS_SOLID;
lb.lbColor = skinMenu.clr_vertical1;
hBrush = CreateBrushIndirect( &lb );
rct.top = lpdis->rcItem.top;
rct.left = lpdis->rcItem.left + 24;
rct.bottom = lpdis->rcItem.bottom;
rct.right = lpdis->rcItem.left + 25;
FillRect( lpdis->hDC, &rct, hBrush );
DeleteObject( hBrush );
// Draw vertical line2
lb.lbColor = skinMenu.clr_vertical2;
hBrush = CreateBrushIndirect( &lb );
rct.top = lpdis->rcItem.top;
rct.left = lpdis->rcItem.left + 25;
rct.bottom = lpdis->rcItem.bottom;
rct.right = lpdis->rcItem.left + 26;
FillRect( lpdis->hDC, &rct, hBrush );
DeleteObject( hBrush );
}
}
if( lpdis->itemState & ODS_CHECKED )
DrawMasked( lpdis->hDC, hBmpCheck2015, ( WORD ) lpdis->rcItem.top, ( WORD ) ( lpdis->rcItem.left + 1 ) );
if( hBmp )
{
if( ! ( lpdis->itemState & ODS_CHECKED ) )
DrawMasked( lpdis->hDC, hBmp, ( WORD ) ( lpdis->rcItem.top + 2 ),
( WORD ) ( lpdis->rcItem.left + 4 ) );
else
if( ! ( lpdis->itemState & ODS_SELECTED ) )
DrawGrayed( lpdis->hDC, hBmp, lpdis->rcItem.top + 1,
lpdis->rcItem.left + 1 );
else
DrawMasked( lpdis->hDC, hBmp, ( WORD ) ( lpdis->rcItem.top + 1 ),
( WORD ) ( lpdis->rcItem.left + 1 ) );
}
lpdis->rcItem.top += 2;
if( hTopMenu != ( HMENU ) lpdis->hwndItem )
{
uFormat = DT_LEFT;
lpdis->rcItem.left += 33;
}
else
uFormat = DT_CENTER;
SetBkMode( lpdis->hDC, TRANSPARENT );
if( lpdis->itemState & ODS_GRAYED )
SetTextColor( lpdis->hDC, skinMenu.clr_textGrayed );
if( ! bTab )
{
if( strlen( szPrompt ) )
DrawText( lpdis->hDC, szPrompt, -1, &lpdis->rcItem, uFormat );
else
{
if( ! HB_ISDIBitmap( lpdis ) )
{
// draw separator
lb.lbColor = skinMenu.clr_vertical1;
hBrush = CreateBrushIndirect( &lb );
lpdis->rcItem.top += 2;
lpdis->rcItem.bottom = lpdis->rcItem.top + 1;
rct.top = lpdis->rcItem.top ;
rct.left = lpdis->rcItem.left - 8;
rct.bottom = lpdis->rcItem.bottom;
rct.right = lpdis->rcItem.right;
if( hTopMenu != ( HMENU ) lpdis->hwndItem )
FillRect( lpdis->hDC, &rct, hBrush );
DeleteObject( hBrush );
lb.lbColor = skinMenu.clr_vertical2;
hBrush = CreateBrushIndirect( &lb );
lpdis->rcItem.top ++;
lpdis->rcItem.bottom = lpdis->rcItem.top + 1;
rct.top = lpdis->rcItem.top ;
rct.left = lpdis->rcItem.left - 8;
rct.bottom = lpdis->rcItem.bottom;
rct.right = lpdis->rcItem.right;
if( hTopMenu != ( HMENU ) lpdis->hwndItem )
FillRect( lpdis->hDC, &rct, hBrush );
DeleteObject( hBrush );
}
}
}
else
{
lpdis->rcItem.right -= 21;
StrToken( szPrompt, 1, 9, &wLen ); // 32 bits does not fill wLen before
DrawText( lpdis->hDC, StrToken( szPrompt, 1, 9, &wLen ), wLen, &lpdis->rcItem, DT_LEFT );
StrToken( szPrompt, 2, 9, &wLen ); // 32 bits does not fill wLen before
DrawText( lpdis->hDC, StrToken( szPrompt, 2, 9, &wLen ), wLen, &lpdis->rcItem, DT_RIGHT );
lpdis->rcItem.right += 21;
}
hb_retl( TRUE );
break;
case ODA_FOCUS:
hb_retl( FALSE );
break;
}
}
//----------------------------------------------------------------------------//
#ifndef MIIM_FTYPE
#define MIIM_FTYPE 0x00000100
#endif
HB_FUNC( MITEMS2015 ) // hMenu
{
#ifdef _WIN64
HMENU hMenu = ( HMENU ) hb_parnll( 1 );
#else
HMENU hMenu = ( HMENU ) hb_parnl( 1 );
#endif
WORD w;
MENUITEMINFO mi;
for( w = 0; w < GetMenuItemCount( hMenu ); w++ )
{
memset( ( char * ) &mi, 0, sizeof( MENUITEMINFO ) );
mi.cbSize = sizeof( MENUITEMINFO );
mi.fMask = MIIM_FTYPE;
GetMenuItemInfo( hMenu, w, TRUE, &mi );
if( ( mi.fType & MFT_OWNERDRAW ) != MFT_OWNERDRAW )
{
mi.cbSize = sizeof( MENUITEMINFO );
mi.fMask = ( MIIM_FTYPE | MIIM_DATA );
mi.fType |= MFT_OWNERDRAW;
mi.dwItemData = ( DWORD ) hMenu;
SetMenuItemInfo( hMenu, w, TRUE, &mi );
}
}
}
.../...
if( ! hBmpCheck2015 )
{
OSVERSIONINFO vi;
if ( skinMenu.byteChecked != NULL )
Check2015( lpdis->hDC, skinMenu.byteChecked );
.../...
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: No registered users and 12 guests