Status bar

This is a discussion on Status bar within the Windows Programming forums, part of the Platform Specific Boards category; I want to create a status bar: Code: #include <windows.h> #include <commctrl.h> #define ID_STATUSBAR 4997 /* Declare Windows procedure */ ...

  1. #1
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318

    Status bar

    I want to create a status bar:
    Code:
    #include <windows.h>
    #include <commctrl.h>
    #define ID_STATUSBAR 4997
    /*  Declare Windows procedure  */
    HWND status;
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
    
    /*  Make the class name into a global variable  */
    char szClassName[ ] = "WindowsApp";
    
    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 = NULL;                 /* 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 */
               "Windows App",       /* 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;
    }
    
    
    /*  This function is called by the Windows function DispatchMessage()  */
    
    LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){
        switch(message){
             case WM_CREATE:{
                 status=CreateWindowEx(0,STATUSCLASSNAME,NULL,WS_CHILD|WS_VISIBLE|SBARS_SIZEGRIP,
                        0,0,0,0,hwnd,(HMENU)ID_STATUSBAR,GetModuleHandle(NULL),NULL);
                 SendMessage(status, SB_SETTEXT, 0, (LPARAM)"This is a status bar!");
                 return 0;
             }
             case WM_CLOSE:
                 DestroyWindow(hwnd);
                 break;
             case WM_DESTROY:
                 PostQuitMessage(0);
                 break;
             default:
                 return DefWindowProc (hwnd, message, wParam, lParam);
       }
       return 0;
    }
    But this code won't work. Please do not post anything in Visual C++. All status bar tutorials I found were in VC++.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Before using one of the common controls you need to call initcommoncontrols/initcommoncontrolsEx.

  3. #3
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Thanks

  4. #4
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    But in this code:
    Code:
    #include <windows.h>
    #include "main.h"
    #include <string>
    #include <fstream>
    #include <direct.h>
    #include <algorithm>
    #include <process.h>
    #include <commctrl.h>
    void Function(void *P);
    CRITICAL_SECTION crit;
    LRESULT CALLBACK MainMessageHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
    HWND CreateMainWindow(int nShow);
    std::string songid,destination,basename,boogi,name,var,var2,str;
    std::ifstream fin;
    std::ofstream fer;
    HWND hww,hww2,hww3,hww4,hww5,hwnd,hStatus;
    char non[256],non2[500],non3[500],shelp[500],shelp2[256];
    HMENU menu;
    HINSTANCE hThisInstance;
    HFONT hf,hf2;
    long lf,lf2;
    HDC hdc;
    bool success;
    int gar,leng,ga;
    bool DownloadFile(LPCTSTR URL , LPCTSTR LocalFilename); 
    typedef long (WINAPI * MYPROC)(long,LPCTSTR,LPCTSTR,DWORD,long);
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE reserved, LPSTR szCommand, INT nShow)
    {
        InitCommonControls();
    	MSG msg;
        InitializeCriticalSection(&crit);
    	hwnd=CreateMainWindow(nShow);
    	while ( GetMessage(&msg, NULL, 0, 0) ){
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    	DeleteCriticalSection(&crit);
    	return (int) msg.wParam;
    }
    bool DownloadFile(LPCTSTR URL , LPCTSTR LocalFilename) 
    {        
        long lngRetVal;              
    	HMODULE hinstLib; 
        MYPROC ProcAdd;                                 
        BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
    	hinstLib = LoadLibrary("urlmon.dll");
      if(hinstLib != NULL)
      { 
    	ProcAdd = (MYPROC) GetProcAddress(hinstLib, "URLDownloadToFileA");
    	   if (NULL != ProcAdd) 
    	   {
                fRunTimeLinkSuccess = TRUE;
    		    lngRetVal = ProcAdd(0, URL, LocalFilename, 0, 0);
    		    fFreeResult = FreeLibrary(hinstLib);
    
    		}	
      }
    }
    LRESULT CALLBACK MainMessageHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    	switch (uMsg)
    	{
    		case WM_CREATE:{
                fin.open("test.txt"); gar=0;
                while(fin>>boogi){
                if(gar==0){
                name+=boogi; gar=1;}
                else{
                name+=" "; name+=boogi;}}
                *(std::copy(name.begin(), name.end() - name.begin() < 200 ? name.end() : name.begin() + 199, shelp)) = 0;
                hww=CreateWindowEx(WS_EX_CLIENTEDGE,"EDIT","",WS_CHILD|WS_VISIBLE|ES_NUMBER,
                    1,1,53,23,hwnd,(HMENU)0xED,GetModuleHandle(NULL),NULL);
                hdc = GetDC(NULL);
                hStatus=CreateWindowEx(0,STATUSCLASSNAME,"Enter",WS_CHILD|WS_VISIBLE,
                        0,0,0,0,hwnd,(HMENU)4997,GetModuleHandle(NULL),NULL);
                SendMessage(hStatus,SB_SETTEXT,0,(LPARAM)"Hetkel ei tõmba midagi");
                lf = -MulDiv(12, GetDeviceCaps(hdc, LOGPIXELSY), 72);
                lf2 = -MulDiv(10, GetDeviceCaps(hdc, LOGPIXELSY), 72);
                ReleaseDC(NULL, hdc);
                hf = CreateFont(lf, 0, 0, 0, FW_MEDIUM, FALSE, 0, 0, 0, 0, 0, 0, 0, "Times New Roman");
                SendMessage(hww,WM_SETFONT,(WPARAM)hf,TRUE);
                hf2 = CreateFont(lf2, 0, 0, 0, 500, FALSE, 0, 0, 0, 0, 0, 0, 0, "Verdana");
                hww2=CreateWindowEx(NULL,"Button","Tõmba",WS_BORDER|WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
                     56,1,80,23,hwnd,(HMENU)IDB_BUTTON,GetModuleHandle(NULL),NULL);
                SendMessage(hww2,WM_SETFONT,(WPARAM)hf2,TRUE);
                hww3=CreateWindowEx(WS_EX_CLIENTEDGE,"Edit","",WS_CHILD|WS_VISIBLE|ES_MULTILINE,
                     1,26,238,23,hwnd,(HMENU) 0xED, GetModuleHandle(NULL),NULL);
                hww4=CreateWindowEx(WS_EX_CLIENTEDGE,"EDIT",shelp,WS_CHILD|WS_VISIBLE|ES_MULTILINE,
                     1,52,238,46,hwnd,(HMENU) 0xED, GetModuleHandle(NULL),NULL);
                SendMessage(hww3,WM_SETFONT,(WPARAM)hf,TRUE);
                SendMessage(hww4,WM_SETFONT,(WPARAM)hf,TRUE);
                hww5=CreateWindowEx(NULL,"Button","Surfa unos",WS_BORDER|WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
                     139,1,90,23,hwnd,(HMENU)IDB_BUTTON2,GetModuleHandle(NULL),NULL);
                SendMessage(hww5,WM_SETFONT,(WPARAM)hf2,TRUE);
    		}
            case WM_COMMAND:
                switch(wParam){
                    case IDM_LEAVE:
                        DestroyWindow(hwnd);
                        return 0;
                    case IDM_DESTINATION:
                        MessageBox(hwnd,"Programm on täielikult illegaalne!","Programmist...",MB_OK | MB_ICONINFORMATION);
                        return 0;
                    case IDB_BUTTON2:
                        system("\"C:\\Program Files\\Internet Explorer\\iexplore.exe\" http://www.u-pop.ee/uplayer");
                        return 0;
                    case IDB_BUTTON:
                        _beginthread(Function,0,NULL);
                        return 0;
                }
                break;
            case 25688:
                if(ga==0){
                SendMessage(hStatus,SB_SETTEXT,0,(LPARAM)"Hetkel ei tõmba midagi");
                }
                else if(ga==1){
                SendMessage(hStatus,SB_SETTEXT,0,(LPARAM)"Hetkel tõmbab 1 laul");
                }
                else if(ga==2){
                SendMessage(hStatus,SB_SETTEXT,0,(LPARAM)"Hetkel tõmbab 2 laulu");
                }
                else if(ga==3){
                SendMessage(hStatus,SB_SETTEXT,0,(LPARAM)"Hetkel tõmbab 3 laulu");
                }
                else if(ga==4){
                SendMessage(hStatus,SB_SETTEXT,0,(LPARAM)"Hetkel tõmbab 4 laulu");
                }
                else if(ga==5){
                SendMessage(hStatus,SB_SETTEXT,0,(LPARAM)"Hetkel tõmbab 5 laulu");
                }            
                break;
    		case WM_SIZE:
    			RECT rc;
    			GetClientRect(hwnd, &rc);
    			return 0;
    		case WM_DESTROY:
                fin.close();
                fer.open("test.txt");
                GetWindowText(hww4,non,500);
                fer<<non;
                fer.close();
    			PostQuitMessage(0);
    			return 0;
    	}
    
    	return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }
    
    HWND CreateMainWindow(int nShow)
    {
    	WNDCLASSEX wc   = { 0 };
    	HWND       hwnd = NULL;
    
    	wc.cbSize        = sizeof(wc);
    	wc.style         = 0;
    	wc.cbClsExtra    = 0;
    	wc.cbWndExtra    = 0;
    	wc.hInstance     = GetModuleHandle(NULL);
    	wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    	wc.hIconSm       = NULL;
    	wc.lpfnWndProc   = MainMessageHandler;
    	wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    	wc.hbrBackground = (HBRUSH) (COLOR_APPWORKSPACE + 1);
    	wc.lpszMenuName  = NULL;
    	wc.lpszClassName = "Myapp";
    	if(RegisterClassEx(&wc)){
    		hwnd=CreateWindowEx(0,"Myapp","SongDownloader 2.1",WS_OVERLAPPEDWINDOW,
                 CW_USEDEFAULT,CW_USEDEFAULT,250,178,NULL,NULL,GetModuleHandle(NULL),NULL);
    		ShowWindow(hwnd, nShow);
    	}
    	menu=LoadMenu(hThisInstance,MAKEINTRESOURCE(ID_MENU));
        SetMenu(hwnd,menu);
    	return hwnd;
    }
    void Function(void *P){
        if(ga>4){
        MessageBox(hwnd,"Üle viie laulu ei saa korraga tõmmata!","Oota...",MB_OK|MB_ICONINFORMATION);
        }
        else{
        GetWindowText(hww,non,255);
        GetWindowText(hww3,non2,500);
        GetWindowText(hww4,non3,500);
        basename=non2;
        destination=non3;
        songid=non;
        if(_chdir(non3)==0){
            ga++;
            SendMessage(hwnd,25688,0,0);
            if(destination.substr(destination.length()-1,destination.length())=="\\"){
            }
            else{
            destination+="\\";
            }
            var="http://data.uno.ee/juke/songid-"+songid+"-555/songs.asx";
            var2="C:\\temp.abc";
            *(std::copy(var.begin(), var.end() - var.begin() < 200 ? var.end() : var.begin() + 199, shelp)) = 0;
            LPCTSTR URL = shelp;
            *(std::copy(var2.begin(), var2.end() - var2.begin() < 200 ? var2.end() : var2.begin() + 199, shelp2)) = 0;
            LPCTSTR File = shelp2;
            DownloadFile(URL,File);
            std::ifstream fi("C:\\temp.abc");
            fi>>str;
            fi>>str;
            fi>>str;
            fi>>str;
            fi.close();
            remove("C:\\temp.abc");
            leng=str.length();
            leng=leng-17;
            str=str.substr(6,leng);
            var=str;
            var2=destination+basename+".wma";
            *(std::copy(var.begin(), var.end() - var.begin() < 200 ? var.end() : var.begin() + 199, shelp)) = 0;
            URL = shelp;
            *(std::copy(var2.begin(), var2.end() - var2.begin() < 200 ? var2.end() : var2.begin() + 199, shelp2)) = 0;
            File = shelp2;
            success = DownloadFile(URL ,File); 
    	    if(success == false){
                MessageBox(hwnd,"Selle numbriga laulu kas ei ole või ei saanud hetkel tõmmata!","Valmis",MB_OK | MB_ICONINFORMATION);
                ga--;
                SendMessage(hwnd,25688,0,0);
            }
    	    else{
                MessageBox(hwnd,"Üks laul sai valmis!","Valmis",MB_OK | MB_ICONINFORMATION);
                ga--;
                SendMessage(hwnd,25688,0,0);
    	    }
        }
        else{
            MessageBox(hwnd,"Sisestatud kausta aadress ei ole õige!","Viga!",MB_OK | MB_ICONINFORMATION);
        }
    }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. status bar flickering
    By rakan in forum Windows Programming
    Replies: 5
    Last Post: 01-07-2008, 09:11 PM
  2. beach bar (sims type game)
    By DrKillPatient in forum Game Programming
    Replies: 1
    Last Post: 03-06-2006, 12:32 PM
  3. Troubles with Sockets
    By cornholio in forum Windows Programming
    Replies: 6
    Last Post: 10-26-2005, 05:31 AM
  4. Progress Bar in Status Bar :: No MFC
    By Okiesmokie in forum Windows Programming
    Replies: 4
    Last Post: 05-03-2002, 10:51 PM
  5. Disabling "Ready" & Other Auto Status Bar Updates :: MFC
    By kuphryn in forum C++ Programming
    Replies: 1
    Last Post: 04-03-2002, 07:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21