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.
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.
Clear a listbox:
Code:SendDlgItemMessage(hDlg, IDC_PLAYERLIST, LB_RESETCONTENT, 0, 0);
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
Is there an easier way to do this??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; }
Last edited by silentkarma; 09-14-2006 at 12:13 PM.
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.
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..
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.how would my program know people left?