Last Updated 2003/02/28
Programming Tips Visual C++ MFC ステータスバー  索 引 
ステータスバーの作成
2003/02/28

ステータスバーを作成する.

    hWndStatus = CreateWindowEx ( 0L, STATUSCLASSNAME,
                                    "",                     // window title
                                    WS_CHILD | WS_BORDER | WS_VISIBLE | SBS_SIZEGRIP,   // window styles
                                    0, 0, 0, 0,             // x, y, width, height
                                    hWnd,                   // parent window
                                    (HMENU)IDM_STATUS,      // ID
                                    hInst,                  // instance
                                    NULL);                  // window data

ステータスバーを5つの領域に分ける.
SendMessage (hWndStatus, SB_SETPARTS, 5, (LPARAM)aWidths);

1番目に文字を書く
SendMessage (hWndStatus, SB_SETTEXT, 0 | SBT_NOBORDERS, (LPARAM)"Hello");
くぼみをつける場合
SendMessage (hWndStatus, SB_SETTEXT, 1, (LPARAM)"Hello");

アイコンを貼り付ける
SendMessage (hWndStatus, SB_SETTEXT, 3 | SBT_OWNERDRAW, (LPARAM)hIcon);
あとは親ウィンドウで WM_DRAWITEM を処理する.
    case WM_DRAWITEM:
        if( (int)wParam == IDM_STATUS ) {
            LPDRAWITEMSTRUCT lpDis;
            lpDis = (LPDRAWITEMSTRUCT)lParam;
            DrawIconEx(lpDis->hDC,
                    lpDis->rcItem.left, lpDis->rcItem.top,
                    hIcon,
                    16, 16, 0,
                    SelectObject(lpDis->hDC, GetStockObject(WHITE_BRUSH)), DI_NORMAL);
        }
        break;


親ウィンドウのサイズ変更に対応するには WM_SIZE を処理する.

    case WM_SIZE:
        MoveWindow(hWndStatus, 0, HIWORD(lParam) - bPos, LOWORD(lParam),bPos, TRUE);
        //ここでステータスバーのサイズを再宣言する
        aWidths[0] = LOWORD(lParam) / 8;
        aWidths[1] = LOWORD(lParam) / 8 + aWidths [0];
        aWidths[2] = LOWORD(lParam) / 4 + aWidths [1];
        aWidths[3] = 20+aWidths [2];        //icon用の領域
        aWidths[4] = -1; 
        SendMessage(hWndStatus, SB_SETPARTS, 5, (LPARAM)aWidths);
        break;


参照
前後のTips
ステータスバーの作成

DSS ProgrammingTipsCGI Ver2.02