Thread: Clear

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

    Clear

    What is the function to clear data out of a listbox or other object? [win32 api] I want a button to clear a listbox. Thanks.

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Clear a listbox:

    Code:
    SendDlgItemMessage(hDlg, IDC_PLAYERLIST,  LB_RESETCONTENT, 0, 0);

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    55
    Hey bob, haha, seems like you've been following through with my project. I got the clear to work before I read your reply :P [I've been learning alot], so now how do I get the data from memory again in the same button? This way it will refresh. Basically I want to readprocessmemory again with the button after it clears, but I cannot find an easy way to do it.

    Edit - I GOT IT! ON MY OWN! I read through some Win32 API tuts.. =P

    Code:
    //main.cpp
    #include <windows.h>    
    #include <commctrl.h>
    #include <stdio.h>
    #include <string.h>
    #include "main.h"
    #include <winuser.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,(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;
    			}
    			if (LOWORD(wParam) == IDC_REFRESH) {
    				SendDlgItemMessage(hDlg, IDC_PLAYERLIST,  LB_RESETCONTENT, 0, 0);
    					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;
    			}
    			break;
    	}
    	return FALSE;
    }
    int WINAPI WinMain(HINSTANCE hInstance,
           HINSTANCE hPrevInstance,
           LPSTR lpszArgs,
           int nWinMode)
    {
        InitCommonControls();
        DialogBox(hInstance ,MAKEINTRESOURCE(IDD_LISTBOX) , 0, DoListboxProcess);
        return 0;
    }
    Is there an easier way to do this??
    Last edited by silentkarma; 09-14-2006 at 12:13 PM.

  4. #4
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Of course there is! Ever thought of putting those 2 identical "memoryreaders" under one message?
    Code:
    //main.cpp
    #include <windows.h>    
    #include <commctrl.h>
    #include <stdio.h>
    #include <string.h>
    #include "main.h"
    #include <winuser.h>
    #define WM_READMEMORY 12000
    
    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 WN_INITDIALOG:
    			SendMessage(hDlg,WM_READMEMORY,0,0);
    			/*SetTimer(hDlg,100,1500,NULL); */ /*You can un-comment this line, 
    				if you want it to autorefresh every 1.5 seconds */
    			break;
    		case WM_TIMER:
    			SendMessage(hDlg,WM_READMEMORY,0,0);
    			break;
    		case WM_READMEMORY:
    			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;
    			}
    			if (LOWORD(wParam) == IDC_REFRESH) {
    				SendMessage(hDlg,WM_READMEMORY,0,0);
    			}		
    			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;
    }
    Last edited by maxorator; 09-14-2006 at 12:32 PM.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    55
    well, it gave me about 15 errors lol. my way works just as good =P

    Okay so when I run a server on Halo, as players enter, they are stored statically in memory. Now when players leave, their data is still in memory, it doesnt clear when they leave. Why is this and how can I fix it so when I refresh, the players that left wont be in memory or in my listbox. Kinda sucks when I have players not in the server, but are in my listbox. I was thinking I could write their names to 00's but how would my program know people left? Hmm..

  6. #6
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    how would my program know people left?
    I believe you indicated that 200 bytes are assigned to each player, 22 of which are used for the name of the player. That leaves 178 unexplained bytes. I would suggest you use some type of memory monitor to watch the hex values of these unexplained bytes as users come and go and watch for a pattern.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. About clear(). Please help!
    By Antigloss in forum C++ Programming
    Replies: 12
    Last Post: 07-14-2005, 04:02 AM
  2. How to Clear in Visual C++
    By MyDestiny in forum Windows Programming
    Replies: 4
    Last Post: 03-16-2005, 10:40 PM
  3. How to Clear in Visual C++ 6.0
    By MyDestiny in forum Windows Programming
    Replies: 1
    Last Post: 03-16-2005, 11:57 AM
  4. Yet another clear screen thread :D
    By kermit in forum Linux Programming
    Replies: 2
    Last Post: 11-20-2003, 05:14 AM
  5. Using a button to clear a list box!
    By Unregistered in forum C++ Programming
    Replies: 13
    Last Post: 08-23-2002, 07:44 PM