Creating an Internet Explorer-style Menu Bar

This is a discussion on Creating an Internet Explorer-style Menu Bar within the Windows Programming forums, part of the Platform Specific Boards category; Hello... Somebody tried to make the program shown in this URL ? I created the interfaces until the part that ...

  1. #1
    A.I Programmer
    Join Date
    Mar 2007
    Location
    Teresina - Brazil
    Posts
    47

    Creating an Internet Explorer-style Menu Bar

    Hello...

    Somebody tried to make the program shown in this URL?

    I created the interfaces until the part that deals with the "Message Processing for Menu Hot-Tracking"...

    If somebody already implemented this, helps me showing parts of the code.

    Any aid is useful... Always...

    bye

  2. #2
    A.I Programmer
    Join Date
    Mar 2007
    Location
    Teresina - Brazil
    Posts
    47
    I use C Language and Win32 API...

  3. #3
    A.I Programmer
    Join Date
    Mar 2007
    Location
    Teresina - Brazil
    Posts
    47
    My bigger difficulty is the language, I do not say English, and I got few progressos.

    My code:

    Code:
    /*resource.h*/
    #include <windows.h>
    #define _WIN32_IE 0x0501
    #include <commctrl.h>
    
    #define ID_MAINMENU  1000
    #define ID_MENU1     1001
    #define ID_MENU2     1002
    #define ID_MENU3     1003
    
    #define ID_TESTE1    1004
    #define ID_TESTE2    1005
    #define ID_TESTE3    1006
    Code:
    /*main.c*/
    #include <windows.h>
    #include "resource.h"
    
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
    
    char szClassName[ ] = "WindowsApp";
    
    int WINAPI WinMain (HINSTANCE hThisInstance,
                        HINSTANCE hPrevInstance,
                        LPSTR lpszArgument,
                        int nFunsterStil)
    
    {
       HWND hwnd;
       MSG messages;
       WNDCLASSEX wincl;
    
       INITCOMMONCONTROLSEX InitCtrls;
       InitCtrls.dwICC = ICC_LISTVIEW_CLASSES;
       InitCtrls.dwSize = sizeof(INITCOMMONCONTROLSEX);
       InitCommonControlsEx(&InitCtrls);
        
       wincl.hInstance = hThisInstance;
       wincl.lpszClassName = szClassName;
       wincl.lpfnWndProc = WindowProcedure;
       wincl.style = CS_DBLCLKS;
       wincl.cbSize = sizeof (WNDCLASSEX);
    
       wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
       wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
       wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
       wincl.lpszMenuName = NULL;
       wincl.cbClsExtra = 0;
       wincl.cbWndExtra = 0;
       wincl.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
    
       if (!RegisterClassEx (&wincl))
         return 0;
    
       hwnd = CreateWindowEx (
              0,
              szClassName,
              "Internet Explorer-style Menu Bar",
              WS_OVERLAPPEDWINDOW,
              CW_USEDEFAULT,
              CW_USEDEFAULT,
              544,
              375,
              HWND_DESKTOP,
              NULL,
              hThisInstance,
              NULL
              );
    
       ShowWindow (hwnd, nFunsterStil);
    
       while (GetMessage (&messages, NULL, 0, 0))
       {
          if(!IsDialogMessage(hwnd,&messages))
          {
             TranslateMessage(&messages);
             DispatchMessage(&messages);
          }
       }
    
       return messages.wParam;
    }
    
    void ToolBarButtonDropDown(HWND hwnd, LPNMHDR lpnm, LPNMTOOLBAR lpnmTB, int nIndex)
    {
       RECT rc;
       TPMPARAMS tpm;
       HMENU hPopupMenu = NULL;
    	
       SendMessage(lpnmTB->hdr.hwndFrom, TB_GETRECT, (WPARAM)lpnmTB->iItem, (LPARAM)&rc);
    
       MapWindowPoints(lpnmTB->hdr.hwndFrom, HWND_DESKTOP, (LPPOINT)&rc, 2);                         
    
       tpm.cbSize = sizeof(TPMPARAMS);
       tpm.rcExclude = rc;
       hPopupMenu = GetSubMenu(LoadMenu(GetModuleHandle(NULL),MAKEINTRESOURCE(ID_MAINMENU)), nIndex);
    
       TrackPopupMenuEx(hPopupMenu, TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL, rc.left, rc.bottom, hwnd, &tpm); 
    }
    
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
       static HWND Rebar, ToolBar;
       
       switch (message)
       {
          case WM_CREATE:
          {
             REBARINFO RebarInfo;
             REBARBANDINFO RebarBandInfo;
             RECT Rc;
             
             Rebar = CreateWindowEx(WS_EX_TOOLWINDOW,REBARCLASSNAME,NULL,WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|RBS_VARHEIGHT|RBS_BANDBORDERS|RBS_DBLCLKTOGGLE|RBS_DBLCLKTOGGLE|CCS_NODIVIDER,0,0,0,0,hwnd,NULL,GetModuleHandle(NULL),NULL);
             
             if(!Rebar)
             {
                return 0;
             }
             
             RebarInfo.cbSize = sizeof(REBARINFO);
             RebarInfo.fMask = 0;
             RebarInfo.himl = (HIMAGELIST)NULL;
             
             if(!SendMessage(Rebar,RB_SETBARINFO,0,(LPARAM)&RebarInfo))
             {
                return 0;
             }
             
             RebarBandInfo.cbSize = sizeof(REBARBANDINFO);
             RebarBandInfo.fMask  = RBBIM_BACKGROUND|RBBIM_CHILD|RBBIM_CHILDSIZE|RBBIM_COLORS|RBBIM_SIZE|RBBIM_STYLE|RBBIM_TEXT; //RBBIM_HEADERSIZE|RBBIM_IDEALSIZE|RBBIM_IMAGE|RBBIM_LPARAM
             RebarBandInfo.fStyle = RBBS_FIXEDBMP|RBBS_GRIPPERALWAYS;
             RebarBandInfo.hbmBack = 0;
             
             //ToolBar
             
             TBBUTTON TbButton[3];
             
             ToolBar = CreateWindowEx(0,TOOLBARCLASSNAME,NULL,WS_CHILD|WS_VISIBLE|TBSTYLE_FLAT|TBSTYLE_LIST|CCS_NOPARENTALIGN|CCS_NORESIZE|CCS_NODIVIDER,0,0,0,0,hwnd,NULL,GetModuleHandle(NULL),NULL);
             
             SendMessage(ToolBar,TB_BUTTONSTRUCTSIZE,(WPARAM)sizeof(TBBUTTON),0);
             
             ZeroMemory(TbButton, sizeof(TbButton));
             
             TbButton[0].iBitmap = I_IMAGENONE;
             TbButton[0].iString = (INT_PTR)"Menu1";
             TbButton[0].fsState = TBSTATE_ENABLED;
             TbButton[0].fsStyle = BTNS_DROPDOWN;
             TbButton[0].idCommand = ID_MENU1;
             
             TbButton[1].iBitmap = I_IMAGENONE;
             TbButton[1].iString = (INT_PTR)"Menu2";
             TbButton[1].fsState = TBSTATE_ENABLED;
             TbButton[1].fsStyle = BTNS_DROPDOWN;
             TbButton[1].idCommand = ID_MENU2;
             
             TbButton[2].iBitmap = I_IMAGENONE;
             TbButton[2].iString = (INT_PTR)"Menu3";
             TbButton[2].fsState = TBSTATE_ENABLED;
             TbButton[2].fsStyle = BTNS_DROPDOWN;
             TbButton[2].idCommand = ID_MENU3;
             
             SendMessage(ToolBar,TB_ADDBUTTONS,sizeof(TbButton)/sizeof(TBBUTTON),(LPARAM)&TbButton);
             
             long Size = SendMessage(ToolBar,TB_GETBUTTONSIZE,0,0);
             
             GetWindowRect(ToolBar,&Rc);
             
             RebarBandInfo.lpText     = NULL;
             RebarBandInfo.hwndChild  = ToolBar;
             RebarBandInfo.cxMinChild = Rc.right - Rc.left;
             RebarBandInfo.cyMinChild = HIWORD(Size);
             RebarBandInfo.cx         = 100;
             
             SendMessage(Rebar,RB_INSERTBAND,(WPARAM)-1,(LPARAM)&RebarBandInfo);
          }break;
          
          case WM_NOTIFY:
          {
             switch (((LPNMHDR)lParam)->code)
             {
                case TBN_DROPDOWN:
                {
                   LPNMHDR lpnm = ((LPNMHDR)lParam);
                   LPNMTOOLBAR lpnmTB = ((LPNMTOOLBAR)lParam);
    
                   switch(lpnmTB->iItem)
                   {
                      case ID_MENU1:
                      {
                         ToolBarButtonDropDown(hwnd, lpnm, lpnmTB, 0);
                      }break;
                      
                      case ID_MENU2:
                      {
                         ToolBarButtonDropDown(hwnd, lpnm, lpnmTB, 1);
                      }break;
                      
                      case ID_MENU3:
                      {
                         ToolBarButtonDropDown(hwnd, lpnm, lpnmTB, 2);
                      }break;
                   }
                }break;
             }
          }break;
          
          case WM_DESTROY:
            PostQuitMessage (0);
            break;
          
          default:
            return DefWindowProc (hwnd, message, wParam, lParam);
       }
    
       return 0;
    }
    Code:
    /*resource.rc*/
    #include "resource.h"
    
    ID_MAINMENU MENU
    BEGIN
      POPUP "Menu1"
      BEGIN
        MENUITEM "Teste1", ID_TESTE1
        MENUITEM "Teste2", ID_TESTE2
        MENUITEM "Teste3", ID_TESTE3
      END
      
      POPUP "Menu2"
      BEGIN
        MENUITEM "Teste1", ID_TESTE1
        MENUITEM "Teste2", ID_TESTE2
        MENUITEM "Teste3", ID_TESTE3
      END
      
      POPUP "Menu3"
      BEGIN
        MENUITEM "Teste1", ID_TESTE1
        MENUITEM "Teste2", ID_TESTE2
        MENUITEM "Teste3", ID_TESTE3
      END
    END
    I appreciate any aid.

  4. #4
    A.I Programmer
    Join Date
    Mar 2007
    Location
    Teresina - Brazil
    Posts
    47
    I am having problems with the functions SetWindowsHookEx() and CallNextHookEx(). Where I insert this in my code?

  5. #5
    Registered User
    Join Date
    Dec 2008
    Posts
    1

    Any progress?

    Hello,

    I wondered, did you make any progress with this issue. I am trying to implement the same thing and have the same problem, though I have foudn your code very useful so far!!!

    Thanks,

    Marc

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Please do not bump old threads. If you have a similar problem, create a new thread and reference the old by link.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2009, 10:25 AM
  2. Drag and drop from Internet Explorer
    By Echidna in forum Windows Programming
    Replies: 5
    Last Post: 10-02-2002, 03:14 AM
  3. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 10:44 AM
  4. Internet Explorer - Door to troubles
    By Fordy in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 05-29-2002, 01:32 PM
  5. closing microsoft internet explorer
    By canine in forum Windows Programming
    Replies: 11
    Last Post: 03-19-2002, 09:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21