Displaying dwMemoryLoad ?

This is a discussion on Displaying dwMemoryLoad ? within the Windows Programming forums, part of the Platform Specific Boards category; Im pretty new to MFC, im writing this prog to display some system info, it all works fine aside from ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    3

    Unhappy Displaying dwMemoryLoad ?

    Im pretty new to MFC, im writing this prog to display some system info, it all works fine aside from the control that displays dwMemoryLoad, it should give out a percentage, but its either at 0 or 100%, presumably its typed wrong, and is being interpreted as on or off, either way, any help appreciated, my snipped function is (yes ive called the MEMORYSTATUS in my prog, it all works fine, just this):

    void COsiDlg::OnRefresh()
    {
    m_strMemLoad.Format("%d %%",
    mem_stat.dwMemoryLoad);

    UpdateData(FALSE);
    }

    Thx in advance

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Try

    m_strMemLoad.Format("%d\%",mem_stat.dwMemoryLoad);

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    3
    warning C4129: '%' : unrecognized character escape sequence

    Then it causes an assertion failure when i call the function in the program itself, ill paste the whole function incase its something im doing wrong;

    void COsiDlg::OnRefresh()
    {
    TCHAR szBuffer[256];
    DWORD dwSize = 256;

    GetComputerName(szBuffer, &dwSize);
    m_strBoxName = szBuffer;

    MEMORYSTATUS mem_stat;

    GlobalMemoryStatus(&mem_stat);

    m_strTotalPhysical.Format("%ld KB", mem_stat.dwTotalPhys / 1024);
    m_strAvailPhysical.Format("%ld KB", mem_stat.dwAvailPhys / 1024);
    m_strAvailPageFile.Format("%ld KB", mem_stat.dwAvailPageFile / 1024);
    m_strTotalVirtual.Format("%ld KB", mem_stat.dwTotalVirtual / 1024);
    m_strAvailVirtual.Format("%ld KB", mem_stat.dwAvailVirtual / 1024);
    m_strMemLoad.Format("%d\%",mem_stat.dwMemoryLoad);

    UpdateData(FALSE);
    }

    Any other suggestions ?

  4. #4
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Doh...what am I thinking!..sorry...should have tested it before blindly posting......

    Anyway I did an app to try this and used;

    Code:
    void CMFCMemDlg::OnRefresh() 
    {
    	MEMORYSTATUS mem_stat;
    
    	::GlobalMemoryStatus(&mem_stat);
    
    	m_TotalPhys.Format("%ld KB", mem_stat.dwTotalPhys / 1024);
    	m_AvailPhys.Format("%ld KB", mem_stat.dwAvailPhys / 1024);
    	m_AvailPageFile.Format("%ld KB", mem_stat.dwAvailPageFile / 1024);
    	m_TotalVirtual.Format("%ld KB", mem_stat.dwTotalVirtual / 1024);
    	m_AvailVirtual.Format("%ld KB", mem_stat.dwAvailVirtual / 1024);
    	m_MemLoad.Format("%d %%",mem_stat.dwMemoryLoad);	
    
    	UpdateData(FALSE);
    }
    Based on your code, and the memory load is in the 70s.....not 0 or 100!!.....I wonder it actually dispalying the right value for that??

    Anyway, here's the code I drew up....if you wish, compile it and see if the % value in my app is different to yours...
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    3

    Angry

    Ah bleh, seems to be my machine, your code gave me 100% too, yet on a friends machine gave 83%, cheers for the help though, appreciate it

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 04-12-2009, 06:49 PM
  2. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 10:05 AM
  3. Need Help Displaying A Pattern.
    By slickwilly440 in forum C++ Programming
    Replies: 4
    Last Post: 10-05-2005, 12:01 PM
  4. Displaying Arrays
    By mr_spanky202 in forum C Programming
    Replies: 3
    Last Post: 04-07-2003, 03:22 PM
  5. Need codes for displaying figures in descending mode.
    By rbaba in forum C++ Programming
    Replies: 0
    Last Post: 12-14-2001, 08:47 PM

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