FWH/xHarbour Menus
Posted: Thu May 21, 2009 9:57 am
Hi all,
I have found some C lang. code in \FWH\SOURCE\WINAPI called MENUS.C, and have played a little with this code.
I managed to give a nicer look (at least in my opinion) to the menus.
This code can be simply pasted preferably inside the main program (see below), and it will work.
In my case, I use a nice (modified) CLR_HCYAN background, and with about 10 lines of code which I added in
DIALOG.PRG, I managed to create all my dialogs with a very impressive background brush, also in tones of
this CLR_HCYAN background. Most of my users have found the new look of my programs as very relaxing,
and that they do not cause eye problems (in other words, they said that their eyes can see better now).
Anyone who likes to use the code, is able to do it (I am not the original author of the code), however, there
is just one problem (please consider that I haven't used "C" for thousands of years)...
The problem is that the highlighted item (the one you place the mouse over it) has the usual blue background,
(the complete ractangle of the menu item is blue), but the background under the menu item string, holds the
modified CLR_HCYAN color, which I found as a big problem.
If someone can modify the code, and make the background under the letters, as BLUE to match the rectangle's
blue background, will be highly appreciated.
Here's the code... I would like to thank anyone involved into this, and of course, anyone who wishes to use
the code in his programs is welcome. (I guess that when fixed by our C gurus, the corrected code will be
also posted here.
Greetings to all fellow programmers and friends!
Evans Bartzokas
Corinth, Greece
I have found some C lang. code in \FWH\SOURCE\WINAPI called MENUS.C, and have played a little with this code.
I managed to give a nicer look (at least in my opinion) to the menus.
This code can be simply pasted preferably inside the main program (see below), and it will work.
In my case, I use a nice (modified) CLR_HCYAN background, and with about 10 lines of code which I added in
DIALOG.PRG, I managed to create all my dialogs with a very impressive background brush, also in tones of
this CLR_HCYAN background. Most of my users have found the new look of my programs as very relaxing,
and that they do not cause eye problems (in other words, they said that their eyes can see better now).
Anyone who likes to use the code, is able to do it (I am not the original author of the code), however, there
is just one problem (please consider that I haven't used "C" for thousands of years)...
The problem is that the highlighted item (the one you place the mouse over it) has the usual blue background,
(the complete ractangle of the menu item is blue), but the background under the menu item string, holds the
modified CLR_HCYAN color, which I found as a big problem.
If someone can modify the code, and make the background under the letters, as BLUE to match the rectangle's
blue background, will be highly appreciated.
Here's the code... I would like to thank anyone involved into this, and of course, anyone who wishes to use
the code in his programs is welcome. (I guess that when fixed by our C gurus, the corrected code will be
also posted here.
Greetings to all fellow programmers and friends!
Evans Bartzokas
Corinth, Greece
Code: Select all
// Complete menu system.
// It changes the default colors of FWH/XHB menus.
// Just paste into any MAIN() program, and compile...
// Copyright notice:
// This code originally comes from FWH/SOURCE/WINAPI/MENUS.C
// It has been modified by Evans Bartzokas, in hopes that
// it would be of some use to our fellow programmers/friends.
#PRAGMA BEGINDUMP
#define OEMRESOURCE
#define OBM_CHECK 32760
#include <WinTen.h>
#include <Windows.h>
#include <ClipApi.h>
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 MyRectDisable( HDC, LPRECT );
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_CREATEMENU( PARAMS )
{
_retnl( ( LONG ) CreateMenu() );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_CREATEPOPUPMENU( PARAMS )
{
_retnl( ( LONG ) CreatePopupMenu() );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_TRACKPOPUP( PARAMS )
{
_retl( TrackPopupMenu( ( HMENU ) _parnl( 1 ), _parni( 2 ), _parni( 4 ),
_parni( 3 ), _parni( 5 ), ( HWND ) _parni( 6 ), NULL ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_ENABLEMENUITEM( PARAMS )
{
_retl( EnableMenuItem( ( HMENU ) _parnl( 1 ), _parni( 2 ), _parni( 3 ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_CHECKMENUITEM( PARAMS ) // ()
{
_retl( CheckMenuItem( ( HMENU ) _parnl( 1 ), _parni( 2 ), _parni( 3 ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_GETMITEMCOUNT( PARAMS ) // ()
{
_retni( GetMenuItemCount( ( HMENU ) _parnl( 1 ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_GETMITEMID( PARAMS ) // hMenu, nPos
{
_retni( GetMenuItemID( ( HMENU ) _parnl( 1 ), _parni( 2 ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_GETSYSTEMMENU( PARAMS ) // ()
{
_retnl( ( LONG ) GetSystemMenu( ( HWND ) _parnl( 1 ), _parl( 2 ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_DESTROYMENU( PARAMS ) // () hMenu
{
_retl( DestroyMenu( ( HMENU ) _parnl( 1 ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_GETSUBMENU( PARAMS ) // hMenu, nPos
{
_retnl( ( LONG ) GetSubMenu( ( HMENU ) _parnl( 1 ), _parni( 2 ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_GETMENUSTRING( PARAMS ) // () hMenu, nId, nPosOrValue
{
BYTE bBuffer[ 200 ];
WORD wLen = GetMenuString( ( HMENU ) _parnl( 1 ), _parni( 2 ), ( char * ) bBuffer,
199, _parni( 3 ) );
_retclen( ( char * ) bBuffer, wLen );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_GETMENUSTATE( PARAMS ) // () hMenu, nId, nFlags
{
_retni( GetMenuState( ( HMENU ) _parnl( 1 ), _parni( 2 ), _parni( 3 ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_DRAWMENUBAR( PARAMS ) // () hWnd
{
DrawMenuBar( ( HWND ) _parnl( 1 ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_HILITEMENUITEM( PARAMS ) // () hWnd, hMenu, idItem, nHiliteFlags
{
_retl( HiliteMenuItem( ( HWND ) _parnl( 1 ), ( HMENU ) _parnl( 2 ),
_parni( 3 ), _parni( 4 ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_LOADMENU( PARAMS )
{
_retnl( ( LONG ) LoadMenu( ( HINSTANCE ) _parnl( 1 ),
( LPSTR ) IF( ISCHAR( 2 ), _parc( 2 ),
MAKEINTRESOURCE( _parni( 2 ) ) ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_APPENDMENU( PARAMS )
{
_retl( AppendMenu( ( HMENU ) _parnl( 1 ), ( UINT ) _parnl( 2 ), _parnl( 3 ),
IF( ISCHAR( 4 ), _parc( 4 ), ( LPSTR ) _parnl( 4 ) ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_SETMENU( PARAMS )
{
_retl( SetMenu( ( HWND ) _parnl( 1 ), ( HMENU ) _parnl( 2 ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_MODIFYMENU( PARAMS )
{
_retl( ModifyMenu( ( HMENU ) _parnl( 1 ), ( UINT ) _parni( 2 ),
_parni( 3 ), ( UINT ) _parni( 4 ),
IF( ISCHAR( 5 ), _parc( 5 ), ( LPSTR ) _parnl( 5 ) ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_INSERTMENU( PARAMS ) // ( hMenu, nIdItem, nFlags, nNewItem, cPrompt ) --> lSuccess
{
_retl( InsertMenu( ( HMENU ) _parnl( 1 ), _parni( 2 ), _parni( 3 ),
_parni( 4 ), _parc( 5 ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_REMOVEMENU( PARAMS ) // ( hMenu, nItem, nFlags ) --> lSuccess
{
_retl( RemoveMenu( ( HMENU ) _parnl( 1 ),
( UINT ) _parni( 2 ),
( UINT ) _parni( 3 ) ) );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_MENUDRAWITEM( PARAMS ) // ( pDrawItemStruct, cPrompt, lTop, hBitmap )
{
LPDRAWITEMSTRUCT lpdis = ( LPDRAWITEMSTRUCT ) _parnl( 1 );
LPSTR szPrompt = _parc( 2 );
BOOL bTab = bStrAt( 9, szPrompt );
WORD wLen;
BOOL bTop = _parl( 3 );
HPEN hNormal;
HBRUSH hBrush;
LOGBRUSH lb;
RECT rct;
HBITMAP hBmp = ( HBITMAP ) _parnl( 4 );
switch( lpdis->itemAction )
{
case ODA_DRAWENTIRE:
case ODA_SELECT:
lb.lbStyle = BS_SOLID;
lb.lbColor = GetSysColor( COLOR_MENU ); // (SELECTED (BLUE COLOR) ITEMS)
hBrush = CreateBrushIndirect( &lb );
FillRect( lpdis->hDC, &lpdis->rcItem, hBrush );
DeleteObject( hBrush );
if( lpdis->itemState & ODS_SELECTED &&
! ( lpdis->itemState & ODS_GRAYED ) )
{
lb.lbColor = GetSysColor( COLOR_HIGHLIGHT );
SetBkColor( lpdis->hDC, GetSysColor( COLOR_HIGHLIGHT ) );
SetTextColor( lpdis->hDC, GetSysColor( COLOR_HIGHLIGHTTEXT ) );
lpdis->rcItem.left += 19;
}
else
lb.lbColor = 16770508 ; // GetSysColor( COLOR_MENU ); ( ALL UNSELECTED ITEMS )
hBrush = CreateBrushIndirect( &lb );
FillRect( lpdis->hDC, &lpdis->rcItem, hBrush );
DeleteObject( hBrush );
if( lpdis->itemState & ODS_SELECTED &&
! ( lpdis->itemState & ODS_GRAYED ) )
lpdis->rcItem.left -= 19;
rct.top = lpdis->rcItem.top;
rct.left = lpdis->rcItem.left;
rct.right = 17;
rct.bottom = lpdis->rcItem.bottom - 1;
if( lpdis->itemState & ODS_SELECTED )
if( ! ( lpdis->itemState & ODS_GRAYED ) &&
! ( lpdis->itemState & ODS_CHECKED ) )
if( hBmp )
WindowRaised( lpdis->hDC, &rct );
else
{
lb.lbColor = 16770508 ; // GetSysColor( COLOR_HIGHLIGHT );
hBrush = CreateBrushIndirect( &lb );
rct.right += 2;
rct.bottom++;
FillRect( lpdis->hDC, &rct, hBrush );
rct.right -= 2;
rct.bottom--;
DeleteObject( hBrush );
}
if( lpdis->itemState & ODS_CHECKED )
{
HBITMAP hBmp = LoadBitmap( 0, MAKEINTRESOURCE( OBM_CHECK ) );
if( ! ( lpdis->itemState & ODS_SELECTED ) )
DrawGrayed( lpdis->hDC, hBmp, lpdis->rcItem.top + 1,
lpdis->rcItem.left + 1 );
else
DrawMasked( lpdis->hDC, hBmp, lpdis->rcItem.top + 1,
lpdis->rcItem.left + 1 );
DeleteObject( hBmp );
WindowInset( lpdis->hDC, &rct );
}
if( hBmp )
{
if( ! ( lpdis->itemState & ODS_CHECKED ) )
DrawMasked( lpdis->hDC, hBmp, lpdis->rcItem.top + 1,
lpdis->rcItem.left + 1 );
else
if( ! ( lpdis->itemState & ODS_SELECTED ) )
DrawGrayed( lpdis->hDC, hBmp, lpdis->rcItem.top + 1,
lpdis->rcItem.left + 1 );
else
DrawMasked( lpdis->hDC, hBmp, lpdis->rcItem.top + 1,
lpdis->rcItem.left + 1 );
}
lpdis->rcItem.top += 2;
lpdis->rcItem.left += 21;
if( !bTab )
{
// V. ADDED STARTS
SetBkColor( lpdis->hDC, 16770508 ); // HCYAN1
// V. ADDED ENDS
DrawText( lpdis->hDC, szPrompt, -1, &lpdis->rcItem, DT_LEFT );
}
else
{
lpdis->rcItem.right -= 21; // THOSE ITEMS THAT HAVE TABS. eg. (F5)
StrToken( szPrompt, 1, 9, &wLen ); // 32 bits does not fill wLen before
// V. ADDED STARTS
SetBkColor( lpdis->hDC, 16770508 );
// V. ADDED ENDS
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;
}
lpdis->rcItem.top -= 2;
lpdis->rcItem.left -= 21;
if( lpdis->itemState & ODS_GRAYED )
MyRectDisable( lpdis->hDC, &lpdis->rcItem ); // Function below, added by V.
_retl( TRUE );
break;
case ODA_FOCUS:
_retl( FALSE );
break;
}
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_MENUMEASUREITEM( PARAMS ) // ( pMeasureItemStruct, nLen )
{
LPMEASUREITEMSTRUCT lp = ( LPMEASUREITEMSTRUCT ) _parnl( 1 );
lp->itemWidth = _parni( 2 );
lp->itemHeight = GetSystemMetrics( SM_CYMENU ); // 18
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_GETMEAITEM( PARAMS ) // ( pMeasureItemStruct ) --> nMenuItemID
{
LPMEASUREITEMSTRUCT lp = ( LPMEASUREITEMSTRUCT ) _parnl( 1 );
_retnl( lp->itemID );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_GETDRAWITEM( PARAMS ) // ( pDrawItemStruct ) --> nMenuItemID
{
LPDRAWITEMSTRUCT lpdis = ( LPDRAWITEMSTRUCT ) _parnl( 1 );
_retnl( lpdis->itemID );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_GETDRAWMENU( PARAMS ) // ( pDrawItemStruct ) --> hMenu
{
LPDRAWITEMSTRUCT lpdis = ( LPDRAWITEMSTRUCT ) _parnl( 1 );
_retnl( ( LONG ) lpdis->hwndItem );
}
//----------------------------------------------------------------------------//
HARBOUR HB_FUN_ISMENU( PARAMS )
{
_retl( IsMenu( ( HMENU ) _parnl( 1 ) ) );
}
void MyRectDisable( HDC hDC, LPRECT rc ) // Added by V.
{
HDC hDCMono;
HBITMAP hBmpMono, hBmpMonoOld;
HBRUSH hbrLight, hbrShadow, hbrOld;
COLORREF cOld;
hDCMono = CreateCompatibleDC( hDC );
hBmpMono = CreateBitmap( rc->right - rc->left, rc->bottom - rc->top, 1, 1, NULL );
hbrLight = CreateSolidBrush( GetSysColor( COLOR_BTNHIGHLIGHT ) );
hbrShadow = CreateSolidBrush( GetSysColor( COLOR_BTNSHADOW ) );
hBmpMonoOld = ( HBITMAP )SelectObject( hDCMono, hBmpMono );
// cOld = SetBkColor( hDC, GetSysColor( COLOR_BTNFACE ) );
cOld = SetBkColor( hDC, RGB(118,204,228) ); // V. BACKGROUND FOR DISABLED ITEM
BitBlt( hDCMono, 0, 0, rc->right - rc->left, rc->bottom - rc->top, hDC, rc->left, rc->top, SRCCOPY );
// SetBkColor( hDC, GetSysColor( COLOR_BTNHIGHLIGHT ) );
SetBkColor( hDC, RGB(128,128,128)); // GetSysColor( COLOR_BTNHIGHLIGHT ) ); // V. FOREGROUND FOR DISPLAYED ITEM
BitBlt( hDCMono, 0, 0, rc->right - rc->left, rc->bottom - rc->top, hDC, rc->left, rc->top, SRCPAINT );
BitBlt( hDCMono, 0, 0, rc->right - rc->left, rc->bottom - rc->top, hDCMono, 0, 0, DSTINVERT );
// 0xE20746 op code is (Dst ^ (Src & (Pat ^ Dst)))
hbrOld = ( HBRUSH ) SelectObject( hDC, hbrLight );
BitBlt( hDC, rc->left + 1, rc->top + 1, rc->right - rc->left, rc->bottom - rc->top, hDCMono, 0, 0, 0XE20746 );
SelectObject( hDC, hbrShadow );
BitBlt( hDC, rc->left , rc->top , rc->right - rc->left, rc->bottom - rc->top, hDCMono, 0, 0, 0XE20746 );
SetBkColor( hDC, cOld );
SelectObject( hDC, hbrOld );
SelectObject( hDCMono, hBmpMonoOld );
DeleteObject( hBmpMono );
DeleteObject( hbrLight );
DeleteObject( hbrShadow );
DeleteDC( hDCMono );
}
#PRAGMA ENDDUMP