CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2011
    Posts
    6

    Unable to add custom icon / bitmap to command bar - WinCE 5 API

    I am able to add system icons to a command bar, but when I try to add my own, I just get a blank button. I have tried several configurations, a bitmap vs. an icon, and it still shows up as blank. Since I was testing with a system icon, that code is commented out.

    Here is my button structure:

    Code:
    // File bar button structure
    const TBBUTTON tbCBStdBtns[] =
    {
    // BitmapIndex Command State Style UserData String
    // {STD_FILENEW, IDC_NEW, TBSTATE_ENABLED,
    // TBSTYLE_BUTTON, 0, 0},
    {IDB_SQUARED16, IDC_SQUAREDSHIPPING,
    TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0}
    };
    
    Here is the creation:
    
    case WM_CREATE:
    // Create the command bar
    g_hWndCommandBar = CommandBar_Create(g_hInst, hWnd, IDC_CMDBAR);
    CommandBar_AddBitmap (g_hWndCommandBar, g_hInst, IDB_SQUARED16, 1, 0, 0);
    //CommandBar_AddBitmap (g_hWndCommandBar, HINST_COMMCTRL, IDB_STD_SMALL_COLOR, STD_BMPS, 0, 0);
    CommandBar_AddButtons(g_hWndCommandBar, 1, &tbCBStdBtns);
    //CommandBar_AddButtons(g_hWndCommandBar, 1, &tbCBStdBtns);
    CommandBar_InsertMenubar(g_hWndCommandBar, g_hInst, IDR_MENU, 1);
    Note that I want the icon to the left of the menu (originally I wanted the icon on the title bar, but apparently it is not supported in WinCE). I'm pretty new at this, so I apologize in advance if my code inclusion does not follow this website's standards. I will certainly provide the files if necessary.

    Thanks in advance!
    Last edited by MasterWill; July 1st, 2011 at 02:12 PM.

  2. #2
    Join Date
    Jun 2011
    Posts
    6

    Re: Unable to add custom icon / bitmap to command bar - WinCE 5 API

    Update:

    My bitmap appears when I add dummy buttons, but it's out of place. There are now 6 buttons (including the separator) and mine is last in the list despite changing the order in the button structure and ID numbers. Here is the current code:

    Code:
    const TBBUTTON tbCBStdBtns[] = 
    {
    //  BitmapIndex       Command			  State			   Style		 UserData String
    	{IDB_BITMAP16C2, IDC_SQUAREDSHIPPING, TBSTATE_ENABLED, TBSTYLE_BUTTON,    0,   0},
    	{0,               0,         0,          TBSTYLE_SEP,        0,  0},
        {STD_FILENEW,     IDC_NEW,   TBSTATE_ENABLED,
                                                 TBSTYLE_BUTTON,     0,  0},
        {STD_FILEOPEN,    IDC_OPEN,  TBSTATE_ENABLED,
                                                 TBSTYLE_BUTTON,     0,  0},
        {STD_PROPERTIES,  IDC_PROP,  TBSTATE_ENABLED,
                                                 TBSTYLE_BUTTON,     0,  0},
        {STD_CUT,         IDC_CUT,   TBSTATE_ENABLED,
                                                 TBSTYLE_BUTTON,     0,  0},
    
    };
    
    // ...
    
    case WM_CREATE:
    			// Create the command bar
    
    			err = ::GetLastError (); count = ::FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_MAX_WIDTH_MASK, NULL, err, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &p_text, 0, NULL);
    			//MessageBox(NULL, p_text, TEXT("Error"), MB_ICONERROR);
    
    			g_hWndCommandBar = CommandBar_Create(g_hInst, hWnd, IDC_CMDBAR);
    			err = ::GetLastError (); count = ::FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_MAX_WIDTH_MASK, NULL, err, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &p_text, 0, NULL);
    			//if(!g_hWndCommandBar || 1) MessageBox(NULL, p_text, TEXT("Error"), MB_ICONERROR);
    
    			i = CommandBar_AddBitmap (g_hWndCommandBar, g_hInst, IDB_BITMAP16C2, 1, 0, 0);
    			//i = CommandBar_AddBitmap (g_hWndCommandBar, NULL, (int)LoadBitmap (g_hInst, TEXT ("IDB_BITMAP16C")), 1, 0, 0);
    			err = ::GetLastError (); count = ::FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_MAX_WIDTH_MASK, NULL, err, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &p_text, 0, NULL);
    			if(i == -1) MessageBox(NULL, p_text, TEXT("AddBitmap Error"), MB_ICONERROR);
    			
    			result = CommandBar_AddButtons(g_hWndCommandBar, dim(tbCBStdBtns), tbCBStdBtns);
    			//result = CommandBar_AddButtons(g_hWndCommandBar, 1, tbCBStdBtns);
    			//result = CommandBar_InsertButton (g_hWndCommandBar, 0, &tbCBStdBtns);
    			err = ::GetLastError (); count = ::FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_MAX_WIDTH_MASK, NULL, err, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &p_text, 0, NULL);
    			if(result != 1) MessageBox(NULL, p_text, TEXT("AddButtons Error"), MB_ICONERROR);
    			
    			CommandBar_InsertMenubar(g_hWndCommandBar, g_hInst, IDR_MENU, 1);
    			err = ::GetLastError (); count = ::FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_MAX_WIDTH_MASK, NULL, err, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &p_text, 0, NULL);
    			//MessageBox(NULL, p_text, TEXT("Error"), MB_ICONERROR);
    Any advice? Could this be a bug? (sorry for my messy commented code)
    Last edited by MasterWill; July 1st, 2011 at 02:12 PM.

  3. #3
    Join Date
    Jun 2011
    Posts
    6

    Resolved Re: Unable to add custom icon / bitmap to command bar - WinCE 5 API

    SOLVED

    So i guess the iBitmap parameter of the TBBUTTON structure is supposed to be the index of the array, not the ID number. The examples I was using (from the Boling book) put the IDs there, which may work for many buttons. Since I just want one button to act as a System menu (until I figure out how to add one in the title bar in Windows CE), I changed the value to 0 and deleted the temporary dummy buttons.


    Code:
    const TBBUTTON tbCBStdBtns[] =
    {
    // BitmapIndex Command State Style UserData String
    {0, IDC_SQUAREDSHIPPING, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
    
    };
    Attached Images Attached Images  
    Last edited by MasterWill; July 1st, 2011 at 02:11 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured