[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 378
  • Last Modified:

Bitmap menus

How do I make menus with bitmaps on the left side, like in Microsoft office or the Windows 95 start menu? I have tried using the predefined OWL class and many other classes on the Internet but none of them seemed to work.
0
Owlguru
Asked:
Owlguru
  • 4
  • 4
  • 4
1 Solution
 
AlexVirochovskyCommented:
The following code is used to create a new profile with the name
supplied as lpszProfileName:
  LPPROFADMIN         m_pProfAdmin;
  MAPIAdminProfiles(0, &m_pProfAdmin)
  m_pProfAdmin->CreateProfile(lpszProfileName, NULL, 0, 0)


Hi,  in this example i add 3 bitmaps as Items in MainMenu,
and every Bitmap has you oun PopMenu:
BTW: Add this menu must not in constructore, but in Setup of in
Paint (1-st time):

next is code.
TMyWindow::Paint(TDC& dc, bool, TRect&)
{
  static bool b1 =false;
  if (!b1)
   {
   HMENU    hMenu = CreateMenu () ;

   HMENU    hMenuPopup = LoadMenu (hInstance, "MenuFile") ;
   //i use bitmaps from directory,you can , of course, use
   //from RC file.
   HBITMAP  hBitmapFile = StretchBitmap (TBitmap("FileLabl.bmp")) ;
   AppendMenu (hMenu, MF_BITMAP | MF_POPUP, (int) hMenuPopup,
                 (PSTR) (LONG) hBitmapFile) ;

   hMenuPopup = LoadMenu (hInstance, "MenuEdit") ;
   HBITMAP  hBitmapEdit = StretchBitmap (TBitmap("EditLabl.bmp")) ;
   AppendMenu (hMenu, MF_BITMAP | MF_POPUP, (int) hMenuPopup,
                 (PSTR) (LONG) hBitmapEdit) ;

   hMenuPopup = CreateMenu () ;

   for (int i = 0 ; i < 3 ; i++)
     {
        HBITMAP hBitmapPopFont = GetBitmapFont (i) ;
        AppendMenu (hMenuPopup, MF_BITMAP, IDM_COUR + i,
                      (PSTR) (LONG) hBitmapPopFont) ;
     }

   HBITMAP  hBitmapFont = StretchBitmap (TBitmap("FontLabl.bmp")) ;
   AppendMenu (hMenu, MF_BITMAP | MF_POPUP, (int) hMenuPopup,
                 (PSTR) (LONG) hBitmapFont) ;

   SetMenu(this->HWindow,hMenu);
   b1 = true;
  }
....
}
 2 function(pure Windows, you can make with OWL):
HBITMAP StretchBitmap (HBITMAP hBitmap1)
{
     BITMAP     bm1, bm2 ;
     HBITMAP    hBitmap2 ;
     HDC        hdc, hdcMem1, hdcMem2 ;
     TEXTMETRIC tm ;

     hdc = CreateIC ("DISPLAY", NULL, NULL, NULL) ;
     GetTextMetrics (hdc, &tm) ;
     hdcMem1 = CreateCompatibleDC (hdc) ;
     hdcMem2 = CreateCompatibleDC (hdc) ;
     DeleteDC (hdc) ;

     GetObject (hBitmap1, sizeof (BITMAP), (PSTR) &bm1) ;

     bm2 = bm1 ;
     bm2.bmWidth      = (tm.tmAveCharWidth * bm2.bmWidth)  / 4 ;
     bm2.bmHeight     = (tm.tmHeight       * bm2.bmHeight) / 8 ;
     bm2.bmWidthBytes = ((bm2.bmWidth + 15) / 16) * 2 ;

     hBitmap2 = CreateBitmapIndirect (&bm2) ;

     SelectObject (hdcMem1, hBitmap1) ;
     SelectObject (hdcMem2, hBitmap2) ;

     StretchBlt (hdcMem2, 0, 0, bm2.bmWidth, bm2.bmHeight,
                 hdcMem1, 0, 0, bm1.bmWidth, bm1.bmHeight, SRCCOPY) ;

     DeleteDC (hdcMem1) ;
     DeleteDC (hdcMem2) ;

     return hBitmap2 ;
}

HBITMAP GetBitmapFont (int i)//for 3 fonts
{
     static char   *szFaceName[3] = { "Courier New", "Arial",
                                      "Times New Roman" } ;
     static LOGFONT lf ;
     HBITMAP        hBitmap ;
     HDC            hdc, hdcMem ;
     HFONT          hFont ;
     SIZE           size ;
     TEXTMETRIC     tm ;

     hdc = CreateIC ("DISPLAY", NULL, NULL, NULL) ;
     GetTextMetrics (hdc, &tm) ;

     lf.lfHeight = 2 * tm.tmHeight ;
     strcpy ((char *) lf.lfFaceName, szFaceName[i]) ;

     hdcMem = CreateCompatibleDC (hdc) ;
     hFont = (HFONT) SelectObject (hdcMem, CreateFontIndirect (&lf)) ;
     GetTextExtentPoint (hdcMem, szFaceName[i], strlen (szFaceName[i]), &size) ;

     hBitmap = CreateBitmap (size.cx, size.cy, 1, 1, NULL) ;
     SelectObject (hdcMem, hBitmap) ;

     TextOut (hdcMem, 0, 0, szFaceName[i], strlen (szFaceName[i])) ;

     DeleteObject (SelectObject (hdcMem, hFont)) ;
     DeleteDC (hdcMem) ;
     DeleteDC (hdc) ;

     return hBitmap ;
}

Part of rc file:
....
MenuFile MENU
     {
     MENUITEM "&New",        IDM_NEW
     MENUITEM "&Open...",    IDM_OPEN
     MENUITEM "&Save",       IDM_SAVE
     MENUITEM "Save &As...", IDM_SAVEAS
     }

MenuEdit MENU
     {
     MENUITEM "&Undo",       IDM_UNDO
     MENUITEM SEPARATOR
     MENUITEM "Cu&t",        IDM_CUT
     MENUITEM "&Copy",       IDM_COPY
     MENUITEM "&Paste",      IDM_PASTE
     MENUITEM "De&lete",     IDM_DEL
     }
....
I hope, it helps. Alex
0
 
OwlguruAuthor Commented:
Adjusted points to 110
0
 
OwlguruAuthor Commented:
I use Borland C++ 5.02 with OWL 5.2. This method doesn't seem to work. Can you provide me with some more information(e.g. size and type of bitmaps)?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
AlexVirochovskyCommented:
For test i use BC 5.01 , but it is same.
Write you EMail, and i send you full project(that works, of course!).
0
 
JPMCommented:
get to my site   http://www.multimania.com/jpmolina
and you'll find out what you wish.
JPM
0
 
AlexVirochovskyCommented:
owlguru ???
0
 
AlexVirochovskyCommented:
owlguru, you don't react to my and JPM proposals. I repete my one: i can send you full project, that, of couse, works.
to jpm: if I get PTS, i'll send you same summe.
Alex
0
 
JPMCommented:
thanks Alex.
Jean-Paul
0
 
JPMCommented:
thanks Alex.
Jean-Paul
0
 
OwlguruAuthor Commented:
Can you send me the full project at tohatan@interlog.com as soon as possible? Thank you.
0
 
OwlguruAuthor Commented:
JPM, your site doesn't work! (Page cannot be displayed)
0
 
JPMCommented:
the URL of my site is :
http://www.multimania.com/jpmolina/index.html
and it works.
( I just had updated my site which has frames right now )
please try again and say whether it works for you or not.
Jean-Paul
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now