To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
MSDN Subscribers: Download the VS 2010 Release Candidate
MSDN Subscribers: Download the VS 2010 Release Candidate
Sell Your Code and Make Money?
Creating your own Tetris game using VB.NET
Article :: Improving Software Economics, Part 4 of 7: Top 10 Principles of Iterative Software Management



Go Back   VBForums > Other Languages > C and C++

Reply Post New Thread
 
Thread Tools Search this Thread Display Modes
Old Dec 23rd, 2003, 12:47 PM   #1
Chrissie
Lively Member
 
Join Date: Aug 02
Location: The Netherlands
Posts: 96
Chrissie is an unknown quantity at this point (<10)
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) ;
     }
Chrissie is offline   Reply With Quote
Old Dec 23rd, 2003, 03:44 PM   #2
Kasracer
KrisSiegel.com
 
Kasracer's Avatar
 
Join Date: Jul 03
Location: USA, Maryland
Posts: 4,961
Kasracer is a glorious beacon of light (400+)Kasracer is a glorious beacon of light (400+)Kasracer is a glorious beacon of light (400+)Kasracer is a glorious beacon of light (400+)Kasracer is a glorious beacon of light (400+)Kasracer is a glorious beacon of light (400+)
You could always make it low priority
Kasracer is offline   Reply With Quote
Reply

Go Back   VBForums > Other Languages > C and C++


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 12:22 PM.




To view more projects, click here

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.