Thread: Hung up on GetWindowText

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    161

    Hung up on GetWindowText

    I can't figure this one out. I get all the other module information as expected, but I can't get GetWindowText to give me the window title of each process. The code below just spits out "Notification Area" repeatedly. I tried using aProcesses[i] instead and got a bunch of the wrong window titles. I don't get it. I'm also curious how to determine the user running each process. I specifically want to know which ones are SYSTEM processes in order to exclude them from the list.

    Code:
    int ListProcesses(HWND hProcessList) {
        HANDLE hProcess;
        DWORD aProcesses[1024], cbNeeded, cProcesses;
        unsigned int i;
        char szProcessName[500];
        char szProcessPath[500];
        char szProcessID[20];
        char szProcessSize[20];
        char szProcessTitle[1024];
        PROCESS_MEMORY_COUNTERS szProcessMemory;
        SendMessage(hProcessList, LVM_DELETEALLITEMS, 0, 0);
        if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
            return 1;
    
        cProcesses = cbNeeded / 4;
    
        for ( i = 0; i < cProcesses; i++ ) {
            if( aProcesses[i] != 0 ) hProcess = OpenProcess( PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, FALSE, aProcesses[i] );
            if (NULL != hProcess )
            {
                GetModuleBaseName( hProcess, NULL, szProcessName, 500 );
                GetModuleFileNameEx( hProcess, NULL, szProcessPath, 500 );
                memset(&szProcessMemory,0,sizeof(PROCESS_MEMORY_COUNTERS));
                szProcessMemory.cb = sizeof(PROCESS_MEMORY_COUNTERS);
                GetProcessMemoryInfo(hProcess, &szProcessMemory, sizeof(PROCESS_MEMORY_COUNTERS));
                sprintf(szProcessSize, "&#37;.2f", (float)szProcessMemory.WorkingSetSize / 1024 / 1024);
                szProcessTitle[0] = '\0';
                GetWindowText(hProcess, szProcessTitle, sizeof(szProcessTitle));
                sprintf(szProcessID, "%u", aProcesses[i]);
                ListViewAddRow(hProcessList, 5, szProcessName, szProcessTitle, szProcessID, szProcessSize, szProcessPath);
            }
            CloseHandle( hProcess );
        }
    	return 0;
    }
    Last edited by Viper187; 08-31-2008 at 01:16 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GetWindowText() not working with Vista???
    By Abda92 in forum Windows Programming
    Replies: 10
    Last Post: 04-07-2008, 01:29 PM
  2. GetwindowText problem
    By spanker in forum Windows Programming
    Replies: 4
    Last Post: 03-27-2008, 10:25 AM
  3. GetWindowText doesn't return the text
    By Rune Hunter in forum Windows Programming
    Replies: 16
    Last Post: 09-23-2005, 04:49 PM
  4. GetWindowText -> string?
    By XSquared in forum Windows Programming
    Replies: 3
    Last Post: 08-27-2003, 03:58 PM
  5. Using GetWindowText
    By ColdFire in forum Windows Programming
    Replies: 9
    Last Post: 05-26-2002, 10:24 PM