Timer/Loop on Listbox

This is a discussion on Timer/Loop on Listbox within the Windows Programming forums, part of the Platform Specific Boards category; I need to make a listbox refresh, but cannot get it to work. IDK what's wrong and IDK if I ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    55

    Timer/Loop on Listbox

    I need to make a listbox refresh, but cannot get it to work. IDK what's wrong and IDK if I should be using a timer or loop to refresh it. Also, when I read from memory into the listbox, I am currently using LBS_SORT style, but I want it to read into the listbox in order as it is reading it, not alphabetically. Any suggestions? Here's my coding for the listbox:

    Code:
    //main.cpp
    #include <windows.h>    
    #include <commctrl.h>
    #include <stdio.h>
    #include <string.h>
    #include "main.h"
    
    
    BOOL CALLBACK DoListboxProcess(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    {
        HWND hwnd;           
        DWORD pid;
        HANDLE process;
    
        int x, y, z;
        DWORD iAddress = 0x4BD7AFC6;
        DWORD dummy = 0;
        unsigned char value[512];
        char outvalue[32];
    
        switch (message) {
            case WM_INITDIALOG:
               
    			hwnd=FindWindow(NULL, "Halo");
                SendDlgItemMessage(hDlg, IDC_PLAYERLIST,  LB_RESETCONTENT, 0, 0);
                GetWindowThreadProcessId(hwnd, &pid);
                process = OpenProcess(PROCESS_VM_READ
                    |PROCESS_VM_WRITE|     
                    PROCESS_VM_OPERATION    
                    |PROCESS_QUERY_INFORMATION, 
                    FALSE, pid);
                for(x = 0; x < 16;x++)
                {
                    ReadProcessMemory(process    // handle to the process
                        ,(void*) iAddress,     // address to start reading
                        (void*) &value,        // address of buffer to place read data
                        sizeof(value)          // number of bytes to read
                        ,&dummy);              // number of bytes read
                    z = 0;
                    for(y = 10; y < 32; y+=2)
                    {
                        outvalue[z++] = value[y];
                    }
                    outvalue[11] = '\0';
    				
    				
                    SendDlgItemMessage(hDlg, IDC_PLAYERLIST, LB_ADDSTRING, 0, (LPARAM)outvalue);
                    iAddress += sizeof value;
    			}        
                return (TRUE);
            case WM_COMMAND:
    
    
                if (LOWORD(wParam) == IDOK ||LOWORD(wParam)== IDCANCEL  ) {
                    EndDialog(hDlg, TRUE);
                    return (TRUE);
                }
                break;
        }
        return FALSE;
    }
    int WINAPI WinMain(HINSTANCE hInstance,
           HINSTANCE hPrevInstance,
           LPSTR lpszArgs,
           int nWinMode)
    {
        InitCommonControls();
        DialogBox(hInstance ,MAKEINTRESOURCE(IDD_LISTBOX) , 0, DoListboxProcess);
        return 0;
    }
    Code:
    //main.h
    #pragma comment(lib,"USER32.LIB")
    #pragma comment(lib,"GDI32.LIB")
    #pragma comment(lib,"COMCTL32.LIB")
    #define IDD_LISTBOX 100
    #define IDC_PLAYERLIST 101
    Code:
    //util.rc
    /////////////////////////////////////////////////////////////////////////////
    //
    // Dialog
    //
    
    IDD_LISTBOX DIALOG DISCARDABLE  0, 0, 185, 171
    STYLE DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION "Just a test list box"
    FONT 8, "MS Shell Dlg"
    BEGIN
        DEFPUSHBUTTON   "OK",IDOK,89,52,50,14
        PUSHBUTTON      "Cancel",IDCANCEL,89,81,50,14
        LISTBOX         IDC_PLAYERLIST,8,6,72,157,LBS_SORT | 
                        LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
    END
    Last edited by silentkarma; 09-13-2006 at 01:32 PM.

  2. #2
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Maybe just remove LBS_SORT style?
    Rename your WM_INITDIALOG to WM_TIMER, then make a new empty WM_INITDIALOG and use SetTimer() inside it. This should do it:
    Code:
    BOOL CALLBACK DoListboxProcess(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam){
    	HWND hwnd;		   
    	DWORD pid;
    	HANDLE process;
    
    	int x, y, z;
    	DWORD iAddress = 0x4BD7AFC6;
    	DWORD dummy = 0;
    	unsigned char value[512];
    	char outvalue[32];
    
    	switch (message) {
    		case WM_INITDIALOG:
    			SetTimer(hDlg,500,1000,WM_TIMER);
    			break;
    		case WM_TIMER:
    			hwnd=FindWindow(NULL, "Halo");
    			SendDlgItemMessage(hDlg, IDC_PLAYERLIST,  LB_RESETCONTENT, 0, 0);
    			GetWindowThreadProcessId(hwnd, &pid);
    			process = OpenProcess(PROCESS_VM_READ|PROCESS_VM_WRITE|	 
    				PROCESS_VM_OPERATION|PROCESS_QUERY_INFORMATION,FALSE, pid);
    			for(x = 0; x < 16;x++){
    				ReadProcessMemory(process,(void*)iAddress,(void*) &value,sizeof(value),&dummy);
    				z = 0;
    				for(y = 10; y < 32; y+=2){
    					outvalue[z++] = value[y];
    				}
    				outvalue[11] = '\0';
    				SendDlgItemMessage(hDlg, IDC_PLAYERLIST, LB_ADDSTRING, 0, (LPARAM)outvalue);
    				iAddress += sizeof value;
    			}		
    			return true;
    		case WM_COMMAND:
    			if (LOWORD(wParam) == IDOK ||LOWORD(wParam)== IDCANCEL  ) {
    				EndDialog(hDlg, TRUE);
    				return true;
    			}
    			break;
    		case WM_DESTROY:
    			KillTimer(hDlg,500);
    			break;
    	}
    	return FALSE;
    }

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    55
    error C2664: 'SetTimer' : cannot convert parameter 4 from 'const int' to 'void (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,unsigned long)'
    Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast

    Hmm...don't really understand the error.

    http://msdn2.microsoft.com/en-us/library/s5b150wd.aspx
    Last edited by silentkarma; 09-13-2006 at 04:18 PM.

  4. #4
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Try
    Code:
    SetTimer(hDlg 500, 1000, (TIMERPROC)NULL);
    Also, when I read from memory into the listbox, I am currently using LBS_SORT style, but I want it to read into the listbox in order as it is reading it, not alphabetically. Any suggestions?
    Remove the LBS_SORT style from the LISTBOX. For example:

    LISTBOX IDC_PLAYERLIST,8,6,72,157, LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
    Last edited by BobS0327; 09-13-2006 at 07:51 PM.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    55
    error C2143: syntax error : missing ')' before 'constant'
    error C2660: 'SetTimer' : function does not take 1 parameters
    error C2059: syntax error : ')'

    Well, the errors seem much more simpler and less complicated looking :P

  6. #6
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Well, the errors seem much more simpler and less complicated looking :P
    You're missing a right round bracket somewhere... ')'

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    55
    Actually no...I looked through my coding, everything else is the same as before. All the errors are on the SetTimer function line....

    Something is wrong with that.

  8. #8
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Oops, it's a typo on my part

    Code:
    SetTimer(hDlg 500, 1000, (TIMERPROC)NULL);
    should be
    Code:
    SetTimer(hDlg, 500, 1000, (TIMERPROC)NULL);

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    55
    Perfect and perfect! O___o Thanks!

    Edit:

    Okay, well it works perfectly now, but now I've come to a problem. My program will eventually be 'select a player from the list, then it will open up options to edit that player'. Now, since the timer makes the listbox refresh automatically, once I select the player, after my alloted time, it deselects what I have selected. Not sure how all this will go down since I am in the early stages of my project, but I think am better off using a Refresh Button that will refresh, when I need to refresh it.

    I've been trying to research this on my own, but with no luck...

    I tried MSDN and google, but nothing good about refreshing...

    Any ideas?
    Last edited by silentkarma; 09-14-2006 at 12:20 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Deal or No Deal listbox prob
    By kryptkat in forum Windows Programming
    Replies: 5
    Last Post: 03-30-2009, 07:53 PM
  2. ListBox Extra Data Storage
    By Welder in forum Windows Programming
    Replies: 1
    Last Post: 11-01-2007, 02:46 PM
  3. How to cast a ListBox item to an int for a switch statment?
    By Swaine777 in forum C++ Programming
    Replies: 8
    Last Post: 09-26-2004, 09:52 PM
  4. Listbox stealing focus
    By Calthun in forum Windows Programming
    Replies: 3
    Last Post: 09-12-2004, 05:36 PM
  5. Getting FULL filename from listbox
    By Garfield in forum Windows Programming
    Replies: 8
    Last Post: 01-27-2002, 08:28 AM

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