StatusBar-Höhe festlegen



  • Hallo Community,

    wie kann ich die Höhe einer mit CreateWindowEx() erstellten StatusBar, und die Textgröße eines PARTS darin ändern?

    Hier mein Code soweit:

    HWND hStatusBar1 = CreateWindowEx(0L, STATUSCLASSNAME, NULL, 
    	WS_CHILD | WS_BORDER | WS_VISIBLE, -100, -100, 10, 10, hFenster, 
    	(HMENU)100, hInstance, NULL);
    
    int parts[1] = {500};
    SendMessage(hStatusBar1, SB_SETPARTS, 1, (LPARAM)&parts);
    SendMessage(hStatusBar1, SB_SETTEXT, 0, (LPARAM)"ASDF"); 
    //Textgröße von diesem Element ^ soll verändert werden
    

    Danke im Voraus



  • naja ich würde es mal mit WM_SETFONT probieren



  • Danke LowFly funktioniert soweit, und wie kann ich die Höhe der StatusBar verändern? 😃


  • Mod

    Steht in der MSDN Doku.

    SB_SETMINHEIGHT
    Ansonsten alles weitere hier:
    http://msdn.microsoft.com/en-us/library/bb760728(VS.85).aspx#Size_and_Height





  • Vorweg: mein Fenster hat eine festgelegte Größe.

    Also definierte ich die Höhe der StatusBar mit:

    SendMessage(hStatusBar1, SB_SETMINHEIGHT, 150, 0);
    

    jedoch verändert sich die Größe nicht. 😕

    Und kann ich WM_SIZE überhaupt bei einem Fenster mit fixer Größe anwenden?



  • WM_SIZE wird an deine nachrichtenschleife deines programmes gesendet nachdem der benutzer die größe des programmes geändert hat. alternativ dazu WM_SIZEING.
    du könntest mal movewindow, setwindowplacement o. setwindowpos probieren.
    wobei ich zu movewindow tendiere, das benutze ich immer sobald ich eine fenstergröße nachträglich ändern will. bei den anderen beiden funktionen hab ich immer meine probleme.



  • LowFly schrieb:

    WM_SIZE wird an deine nachrichtenschleife deines programmes gesendet nachdem der benutzer die größe des programmes geändert hat. alternativ dazu WM_SIZEING.
    du könntest mal movewindow, setwindowplacement o. setwindowpos probieren.
    wobei ich zu movewindow tendiere, das benutze ich immer sobald ich eine fenstergröße nachträglich ändern will. bei den anderen beiden funktionen hab ich immer meine probleme.

    Die StatusBar bewegt sich trotz MoveWindow keinen Millimeter / verändert die Größe nicht: 😞

    HWND hStatusBar1 = CreateWindowEx( 
    		0L,									
    		STATUSCLASSNAME,					
    		NULL,								
    		WS_CHILD | WS_VISIBLE,				
    		-100, -100, 10, 10,					
    		hForm1,								
    		(HMENU)100,							
    		hInstance,                          
    	NULL);								
    
    	int parts[1] = {500};
    	HANDLE hFont = CreateFont(14, 0, 0, 0, FW_DONTCARE, FALSE, FALSE,
    		FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
    		DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, "Arial");
    
    	SendMessage(hStatusBar1, SB_SETPARTS, 1, (LPARAM)&parts);
    	SendMessage(hStatusBar1, SB_SETTEXT, 0, (LPARAM)"ASDF");
    	SendMessage(hStatusBar1, WM_SETFONT, (WPARAM)hFont, true);
    	MoveWindow(hStatusBar1, 0, 0, 50, 155, true);
    	UpdateWindow(hStatusBar1);
    


  • der einzigste grund den ich mir jetzt vorstellen könnte warum das nicht klappt, ist das du die x & y koordinaten der statusbar bei movewindow mit 0,0 angegeben hast. die wären ja in der oberen linken ecke und dort ist die statusbar niemals nicht zu finden. 🙄

    hol dir zuerst das rechteck der statusbar mit SB_GETRECT und setze davon die x & y koordinaten bei movewindow ein.

    ansonsten bin ich ratlos. ich kann dir nur sagen das ich movewindow für alle unten aufgeführten steuerelemente verwende und es überall funzt. (alle arten von Buttons, Listbox, Liste, Combobox, Tree, Tab, Edit, Richedit)


  • Mod

    SB_SETMINHEIGHT funktioniert sehr wohl.
    Man sollte einfach machn was in der MSDN steht.

    1. Statusbar erzeugen und parts setzen + SB_SETMINHEIGHT:
    Code ist aus derMSDN + Aufruf von SB_SETMINHEIGHT

    HWND DoCreateStatusBar(HWND hwndParent, int idStatus, HINSTANCE
                          hinst, int cParts)
    {
        HWND hwndStatus;
        RECT rcClient;
        HLOCAL hloc;
        PINT paParts;
        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
            (PCTSTR) NULL,           // no text when first created
            SBARS_SIZEGRIP |         // includes a sizing grip
            WS_CHILD | WS_VISIBLE,   // creates a visible child window
            0, 0, 0, 0,              // ignores size and position
            hwndParent,              // handle to parent window
            (HMENU) idStatus,       // child window identifier
            hinst,                   // handle to application instance
            NULL);                   // no window creation data
    
    	SendMessage(hwndStatus, SB_SETMINHEIGHT, 50, 0);
    
        // 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) * cParts);
        paParts = (PINT) LocalLock(hloc);
    
        // Calculate the right edge coordinate for each part, and
        // copy the coordinates to the array.
        nWidth = rcClient.right / cParts;
        for (i = 0; i < cParts; i++) { 
           paParts[i] = nWidth;
           nWidth += nWidth;
        }
    
        // Tell the status bar to create the window parts.
        SendMessage(hwndStatus, SB_SETPARTS, (WPARAM) cParts, (LPARAM)
                   paParts);
    
        // Free the array, and return.
        LocalUnlock(hloc);
        LocalFree(hloc);
        return hwndStatus;
    }
    

    2: WM_SIZE Handler im Parent einbauen:
    IDC_MAIN_STATUS ist bei mir die ID des Statusbars... siehe da

    case WM_SIZE:
    		// Auto-resize statusbar 
    		MoveWindow(hWnd,0,0,0,0,FALSE);
    		break;
    


  • Martin Richter schrieb:

    SB_SETMINHEIGHT funktioniert sehr wohl.
    Man sollte einfach machn was in der MSDN steht.

    1. Statusbar erzeugen und parts setzen + SB_SETMINHEIGHT:
    Code ist aus derMSDN + Aufruf von SB_SETMINHEIGHT

    HWND DoCreateStatusBar(HWND hwndParent, int idStatus, HINSTANCE
                          hinst, int cParts)
    {
        HWND hwndStatus;
        RECT rcClient;
        HLOCAL hloc;
        PINT paParts;
        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
            (PCTSTR) NULL,           // no text when first created
            SBARS_SIZEGRIP |         // includes a sizing grip
            WS_CHILD | WS_VISIBLE,   // creates a visible child window
            0, 0, 0, 0,              // ignores size and position
            hwndParent,              // handle to parent window
            (HMENU) idStatus,       // child window identifier
            hinst,                   // handle to application instance
            NULL);                   // no window creation data
    
    	SendMessage(hwndStatus, SB_SETMINHEIGHT, 50, 0);
    
        // 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) * cParts);
        paParts = (PINT) LocalLock(hloc);
    
        // Calculate the right edge coordinate for each part, and
        // copy the coordinates to the array.
        nWidth = rcClient.right / cParts;
        for (i = 0; i < cParts; i++) { 
           paParts[i] = nWidth;
           nWidth += nWidth;
        }
    
        // Tell the status bar to create the window parts.
        SendMessage(hwndStatus, SB_SETPARTS, (WPARAM) cParts, (LPARAM)
                   paParts);
    
        // Free the array, and return.
        LocalUnlock(hloc);
        LocalFree(hloc);
        return hwndStatus;
    }
    

    2: WM_SIZE Handler im Parent einbauen:
    IDC_MAIN_STATUS ist bei mir die ID des Statusbars... siehe da

    case WM_SIZE:
    		// Auto-resize statusbar 
    		MoveWindow(hWnd,0,0,0,0,FALSE);
    		break;
    

    Danke Martin, der Code funktioniert soweit, jedoch gibt es offenbar eine minimal-Grenze für die Höhe der StatusBar.. ab ca. 25 wird sie bei mir nicht mehr kleiner 😮


  • Mod

    Das wiederum liegt vermutlich an der Font-Größe und den Rahmen, die vorgesehen werden. Ein weiteres Kriterium ist der Gripper rechts außen.



  • Martin Richter schrieb:

    Das wiederum liegt vermutlich an der Font-Größe und den Rahmen, die vorgesehen werden. Ein weiteres Kriterium ist der Gripper rechts außen.

    Ich hab versucht den Gripper rauszunehmen und die Schriftgröße auf 3 zu stellen (Arial), jedoch will die StatusBar einfach nicht kleiner werden: 😞

    HWND DoCreateStatusBar(HWND hwndParent, int idStatus, HINSTANCE hinst, int cParts) 
    { 
    	HWND hwndStatus; 
    	RECT rcClient; 
    	HLOCAL hloc; 
    	PINT paParts; 
    	int i, nWidth; 
    
    	hwndStatus = CreateWindowEx(0, STATUSCLASSNAME, (PCTSTR) NULL, 
    		WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, 
    		hwndParent, (HMENU) idStatus, hinst, NULL);
    
    	SendMessage(hwndStatus, SB_SETMINHEIGHT, 5, 0); 
    
    	GetClientRect(hwndParent, &rcClient); 
    
    	hloc = LocalAlloc(LHND, sizeof(int) * cParts); 
    	paParts = (PINT) LocalLock(hloc); 
    
    HANDLE hFont = CreateFont(3, 0, 0, 0, FW_DONTCARE, FALSE, FALSE,
    	FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
    	DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, "Arial");
    
    SendMessage(hwndStatus, WM_SETFONT, (WPARAM)hFont, true);
    SendMessage(hwndStatus, SB_SETTEXT, 0, (LPARAM)"oqwtouqwtu");
    
    	nWidth = rcClient.right / cParts; 
    	for (i = 0; i < cParts; i++) { 
    		paParts[i] = nWidth;
    		nWidth += nWidth;
    	} 
    
    	SendMessage(hwndStatus, SB_SETPARTS, (WPARAM) cParts, (LPARAM)paParts); 
    
    	LocalUnlock(hloc); 
    	LocalFree(hloc);
    
    	return hwndStatus; 
    }
    

    Den Rahmen kann man auch noch rausnehmen ? 😮


  • Mod

    Welchen Sinn macht bitte ein 3pt hoher Statusbar.
    Was hast Du eigentlich vor?

    Wenn es so speziel ist, was Du da bauen willst dann erzeuge Dein eigenes Fenster. Das hättest Du in der Zwischenzeit schon längst fertig programmiert.



  • Martin Richter schrieb:

    Welchen Sinn macht bitte ein 3pt hoher Statusbar.
    Was hast Du eigentlich vor?

    Wenn es so speziel ist, was Du da bauen willst dann erzeuge Dein eigenes Fenster. Das hättest Du in der Zwischenzeit schon längst fertig programmiert.

    3pt. war nur ein Beispiel wo es nicht mehr funktioniert, ich glaube du hast recht, und es wäre sinnvoller das Problem auf anderem Wege zu lösen.

    Eigentlich wollte ich versuchen, wie zB. in .net die Status-Leiste noch niedriger zu machen, da mein vorgesehenes Fenster ebenso klein ist, und sonst nicht mit der StatusBar zusammenpasst. 🙄

    Danke dir für die Hilfe 👍


Anmelden zum Antworten