#define OEMRESOURCE
#include <WinTen.h>
#include <Windows.h>
#include <hbApi.h>
#include <commctrl.h>
#include <StdLib.h>
#define IF(x,y,z) ((x)?(y):(z))
BOOL bStrAt( BYTE bChar, LPSTR szText );
LPSTR StrToken( LPSTR szText, WORD wOcurrence, BYTE bSeparator, LPWORD pwLen );
void WindowBoxIn( HDC hDC, RECT * pRect );
void WndDrawBox( HDC hDC, RECT * rct, HPEN hPUpLeft, HPEN hPBotRit );
void WindowInset( HDC hDC, RECT * pRect );
void WindowRaised( HDC hDC, RECT * pRect );
void DrawBitmap( HDC, HBITMAP, WORD, WORD, WORD, WORD, DWORD );
void DrawMasked( HDC, HBITMAP, WORD, WORD );
void DrawGrayed( HDC, HBITMAP, int, int );
void RectDisable( HDC, LPRECT);
void DegardeFill( HDC hDC, RECT * rori, COLORREF cFrom, COLORREF cTo, int nDegType ) ;
void DegradColor( HDC hDC, RECT * rori, COLORREF cFrom, COLORREF cTo, int nDegType, int iRound ) ;
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_CREATEMENU( ) //<---- aqui el problema
{
hb_retnl( ( LONG ) CreateMenu() );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_CREATEPOPUPMENU( )
{
hb_retnl( ( LONG ) CreatePopupMenu() );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_TRACKPOPUP( )
{
hb_retl( TrackPopupMenu( ( HMENU ) hb_parnl( 1 ), hb_parni( 2 ), hb_parni( 4 ),
hb_parni( 3 ), hb_parni( 5 ), ( HWND ) hb_parni( 6 ), NULL ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_ENABLEMENUITEM( )
{
hb_retl( EnableMenuItem( ( HMENU ) hb_parnl( 1 ), hb_parni( 2 ), hb_parni( 3 ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_CHECKMENUITEM( ) // ()
{
hb_retl( CheckMenuItem( ( HMENU ) hb_parnl( 1 ), hb_parni( 2 ), hb_parni( 3 ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_GETMITEMCOUNT( ) // ()
{
hb_retni( GetMenuItemCount( ( HMENU ) hb_parnl( 1 ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_GETMITEMID( ) // hMenu, nPos
{
hb_retni( GetMenuItemID( ( HMENU ) hb_parnl( 1 ), hb_parni( 2 ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_GETSYSTEMMENU( ) // ()
{
hb_retnl( ( LONG ) GetSystemMenu( ( HWND ) hb_parnl( 1 ), hb_parl( 2 ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_DESTROYMENU( ) // () hMenu
{
hb_retl( DestroyMenu( ( HMENU ) hb_parnl( 1 ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_GETSUBMENU( ) // hMenu, nPos
{
hb_retnl( ( LONG ) GetSubMenu( ( HMENU ) hb_parnl( 1 ), hb_parni( 2 ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_GETMENUSTRING( ) // () hMenu, nId, nPosOrValue
{
BYTE bBuffer[ 200 ];
WORD wLen = GetMenuString( ( HMENU ) hb_parnl( 1 ), hb_parni( 2 ), ( char * ) bBuffer,
199, hb_parni( 3 ) );
hb_retclen( ( char * ) bBuffer, wLen );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_GETMENUSTATE( ) // () hMenu, nId, nFlags
{
hb_retni( GetMenuState( ( HMENU ) hb_parnl( 1 ), hb_parni( 2 ), hb_parni( 3 ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_DRAWMENUBAR( ) // () hWnd
{
DrawMenuBar( ( HWND ) hb_parnl( 1 ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_HILITEMENUITEM( ) // () hWnd, hMenu, idItem, nHiliteFlags
{
hb_retl( HiliteMenuItem( ( HWND ) hb_parnl( 1 ), ( HMENU ) hb_parnl( 2 ),
hb_parni( 3 ), hb_parni( 4 ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_LOADMENU( )
{
hb_retnl( ( LONG ) LoadMenu( ( HINSTANCE ) hb_parnl( 1 ),
( LPSTR ) IF( ISCHAR( 2 ), hb_parc( 2 ),
MAKEINTRESOURCE( hb_parni( 2 ) ) ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_APPENDMENU( )
{
hb_retl( AppendMenu( ( HMENU ) hb_parnl( 1 ), ( UINT ) hb_parnl( 2 ), hb_parnl( 3 ),
IF( ISCHAR( 4 ), hb_parc( 4 ), ( LPSTR ) hb_parnl( 4 ) ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_SETMENU( )
{
hb_retl( SetMenu( ( HWND ) hb_parnl( 1 ), ( HMENU ) hb_parnl( 2 ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_MODIFYMENU( )
{
hb_retl( ModifyMenu( ( HMENU ) hb_parnl( 1 ), ( UINT ) hb_parni( 2 ),
hb_parni( 3 ), ( UINT ) hb_parni( 4 ),
IF( ISCHAR( 5 ), hb_parc( 5 ), ( LPSTR ) hb_parnl( 5 ) ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_INSERTMENU( ) // ( hMenu, nIdItem, nFlags, nNewItem, cPrompt ) --> lSuccess
{
hb_retl( InsertMenu( ( HMENU ) hb_parnl( 1 ), hb_parni( 2 ), hb_parni( 3 ),
hb_parni( 4 ), hb_parc( 5 ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_REMOVEMENU( ) // ( hMenu, nItem, nFlags ) --> lSuccess
{
hb_retl( RemoveMenu( ( HMENU ) hb_parnl( 1 ),
( UINT ) hb_parni( 2 ),
( UINT ) hb_parni( 3 ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_ATMENUDRAWITEM( ) // ( pDrawItemStruct, cPrompt, lTop, hBitmap,lSeparator,acolor,lbar )
{
LPDRAWITEMSTRUCT lpdis = ( LPDRAWITEMSTRUCT ) hb_parnl( 1 );
LPSTR szPrompt = ( char *)hb_parc( 2 );
BOOL bTab = bStrAt( 9, szPrompt );
WORD wLen;
BOOL lSeparator = hb_parl( 5 );
BOOL lBar = hb_parl( 7 );
HPEN hNormal,hOldPen;
HBRUSH hBrush;
LOGBRUSH lb;
RECT rct;
RECT rctdg;
RECT rctsep;
RECT rctshd;
COLORREF nClrMenu = hb_parnl(6,1);
COLORREF nClrMenuTxt = hb_parnl(6,2);
COLORREF nClrBack = hb_parnl(6,3);
COLORREF nClrTo = hb_parnl(6,4);
COLORREF nClrHighBai = hb_parnl(6,5);
COLORREF nClrHighBaf = hb_parnl(6,6);
COLORREF nClrHighTxt = hb_parnl(6,7);
COLORREF nClrHighBar = hb_parnl(6,8);
HBITMAP hBmp = ( HBITMAP ) hb_parnl( 4 );
switch( lpdis->itemAction )
{
case ODA_DRAWENTIRE:
case ODA_SELECT:
lb.lbStyle = BS_SOLID;
lb.lbColor = nClrMenu;
hBrush = CreateBrushIndirect( &lb );
FillRect( lpdis->hDC, &lpdis->rcItem, hBrush );
DeleteObject( hBrush );
SetBkColor( lpdis->hDC, nClrMenu );
SetBkMode( lpdis->hDC, TRANSPARENT );
SetTextColor( lpdis->hDC, nClrMenuTxt);
if( lpdis->itemState & ODS_SELECTED &&
! ( lpdis->itemState & ODS_GRAYED ) && !lSeparator )
{
lb.lbColor = nClrHighBai;
SetBkColor( lpdis->hDC, nClrHighBai );
SetTextColor( lpdis->hDC, nClrHighTxt );
if( !lBar )
lpdis->rcItem.left += 22;
}
else
lb.lbColor = nClrMenu;
hBrush = CreateBrushIndirect( &lb );
FillRect( lpdis->hDC, &lpdis->rcItem, hBrush );
DeleteObject( hBrush );
if( lpdis->itemState & ODS_SELECTED &&
! ( lpdis->itemState & ODS_GRAYED ) )
{
if( !lBar )
lpdis->rcItem.left -= 22;
}
if(!lBar)
{
rct.top = lpdis->rcItem.top+1;
rct.left = lpdis->rcItem.left+1;
rct.right = lpdis->rcItem.right-1; //22;
rct.bottom = lpdis->rcItem.bottom - 2;
}
else
{
rct.top = lpdis->rcItem.top+1;
rct.left = lpdis->rcItem.left+1;
rct.right = lpdis->rcItem.right-4;
rct.bottom = lpdis->rcItem.bottom - 1;
rctshd.top = lpdis->rcItem.top+3;
rctshd.left = lpdis->rcItem.right-3;
rctshd.right = lpdis->rcItem.right;
rctshd.bottom = lpdis->rcItem.bottom;
}
rctdg.top = lpdis->rcItem.top-1; //-4
rctdg.left = lpdis->rcItem.left;
rctdg.right = 22;
rctdg.bottom = lpdis->rcItem.bottom+1; // - 1;
if( !lBar )
DegradColor( lpdis->hDC, &rctdg, nClrBack, nClrTo, 2, 1 ) ;
if( lpdis->itemState & ODS_SELECTED )
if( ! ( lpdis->itemState & ODS_GRAYED ) ) //&&
{
hNormal = CreatePen(PS_SOLID,0,nClrHighBar);
hOldPen = SelectObject(lpdis->hDC,hNormal);
Rectangle(lpdis->hDC,rct.left-1,rct.top-1,rct.right+1,rct.bottom+1);
SelectObject(lpdis->hDC,hOldPen);
DeleteObject( hNormal );
DegradColor( lpdis->hDC, &rct, nClrHighBai, nClrHighBaf, 1, 1 ) ;
if(lBar)
{
lb.lbColor = GetSysColor(16);
hBrush = CreateBrushIndirect( &lb );
FillRect( lpdis->hDC, &rctshd, hBrush );
DeleteObject( hBrush );
rctshd.top = lpdis->rcItem.top;
rctshd.left = lpdis->rcItem.right-3;
rctshd.right = lpdis->rcItem.right;
rctshd.bottom = lpdis->rcItem.top+3;
lb.lbColor = nClrMenu;
hBrush = CreateBrushIndirect( &lb );
FillRect( lpdis->hDC, &rctshd, hBrush );
DeleteObject( hBrush );
}
}
if(!lBar)
{
if( lpdis->itemState & ODS_CHECKED )
{
HBITMAP hBmp = LoadBitmap( 0, MAKEINTRESOURCE( OBM_CHECK ) );
if( ! ( lpdis->itemState & ODS_SELECTED ) )
DrawMasked( lpdis->hDC, hBmp, lpdis->rcItem.top + 3,
lpdis->rcItem.left + 4 );
else
DrawMasked( lpdis->hDC, hBmp, lpdis->rcItem.top + 3,
lpdis->rcItem.left + 4 );
DeleteObject( hBmp );
}
if( hBmp && !( (int) hBmp == 1 ) )
{
if( ! ( lpdis->itemState & ODS_CHECKED ) )
DrawMasked( lpdis->hDC, hBmp, lpdis->rcItem.top + 3, //ojo
lpdis->rcItem.left + 2 );
else
if( ! ( lpdis->itemState & ODS_SELECTED ) )
DrawGrayed( lpdis->hDC, hBmp, lpdis->rcItem.top + 3,
lpdis->rcItem.left + 2 );
else
DrawMasked( lpdis->hDC, hBmp, lpdis->rcItem.top + 3,
lpdis->rcItem.left + 2 );
}
}
if(!lBar)
{
lpdis->rcItem.top += 4;
lpdis->rcItem.left += 26;
}
else
{
lpdis->rcItem.top += 2;
lpdis->rcItem.left += 3;
}
if( !bTab )
{
if( lSeparator )
{
rctsep.top = lpdis->rcItem.top-1;
rctsep.left = lpdis->rcItem.left;
rctsep.right = lpdis->rcItem.right+5;
rctsep.bottom = lpdis->rcItem.bottom - 4;
lb.lbStyle = BS_SOLID;
lb.lbColor = nClrHighBar ;
hBrush = CreateBrushIndirect( &lb );
FillRect( lpdis->hDC, &rctsep, hBrush );
DeleteObject( hBrush );
}
else
{
if(!lBar)
{
DrawText( lpdis->hDC, szPrompt, -1, &lpdis->rcItem, DT_LEFT );
}
else
{
lpdis->rcItem.left -= 5;
DrawText( lpdis->hDC, szPrompt, -1, &lpdis->rcItem, DT_CENTER );
lpdis->rcItem.left += 5;
}
}
}
else
{
lpdis->rcItem.right -= 26;
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 += 26;
}
if(!lBar)
{
/*
if( !lSeparator )
{
if( lpdis->itemState & ODS_GRAYED )
RectDisable( lpdis->hDC, &lpdis->rcItem );
}
*/
lpdis->rcItem.top -= 4;
lpdis->rcItem.left -= 26;
}
else
{
lpdis->rcItem.top -= 2;
lpdis->rcItem.left -= 4;
}
hb_retl( TRUE );
break;
case ODA_FOCUS:
hb_retl( FALSE );
break;
}
}
//----------------------------------------------------------------------------//
/*
#ifdef __HARBOUR__
CLIPPER MENUMEASUREITEM( ) // ( pMeasureItemStruct, nLen )
#else
CLIPPER MENUMEASUR( ) // EITEM( pMeasureItemStruct, nLen )
#endif
{
LPMEASUREITEMSTRUCT lp = ( LPMEASUREITEMSTRUCT ) hb_parnl( 1 );
lp->itemWidth = hb_parni( 2 );
lp->itemHeight = GetSystemMetrics( SM_CYMENU ); //18
}
*/
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_GETMEAITEM( ) // ( pMeasureItemStruct ) --> nMenuItemID
{
LPMEASUREITEMSTRUCT lp = ( LPMEASUREITEMSTRUCT ) hb_parnl( 1 );
hb_retnl( lp->itemID );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_GETDRAWITEM( ) // ( pDrawItemStruct ) --> nMenuItemID
{
LPDRAWITEMSTRUCT lpdis = ( LPDRAWITEMSTRUCT ) hb_parnl( 1 );
hb_retnl( lpdis->itemID );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_GETDRAWMENU( ) // ( pDrawItemStruct ) --> hMenu
{
LPDRAWITEMSTRUCT lpdis = ( LPDRAWITEMSTRUCT ) hb_parnl( 1 );
hb_retnl( ( LONG ) lpdis->hwndItem );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_ISMENU( )
{
hb_retl( IsMenu( ( HMENU ) hb_parnl( 1 ) ) );
}
//----------------------------------------------------------------------------//
HB_FUNC( _GETMENUID)
{
hb_retnl((LONG)GetMenu((HWND)hb_parnl(1)));
}
//----------------------------------------------------------------------------//
HB_FUNC ( _COLORMENU )
{
HMENU iMenu;
MENUINFO iMenuInfo ;
COLORREF lColor = hb_parnl(2);
BOOL lSubMenu = hb_parl(3);
HWND himage ;
himage = (HWND)LoadImage(0,hb_parc(4),IMAGE_BITMAP ,0,0,LR_LOADFROMFILE | LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT );
if (himage==NULL)
{
himage = (HWND)LoadImage(GetModuleHandle(NULL),hb_parc(4),IMAGE_BITMAP ,0,0, LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT );
}
iMenu = GetMenu((HWND) hb_parnl(1));
GetMenuInfo(iMenu, &iMenuInfo);
iMenuInfo.cbSize = sizeof(MENUINFO);
iMenuInfo.dwStyle = GetWindowLongPtr( (HWND) hb_parnl(1), GWL_STYLE );
if (lSubMenu)
{
iMenuInfo.fMask = MIM_BACKGROUND | MIM_APPLYTOSUBMENUS ;
}
else
{
iMenuInfo.fMask = MIM_BACKGROUND;
}
if (himage==NULL)
{
iMenuInfo.hbrBack = CreateSolidBrush(lColor);
}
else
{
iMenuInfo.hbrBack = CreatePatternBrush( (HBITMAP) himage);
}
SetMenuInfo(iMenu, &iMenuInfo);
DrawMenuBar((HWND) hb_parnl(1));
}
//----------------------------------------------------------------------------//
HB_FUNC ( _COLORSUBMENU )
{
HMENU iMenu;
MENUINFO iMenuInfo ;
COLORREF lColor = hb_parnl(2);
iMenu = GetMenu((HWND) hb_parnl(1));
GetMenuInfo(iMenu, &iMenuInfo);
iMenuInfo.cbSize = sizeof(MENUINFO);
iMenuInfo.fMask = MIM_BACKGROUND | MIM_APPLYTOSUBMENUS;
iMenuInfo.hbrBack = CreateSolidBrush(lColor);
SetMenuInfo(iMenu, &iMenuInfo);
// DrawMenuBar((HWND) hb_parnl(1));
}
//----------------------------------------------------------------------------//
HB_FUNC( CHGMENUMEA ) // pMeasureItemStruct, nWidth, nHeight
{
LPMEASUREITEMSTRUCT lp = ( LPMEASUREITEMSTRUCT ) hb_parnl( 1 );
lp->itemWidth = hb_parni( 2 ) ;
lp->itemHeight = hb_parni( 3 ) ;
}
HB_FUNC( GETDRAWISR ) // ( pDrawitemstruct )
{
LPDRAWITEMSTRUCT lp = ( LPDRAWITEMSTRUCT ) hb_parnl( 1 );
hb_reta( 12 );
hb_storni( lp->CtlType , -1, 1 );
hb_storni( lp->CtlID , -1, 2 );
hb_storni( lp->itemID , -1, 3 );
hb_storni( lp->itemAction , -1, 4 );
hb_storni( lp->itemState , -1, 5 );
hb_storni( ( LONG ) lp->hwndItem , -1, 6 );
hb_storni( ( LONG ) lp->hDC , -1, 7 );
hb_storni( lp->rcItem.top , -1, 8 );
hb_storni( lp->rcItem.left , -1, 9 );
hb_storni( lp->rcItem.bottom, -1, 10 );
hb_storni( lp->rcItem.right , -1, 11 );
hb_stornd( lp->itemData , -1, 12 );
}
HB_FUNC( GETMEAUSUR ) // ( pMeasureItemStruct )
{
LPMEASUREITEMSTRUCT lp = ( LPMEASUREITEMSTRUCT ) hb_parnl( 1 );
hb_reta( 6 );
hb_storni( lp->CtlType , -1, 1 );
hb_storni( lp->CtlID , -1, 2 );
hb_storni( lp->itemID , -1, 3 );
hb_storni( lp->itemWidth , -1, 4 );
hb_storni( lp->itemHeight , -1, 5 );
hb_stornd( lp->itemData , -1, 12 );
}
//----------------------------------------------------------------------------//