|
|
#1 |
|
Lively Member
Join Date: Aug 02
Location: The Netherlands
Posts: 96
![]() |
Multitasking: restricting CPU usage
I'm currently working on a Multitasking Demo which comes from a Petzold book.
The app takes 99% of CPU usage, which makes it almost impossible to close it down, even causing system instability. Is it possible to restrict CPU usage? Code:
LRESULT APIENTRY WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
static char *szChildClass[] = { "Child1", "Child2",
"Child3", "Child4" } ;
static HWND hwndChild[4] ;
static WNDPROC ChildProc[] = { WndProc1, WndProc2,
WndProc3, WndProc4 } ;
HINSTANCE hInstance ;
int i, cxClient, cyClient ;
WNDCLASSEX wndclass ;
switch (iMsg)
{
case WM_CREATE :
hInstance = (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE) ;
wndclass.cbSize = sizeof (wndclass) ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = NULL ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.hIconSm = NULL ;
for (i = 0 ; i < 4 ; i++)
{
wndclass.lpfnWndProc = ChildProc[i] ;
wndclass.lpszClassName = szChildClass[i] ;
RegisterClassEx (&wndclass) ;
hwndChild[i] = CreateWindow (szChildClass[i], NULL,
WS_CHILDWINDOW | WS_BORDER | WS_VISIBLE,
0, 0, 0, 0, hwnd, (HMENU) i, hInstance, NULL) ;
}
return 0 ;
case WM_SIZE :
cxClient = LOWORD (lParam) ;
cyClient = HIWORD (lParam) ;
for (i = 0 ; i < 4 ; i++)
MoveWindow (hwndChild[i], (i % 2) * cxClient / 2,
(i > 1) * cyClient / 2,
cxClient / 2, cyClient / 2, TRUE) ;
return 0 ;
case WM_CHAR :
if (wParam == '\x1B')
DestroyWindow (hwnd) ;
return 0 ;
case WM_DESTROY :
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
}
|
|
|
|
|
|
#2 |
|
KrisSiegel.com
Join Date: Jul 03
Location: USA, Maryland
Posts: 4,961
![]() ![]() ![]() ![]() ![]() ![]() |
You could always make it low priority
|
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|