Menu

Bitmaps

2007-08-19
2012-09-26
  • Martian Man

    Martian Man - 2007-08-19

    How do I make a new bitmap in the secondary menu with the new, open, save, and so on pictures?

     
    • Osito

      Osito - 2007-08-19

      Are you talking about a toolbar, where you have additional icons for doing common tasks?

       
    • Anonymous

      Anonymous - 2007-08-19

      Uh!?

       
    • Martian Man

      Martian Man - 2007-08-20

      In response to Osito, yes that toolbar. Please respond. Thanks!

       
      • Osito

        Osito - 2007-08-20

        I had a tough time finding examples of that. I think maybe the Microsoft suite of tools has a wizard for toolbars, so not many people do it from code? I did eventually get it to work. Here is an example. It is called from within the WM_CREATE case. It is right after the main window is created (also after InitCommonControls() is called, which requires #include <commctrl.h>).

        I have TOOLBAR_NUMBER_OF_BUTTONS and all of the indices used in the tbb array defined in my .h file to make it easier to rearrange the buttons.

        You will also need a line like this in your resource file: IDB_TB_BITMAP BITMAP "buttons.bmp" and a #define for the IDB_TB_BITMAP. The bitmap is just a bunch of buttons side by side. In my case it is 416x32 pixels, because I have 13 buttons that are 32x32.

        I think there's something else too, but it escapes me ATM.

        void CreateToolBar(HWND hwnd)
        {
        TBBUTTON tbb[TOOLBAR_NUMBER_OF_BUTTONS];
        TBADDBITMAP new_buttons;
        int i;

        // create window
        g_hToolBar = CreateWindowEx(0,TOOLBARCLASSNAME,NULL,WS_CHILD|WS_VISIBLE|WS_BORDER,0,0,0,0,hwnd,(HMENU)ID_TOOLBAR,g_hInst,NULL);

        // tell it the size of the structure
        SendMessage(g_hToolBar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);

        // set bitmap size
        SendMessage(g_hToolBar,TB_SETBITMAPSIZE,0,MAKELONG(32,32));

        // load bitmaps
        new_buttons.hInst = g_hInst;
        new_buttons.nID=IDB_TB_BITMAP;
        SendMessage(g_hToolBar,TB_ADDBITMAP,TOOLBAR_NUMBER_OF_BITMAPS,(LPARAM)&new_buttons);

        // clear button structures and set info
        ZeroMemory(tbb, sizeof(tbb));

        // fill with separators by default
        for (i=0;i<TOOLBAR_NUMBER_OF_BUTTONS;i++) {tbb[i].fsStyle = TBSTYLE_SEP;}

        tbb[TOOLBAR_START].iBitmap = TOOLBAR_BITMAP_START;
        tbb[TOOLBAR_START].fsState = TBSTATE_ENABLED;
        tbb[TOOLBAR_START].fsStyle = TBSTYLE_BUTTON;
        tbb[TOOLBAR_START].idCommand = CM_STARTLOGGING;
        tbb[TOOLBAR_START].iString = (int)"Start";

        tbb[TOOLBAR_STOP].iBitmap = TOOLBAR_BITMAP_STOP;
        tbb[TOOLBAR_STOP].fsState = TBSTATE_ENABLED;
        tbb[TOOLBAR_STOP].fsStyle = TBSTYLE_BUTTON;
        tbb[TOOLBAR_STOP].idCommand = CM_STOPLOGGING;
        tbb[TOOLBAR_STOP].iString = (int)"Stop";

        tbb[TOOLBAR_ABORT].iBitmap = TOOLBAR_BITMAP_ABORT;
        tbb[TOOLBAR_ABORT].fsState = TBSTATE_ENABLED;
        tbb[TOOLBAR_ABORT].fsStyle = TBSTYLE_BUTTON;
        tbb[TOOLBAR_ABORT].idCommand = CM_CHAMBERABORT;
        tbb[TOOLBAR_ABORT].iString = (int)"Reset";

        tbb[TOOLBAR_SETTINGS].iBitmap = TOOLBAR_BITMAP_SETTINGS;
        tbb[TOOLBAR_SETTINGS].fsState = TBSTATE_ENABLED;
        tbb[TOOLBAR_SETTINGS].fsStyle = TBSTYLE_BUTTON;
        tbb[TOOLBAR_SETTINGS].idCommand = CM_READSETTINGS;
        tbb[TOOLBAR_SETTINGS].iString = (int)"Settings";

        tbb[TOOLBAR_IDS].iBitmap = TOOLBAR_BITMAP_IDS;
        tbb[TOOLBAR_IDS].fsState = TBSTATE_ENABLED;
        tbb[TOOLBAR_IDS].fsStyle = TBSTYLE_BUTTON;
        tbb[TOOLBAR_IDS].idCommand = CM_READIDS;
        tbb[TOOLBAR_IDS].iString = (int)"IDs";

        tbb[TOOLBAR_CELCIUS].iBitmap = TOOLBAR_BITMAP_CELCIUS;
        tbb[TOOLBAR_CELCIUS].fsState = TBSTATE_ENABLED;
        tbb[TOOLBAR_CELCIUS].fsStyle = TBSTYLE_BUTTON;
        tbb[TOOLBAR_CELCIUS].idCommand = CM_READCHAMBERSTATUS;
        tbb[TOOLBAR_CELCIUS].iString = (int)"Status";

        tbb[TOOLBAR_INFO].iBitmap = TOOLBAR_BITMAP_INFO;
        tbb[TOOLBAR_INFO].fsState = TBSTATE_ENABLED;
        tbb[TOOLBAR_INFO].fsStyle = TBSTYLE_BUTTON;
        tbb[TOOLBAR_INFO].idCommand = CM_SHOWDEVINFO;
        tbb[TOOLBAR_INFO].iString = (int)"Info";

        tbb[TOOLBAR_PLUS].iBitmap = TOOLBAR_BITMAP_PLUS;
        tbb[TOOLBAR_PLUS].fsState = TBSTATE_ENABLED;
        tbb[TOOLBAR_PLUS].fsStyle = TBSTYLE_BUTTON;
        tbb[TOOLBAR_PLUS].idCommand = CM_PLUS;
        tbb[TOOLBAR_PLUS].iString = (int)"Increase";

        tbb[TOOLBAR_MINUS].iBitmap = TOOLBAR_BITMAP_MINUS;
        tbb[TOOLBAR_MINUS].fsState = TBSTATE_ENABLED;
        tbb[TOOLBAR_MINUS].fsStyle = TBSTYLE_BUTTON;
        tbb[TOOLBAR_MINUS].idCommand = CM_MINUS;
        tbb[TOOLBAR_MINUS].iString = (int)"Decrease";

        tbb[TOOLBAR_HELP].iBitmap = TOOLBAR_BITMAP_HELP;
        tbb[TOOLBAR_HELP].fsState = TBSTATE_ENABLED;
        tbb[TOOLBAR_HELP].fsStyle = TBSTYLE_BUTTON;
        tbb[TOOLBAR_HELP].idCommand = CM_HELP_ABOUT;
        tbb[TOOLBAR_HELP].iString = (int)"About";

        tbb[TOOLBAR_GOBACK].iBitmap = TOOLBAR_BITMAP_BACK;
        tbb[TOOLBAR_GOBACK].fsState = TBSTATE_ENABLED;
        tbb[TOOLBAR_GOBACK].fsStyle = TBSTYLE_BUTTON;
        tbb[TOOLBAR_GOBACK].idCommand = CM_GOBACK;
        tbb[TOOLBAR_GOBACK].iString = (int)"Back";

        tbb[TOOLBAR_GOFORWARD].iBitmap = TOOLBAR_BITMAP_FORWARD;
        tbb[TOOLBAR_GOFORWARD].fsState = TBSTATE_ENABLED;
        tbb[TOOLBAR_GOFORWARD].fsStyle = TBSTYLE_BUTTON;
        tbb[TOOLBAR_GOFORWARD].idCommand = CM_GOFORWARD;
        tbb[TOOLBAR_GOFORWARD].iString = (int)"Forward";

        tbb[TOOLBAR_STEST].iBitmap = TOOLBAR_BITMAP_STEST;
        tbb[TOOLBAR_STEST].fsState = TBSTATE_ENABLED;
        tbb[TOOLBAR_STEST].fsStyle = TBSTYLE_BUTTON;
        tbb[TOOLBAR_STEST].idCommand = CM_SERIALTEST;
        tbb[TOOLBAR_STEST].iString = (int)"COM Scan";

        // add buttons to toolbar
        SendMessage(g_hToolBar,TB_ADDBUTTONS,TOOLBAR_NUMBER_OF_BUTTONS,(LPARAM)&tbb);

        // is this even necessary?
        SendMessage(g_hToolBar,TB_AUTOSIZE,0,0);
        }

         
        • Osito

          Osito - 2007-08-20

          I forgot this, in your main case statement. I also have a statusbar - if you don't you'll have to rewrite it a little to get rid of that stuff.

            case WM_SIZE:
            {
               RECT rectClient, rectStatus, rectTool;
               UINT uToolHeight, uStatusHeight, uClientAlreaHeight, uStatusSegmentWidth;
          
               SendMessage(g_hToolBar, TB_AUTOSIZE, 0, 0);
               SendMessage(g_hStatusBar, WM_SIZE, 0, 0);
          
               GetClientRect(hwnd, &amp;rectClient);
               GetWindowRect(g_hStatusBar, &amp;rectStatus);
               GetWindowRect(g_hToolBar, &amp;rectTool);
          
               uToolHeight = rectTool.bottom - rectTool.top;
               uStatusHeight = rectStatus.bottom - rectStatus.top;
               uClientAlreaHeight = rectClient.bottom;
          
               uStatusSegmentWidth = (rectClient.right-rectClient.left)/STATUSBAR_NUMBER_OF_SEGMENTS;
               for(i=0;i&lt;STATUSBAR_NUMBER_OF_SEGMENTS-1;i++) {statusbar_width[i]=uStatusSegmentWidth*(i+1);}
               statusbar_width[STATUSBAR_NUMBER_OF_SEGMENTS-1]=-1;
          
               MoveWindow(GetDlgItem(hwnd, IDC_MAIN_TEXT), 0, uToolHeight, rectClient.right, uClientAlreaHeight - uStatusHeight - uToolHeight, TRUE);
               SendMessage(g_hStatusBar,SB_SETPARTS,(WPARAM)STATUSBAR_NUMBER_OF_SEGMENTS,(LPARAM)statusbar_width);
            }
          
           

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.