Prostudiraj malo sledece pa vidi sta ti treba:
Code:
#include "stdafx.h"
#include "resource.h"
DWORD Memory_ThreadID = 0;
BOOL Memory_ThreadRunning = FALSE;
BOOL Memory_Abort = FALSE;
DWORD WINAPI Memory_ThreadProc(HWND hW);
//==========================================================================
// Dialog Procedure
//==========================================================================
BOOL CALLBACK Memory_DlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static MEMORYSTATUS MemStatus;
switch(uMsg) {
case WM_INITDIALOG: {
GlobalMemoryStatus(&MemStatus);
int Total = (int)(MemStatus.dwTotalPhys / 1048576);
Slider_Setup(GetDlgItem(hW, IDC_RAM), 1, Total, Total / 10, Total / 10);
Slider_SetPosition(GetDlgItem(hW, IDC_RAM), Total * 3 / 4);
CenterWindow(hW);
break;
}
case WM_COMMAND:
switch(wParam) {
case IDC_START:
if(Memory_ThreadRunning == FALSE)
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Memory_ThreadProc, hW, 0, &Memory_ThreadID);
else {
EnableWindow(GetDlgItem(hW, IDC_START), FALSE);
Memory_Abort = TRUE;
}
break;
case IDOK:
case IDCANCEL:
if(Memory_ThreadRunning == FALSE) EndDialog(hW, TRUE);
return TRUE;
}
break;
case WM_NOTIFY:
switch(LOWORD(wParam)) {
case IDC_RAM: {
char s[255];
sprintf(s, "%d MB", Slider_GetPosition(GetDlgItem(hW, IDC_RAM)));
SetDlgItemText(hW, IDC_RAM_DISPLAY, s);
break;
}
}
break;
}
return FALSE;
}
//==========================================================================
// Thread
//==========================================================================
DWORD WINAPI Memory_ThreadProc(HWND hW)
{
Memory_ThreadRunning = TRUE;
SetWindowText(GetDlgItem(hW, IDC_START), "Abort");
EnableWindow(GetDlgItem(hW, IDC_RAM), FALSE);
HWND hWC = GetDlgItem(hW, IDC_PROGRESS);
int Total = Slider_GetPosition(GetDlgItem(hW, IDC_RAM));
LPDWORD lpSegment = (LPDWORD)malloc(Total * sizeof(LPDWORD));
if(lpSegment) {
ProgressBar_SetRange(hWC, 0, Total);
ProgressBar_SetPos(hWC, 0)
int Current = 0;
while(Current < Total) {
lpSegment[Current] = (DWORD)malloc(1048576);
if(lpSegment[Current] == 0)
MessageBox(hW, "Error Allocating memory!", "Error", 0);
ProgressBar_SetPos(hWC, Current++);
Sleep(0);
if(Memory_Abort) break;
}
while(Current > 0) {
ProgressBar_SetPos(hWC, Current--);
free((LPVOID)lpSegment[Current]);
Sleep(0);
}
free((LPVOID)lpSegment);
ProgressBar_SetPos(hWC, 0);
Beep(0, 0);
} else {
MessageBox(hW, "Error Allocating memory!", "Error", 0);
}
Memory_ThreadRunning = FALSE;
Memory_Abort = FALSE;
EnableWindow(GetDlgItem(hW, IDC_START), TRUE);
EnableWindow(GetDlgItem(hW, IDC_RAM), TRUE);
SetWindowText(GetDlgItem(hW, IDC_START), "Start");
return 0;
}