如题,不用MFC。请把源码帖出来,大家讨论一下吧。

解决方案 »

  1.   

    MSDN里的// CreateAToolBar creates a toolbar and adds a set of buttons to it.
    // The function returns the handle to the toolbar if successful, 
    // or NULL otherwise. 
    // hwndParent is the handle to the toolbar's parent window. 
    HWND CreateAToolBar(HWND hwndParent) 

       HWND hwndTB; 
       TBADDBITMAP tbab; 
       TBBUTTON tbb[3]; 
       char szBuf[16]; 
       int iCut, iCopy, iPaste;
       INITCOMMONCONTROLSEX icex;
        
    // Ensure that the common control DLL is loaded. 
       icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
       icex.dwICC  = ICC_BAR_CLASSES;
       InitCommonControlsEx(&icex);
     
    // Create a toolbar. 
       hwndTB = CreateWindowEx(0, TOOLBARCLASSNAME, (LPSTR) NULL, 
            WS_CHILD | CCS_ADJUSTABLE, 0, 0, 0, 0, hwndParent, 
            (HMENU) ID_TOOLBAR, g_hinst, NULL); 
     
    // Send the TB_BUTTONSTRUCTSIZE message, which is required for 
    // backward compatibility. 
       SendMessage(hwndTB, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0); 
     
    // Add the button strings to the toolbar's internal string list. 
       LoadString(g_hinst, IDS_CUT, szBuf, MAX_LEN-1); 
    //Save room for second null terminator.
       szBuf[lstrlen(szBuf) + 1] = 0;  //Double-null terminate. 
       iCut = SendMessage(hwndTB, TB_ADDSTRING, 0, (LPARAM) (LPSTR) szBuf); 
       LoadString(g_hinst, IDS_COPY, szBuf, MAX_LEN-1);  
    //Save room for second null terminator. 
       szBuf[lstrlen(szBuf) + 1] = 0;  //Double-null terminate. 
       iCopy = SendMessage(hwndTB, TB_ADDSTRING, (WPARAM) 0, 
           (LPARAM) (LPSTR) szBuf); 
       LoadString(g_hinst, IDS_PASTE, szBuf, MAX_LEN-1);  
    //Save room for second null terminator.
       szBuf[lstrlen(szBuf) + 1] = 0;  //Double-null terminate.  
       iPaste = SendMessage(hwndTB, TB_ADDSTRING, (WPARAM) 0, 
            (LPARAM) (LPSTR) szBuf); 
     
    // Fill the TBBUTTON array with button information, and add the 
    // buttons to the toolbar. The buttons on this toolbar have text 
    // but do not have bitmap images. 
       tbb[0].iBitmap = I_IMAGENONE; 
       tbb[0].idCommand = IDS_CUT; 
       tbb[0].fsState = TBSTATE_ENABLED; 
       tbb[0].fsStyle = BTNS_BUTTON; 
       tbb[0].dwData = 0; 
       tbb[0].iString = iCut;
     
       tbb[1].iBitmap = I_IMAGENONE; 
       tbb[1].idCommand = IDS_COPY; 
       tbb[1].fsState = TBSTATE_ENABLED; 
       tbb[1].fsStyle = BTNS_BUTTON; 
       tbb[1].dwData = 0; 
       tbb[1].iString = iCopy; 
     
       tbb[2].iBitmap = I_IMAGENONE; 
       tbb[2].idCommand = IDS_PASTE; 
       tbb[2].fsState = TBSTATE_ENABLED; 
       tbb[2].fsStyle = BTNS_BUTTON; 
       tbb[2].dwData = 0; 
       tbb[2].iString = iPaste; 
     
       SendMessage(hwndTB, TB_ADDBUTTONS, (WPARAM) NUM_BUTTONS, 
            (LPARAM) (LPTBBUTTON) &tbb); 
     
       SendMessage(hwndTB, TB_AUTOSIZE, 0, 0);    ShowWindow(hwndTB, SW_SHOW); 
       return hwndTB; 

      

  2.   

    忘了说明一下,我用的是DialogBox函数生成的窗体。试过msdn上的使用Statusbar的例子,用CreateWindowEx成功返回状态栏的句柄,但在窗体上却不可见!!!
      

  3.   

    // DoCreateStatusBar - creates a status bar and divides it into 
    //     the specified number of parts. 
    // Returns the handle to the status bar. 
    // hwndParent - parent window for the status bar. 
    // nStatusID - child window identifier. 
    // hinst - handle to the application instance. 
    // nParts - number of parts into which to divide the status bar. 
    HWND DoCreateStatusBar(HWND hwndParent, int nStatusID, 
        HINSTANCE hinst, int nParts) 

        HWND hwndStatus; 
        RECT rcClient; 
        HLOCAL hloc; 
        LPINT lpParts; 
        int i, nWidth; 
     
        // Ensure that the common control DLL is loaded. 
        InitCommonControls(); 
     
        // Create the status bar. 
        hwndStatus = CreateWindowEx( 
            0,                       // no extended styles 
            STATUSCLASSNAME,         // name of status bar class 
            (LPCTSTR) NULL,          // no text when first created 
            SBARS_SIZEGRIP |         // includes a sizing grip 
            WS_CHILD,                // creates a child window 
            0, 0, 0, 0,              // ignores size and position 
            hwndParent,              // handle to parent window 
            (HMENU) nStatusID,       // child window identifier 
            hinst,                   // handle to application instance 
            NULL);                   // no window creation data 
     
        // Get the coordinates of the parent window's client area. 
        GetClientRect(hwndParent, &rcClient); 
     
        // Allocate an array for holding the right edge coordinates. 
        hloc = LocalAlloc(LHND, sizeof(int) * nParts); 
        lpParts = LocalLock(hloc); 
     
        // Calculate the right edge coordinate for each part, and 
        // copy the coordinates to the array. 
        nWidth = rcClient.right / nParts; 
        for (i = 0; i < nParts; i++) { 
            lpParts[i] = nWidth; 
            nWidth += nWidth; 
        } 
     
        // Tell the status bar to create the window parts. 
        SendMessage(hwndStatus, SB_SETPARTS, (WPARAM) nParts, 
            (LPARAM) lpParts); 
     
        // Free the array, and return. 
        LocalUnlock(hloc); 
        LocalFree(hloc); 
        return hwndStatus; 

     
      

  4.   

    你有
        // Ensure that the common control DLL is loaded. 
        InitCommonControls(); 
    这一句吗?
      

  5.   

    有啊,我用的listview一却都正常,以前没有在SDK的程序里用过Statusbar和Toolbar,无从下手,还请多多指教!
      

  6.   

    http://www.yesky.com/SoftChannel/72342371928702976/20020730/1622727.shtml
      

  7.   

    hStatus=DoCreateStatusBar(hWnd,123,hInst,3);
    ShowWindow(hStatus,SW_SHOW); //你ShowWindow了没有?
      

  8.   

    刚试了一下,果然是没有用ShowWindow的原故,太感谢楼上的朋友。
    不过为什么我的窗体大小变化时,状态栏不是由Windows重新设置大小和位置,还要由程序员自已写代码吗?
      

  9.   

    在对话框如果不行的话,试试MoveWindow() 把StatusBar移到想要的位置。
      

  10.   

    在对话框里用的状态栏好象在ClientRect里,看来我的控件的位置都要重排了。