[WINAPI] Statusbar



  • Wie kann ich in ein Fenster eine Statusbar einbauen???
    PLS einfache Seite oder einfach erklärt...
    MFG DDSD



  • Warum lernst du nicht die Grundlagen? Sonst musst du ja bei jedem bisschen fragen.



  • Ich hab mir schon alle möglichen Turtorials durchgesehen und kapier nix...
    Des is überall einfach nur blöd beschrieben und nirgens gleich gemacht
    MFG DDSD



  • 1.) Header-Datei "commctrl.h" einbinden
    2.) Import Library "comctl32.lib" einbinden
    3.) InitCommonControls oder InitCommonControlsEx aufrufen
    4.) CreateWindowEx mit STATUSCLASSNAME als Fensterklassenname aufrufen
    5.) Mit SendMessage SB_XXX Nachrichten an das Status-Fenster senden um dessen Einstellungen zu ändern



  • Das mit den "SB_XXX" musst du mir mal genauer erklären. Welche Messages muss ich da genau schicken??





  • sorry das Problem hat sich schon gelöst:

    http://www.willemer.de/informatik/windows/winstatb.htm



  • Nein, bei mir nicht...
    Bei mir wird die Statusbar nicht angezeigt 😞
    Und beim Menüpunkt About kommt auch nicht das richtige.
    Und er hat jetzt beim Kompilieren einen Ressource-Fehler :(((
    Hier mal mein Code:

    main.cpp

    #include <windows.h>
    #include "resource.h"
    #include <commctrl.h>
    
    /*  Declare Windows procedure  */
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
    
    /*  Make the class name into a global variable  */
    char szClassName[ ] = "Kassensystem";
    
    int WINAPI WinMain (HINSTANCE hThisInstance,
                        HINSTANCE hPrevInstance,
                        LPSTR lpszArgument,
                        int nFunsterStil)
    
    {
        HWND hwnd;               /* This is the handle for our window */
        MSG messages;            /* Here messages to the application are saved */
        WNDCLASSEX wincl;        /* Data structure for the windowclass */
    
        /* The Window structure */
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
        wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
        wincl.cbSize = sizeof (WNDCLASSEX);
    
        /* Use default icon and mouse-pointer */
        wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
        wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
        wincl.lpszMenuName = MAKEINTRESOURCE(IDR_MYMENU);                 /* No menu */
        wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
        wincl.cbWndExtra = 0;                      /* structure or the window instance */
        /* Use Windows's default color as the background of the window */
        wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
    
        /* Register the window class, and if it fails quit the program */
        if (!RegisterClassEx (&wincl))
            return 0;
    
        /* The class is registered, let's create the program*/
        hwnd = CreateWindowEx (
               0,                   /* Extended possibilites for variation */
               szClassName,         /* Classname */
               "Kassensystem",       /* Title Text */
               WS_OVERLAPPEDWINDOW, /* default window */
               CW_USEDEFAULT,       /* Windows decides the position */
               CW_USEDEFAULT,       /* where the window ends up on the screen */
               544,                 /* The programs width */
               375,                 /* and height in pixels */
               HWND_DESKTOP,        /* The window is a child-window to desktop */
               NULL,                /* No menu */
               hThisInstance,       /* Program Instance handler */
               NULL                 /* No Window Creation data */
               );
    
        /* Make the window visible on the screen */
        ShowWindow (hwnd, nFunsterStil);
    
        /* Run the message loop. It will run until GetMessage() returns 0 */
        while (GetMessage (&messages, NULL, 0, 0))
        {
            /* Translate virtual-key messages into character messages */
            TranslateMessage(&messages);
            /* Send message to WindowProcedure */
            DispatchMessage(&messages);
        }
    
        /* The program return-value is 0 - The value that PostQuitMessage() gave */
        return messages.wParam;
    }
    
    HWND CreateStatusBar(HWND hWnd, UINT ResID)
    {
        HWND hWndStatus;
        HINSTANCE hInst;
    
    	hWndStatus = CreateWindowEx (0L, // extended style
    		STATUSCLASSNAME, "",
    		WS_CHILD | WS_BORDER | WS_VISIBLE | SBS_SIZEGRIP, // window styles
    		0, 0, 0, 0, // x, y, width, height
    		hWnd, (HMENU)ResID, hInst, NULL);
    	return hWndStatus;
    }
    
    BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
        switch(Message)
        {
            case WM_INITDIALOG:
                return TRUE;
            case WM_COMMAND:
                switch(LOWORD(wParam))
                {
                    case IDOK:
                        EndDialog(hwnd, IDOK);
                        break;
                }
                break;
            default:
                return FALSE;
        }
        return TRUE;
        //DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(ID_HELP_ABOUT), hwnd, AboutDlgProc);
    }
    
    /*  This function is called by the Windows function DispatchMessage()  */
    
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        static UINT Id;
        HWND hwndStatus;
        HWND hwndList;
    
        switch (message)                  /* handle the messages */
        {
            case WM_SIZE:
                RECT rSB;
                GetWindowRect(hwndStatus, &rSB);
                MoveWindow (hwndStatus, 0, HIWORD(lParam) - 10, LOWORD(lParam), HIWORD(lParam), TRUE);
               // MoveWindow(hwndList, 0, rcl.bottom - rcl.top, LOWORD(lParam), HIWORD(lParam) - (rSB.bottom - rSB.top) + 1, TRUE );
            break;
    
            case WM_COMMAND:
                Id = LOWORD(wParam); 
                switch (Id) {
                    case ID_HELP_\1:
                    {
                        int ret = DialogBox(GetModuleHandle(NULL),MAKEINTRESOURCE(ID_HELP_ABOUT), hwnd, AboutDlgProc);
                        if(ret == IDOK){
                            MessageBox(hwnd, "Dialog exited with IDOK.", "Notice", MB_OK | MB_ICONINFORMATION);
                        }  
                        else if(ret == -1){
                            MessageBox(hwnd, "Dialog failed!", "Error", MB_OK | MB_ICONINFORMATION);
                        }
                    }
                    break;
    
                    case ID_DATEI_OPEN:
                        break;
                    case ID_DATEI_EXIT:
                        PostMessage(hwnd, WM_CLOSE, 0, 0);
                        break;
                    case ID_KS_LOGIN:
                        EnableMenuItem(GetMenu(hwnd), ID_KS_LOGIN, MF_GRAYED);
                        EnableMenuItem(GetMenu(hwnd), ID_KS_LOGOUT, MF_ENABLED);
                        break;
                    case ID_KS_LOGOUT:
                        EnableMenuItem(GetMenu(hwnd), ID_KS_LOGOUT, MF_GRAYED);
                        EnableMenuItem(GetMenu(hwnd), ID_KS_LOGIN, MF_ENABLED);
                        break;
                }    
                break;
    
            case WM_DESTROY:
                PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
                break;
            default:                      /* for messages that we don't deal with */
                return DefWindowProc (hwnd, message, wParam, lParam);
        }
    
        return 0;
    }
    
    void SetStatusText(HWND hWndStatus, char *Text)
    {
        HWND hwnd;
        HWND hStatus;
        hStatus = CreateWindowEx(0, STATUSCLASSNAME, NULL,
    WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP, 0, 0, 0, 0,
    hwnd, (HMENU)IDC_MAIN_STATUS, GetModuleHandle(NULL), NULL);
    
    	SendMessage (hWndStatus, SB_SETTEXT, 0, (LPARAM)Text);
    
    static int aWidths [2] = {200,300};
       SendMessage (hWndStatus, SB_SETPARTS, 2, (LPARAM)aWidths); 
       SendMessage (hWndStatus, SB_SETTEXT, 0, (LPARAM)"Linkes Feld");
       SendMessage (hWndStatus, SB_SETTEXT, 1, (LPARAM)"noch n Feld");
    
    }
    

    resource.h

    #define IDR_MYMENU 101
    
    #define IDC_MAIN_STATUS 2001
    
    #define IDC_STATIC 5001
    
    #define ID_DATEI_OPEN 9001
    #define ID_DATEI_SAVEAS 9002
    #define ID_DATEI_EXIT 9003
    #define ID_KS_LOGIN 9004
    #define ID_KS_LOGOUT 9005
    #define ID_HELP_ABOUT 9006
    

    menu.rc

    #include "resource.h"
    
    IDR_MYMENU MENU DISCARDABLE 
    BEGIN
        POPUP "&Datei"
        BEGIN
            MENUITEM "Ö&ffnen...",                  ID_DATEI_OPEN
            MENUITEM "&Speichern als...",           ID_DATEI_SAVEAS
            MENUITEM SEPARATOR
            MENUITEM "&Beenden",                    ID_DATEI_EXIT
        END
        POPUP "&Kassensystem"
        BEGIN
            MENUITEM "Log&in",                  ID_KS_LOGIN
            MENUITEM "Log&out",                  ID_KS_LOGOUT, GRAYED
        END
        POPUP "&Help"
        BEGIN
            MENUITEM "&About...",                  ID_HELP_ABOUT
        END
    END
    

    about.rc

    #include "resource.h"
    
    ID_HELP_ABOUT DIALOG DISCARDABLE 0, 0, 239, 66
    STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION "My About Box"
    FONT 8, "MS Sans Serif"
    BEGIN
        DEFPUSHBUTTON "&OK",IDOK,174,18,50,14
        GROUPBOX "About this program...",IDC_STATIC,7,7,225,52
        CTEXT "An example program showing how to use Dialog Boxes\r\n\r\nby theForger",
        IDC_STATIC,16,18,144,33
    END
    

    MFG DDSD



  • Punkt 3 hast du schonmal nicht beachtet.



  • Hab es nicht nach algorithmus gemacht, sondern nach einer Beschreibung...
    MFG DDSD



  • ist mir doch scheiss egal. ich dachte du willst hilfe. 😡



  • Brauchst ned gleich wild werden...
    Hab die Zeilen einfach ned verstanden
    MFG DDSD



  • ok dann fiel spaß noch. 😡 😡



  • ???
    Was is denn jetzt???
    Nur weil ich mich ned auskenn ???
    Naja, ich hoff ich finde wen anderen, der mir helfen kann...



  • Keiner wird dir helfen.
    Du musst schon selber lernen, für 2000 Scheine mach ich dir das 😕



  • Was meinst du mach ich???
    Ich durchforste das INEt und alles was man bekommst sind dumme antowortren von ForenUsern, Sexseiten, Turtaorials in Russisch und nichts brauchbarens...



  • http://www.win-api.de/
    http://www.winapi.net/

    So wenn das nicht hilft:

    www.raus.de/crashme

    oder aber

    1000 Scheine in Bar auf mein Konto

    Rabatt für Freunde 😉



  • du bemühst dich überhaupt nicht. du hast den tipp bekommen das du punkt 3 noch beachten musst. was klappt an der umsetzung von punkt 3 nicht?



  • WA.de ... da is weder menü noch statusbar...oder ich bin blind
    .net ... naja, das is noch weniger als .de



  • Regt euch ab, kerine Beleidungen!!!

    Du hast in WndProc (weiß jetzt nicht mehr, wie du das genannt hast. Halt dam Callback, des Windows, im welchem die Statusbar angezeigt werden soll) eine wichtige Sache vergessen:

    Es muss nämlich erst die Statusbar initialiesiert werden:

    Diese muss initialiesiert werden, sobald du ein Fenster von dem Typ "szClassName" erzeugst.

    Dann wird die Message WM_CREATE aufgerufen, in den ode musst du also folgemdes einfügen:

    case WM_CREATE:
    createstutusbar(hWnd, ....);
    return 0;
    

    Diesen Code solltest du nicht komplett übernehemn, wiel ich nicht die Namen verwebdet hab, die du verwendet hast. Aber ich hoffe du verstehst was ich dir mit diesem Beitrag sagen wollte...........


Anmelden zum Antworten