473,396 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

wm_paint : 100% cpu

12
Hi

When I listen WM_PAINT event, the cpu is max.
Expand|Select|Wrap|Line Numbers
  1. LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  2. {
  3. int x, y;  HDC hdc; HPEN hOldPen, hPen; HBRUSH hOldBrush, hBrush;
  4. y = lParam / 65536;
  5. x = lParam % 65536;
  6.     switch (message)
  7.     {  // SetTextColor(hdc,RGB(0,0,255));
  8.              //SetBkColor(hdc, RGB(236,232,245));
  9.            case WM_DESTROY:
  10.            PostQuitMessage(0);
  11.            break;
  12.            case WM_PAINT:
  13.               hdc=GetDC(hwnd);
  14.               hPen= CreatePen(PS_SOLID, 1, RGB(215, 0, 0));
  15.               hOldPen=(HPEN)SelectObject(hdc,hPen);
  16.  
  17.               //drawing
  18.  
  19.               SelectObject(hdc,hOldPen);
  20.               DeleteObject(hPen);
  21.               SelectObject(hdc,hOldBrush);
  22.               DeleteObject(hBrush);
  23.               ReleaseDC(hwnd,hdc);
  24.  
  25.            break;
  26.            case WM_MOUSEMOVE:
  27.             //.....
  28.            break;
  29.            case WM_LBUTTONDOWN:
  30.               //.... 
  31.            break;
  32.            default:
  33.            return DefWindowProc(hwnd, message, wParam, lParam);
  34.     }
  35.   }
  36.  
So, I think the wm_paint message every time run.(if need not redraw the window at the time, run wm_paint message, too)
What can I do?
thanks!
Jul 16 '07 #1
2 2299
Banfa
9,065 Expert Mod 8TB
You should not be calling GetDC(...) and ReleaseDC(...) from the WM_PAINT message.

The are special functions for this, instead you should use BeginPaint(...) and EndPaint(...).

See the example here.

I am afraid it is not clear to me what you mean by "when I listen WM_PAINT event".
Jul 16 '07 #2
kiberg
12
I am afraid it is not clear to me what you mean by "when I listen WM_PAINT event".
Sorry, i dont speak english only little...
But your solution is good.
Thank you very much!
Jul 16 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: | last post by:
newbie code -------------------------- #include <iostream> using namespace std; #include <cstring> class aaa {
4
by: Kevin Dombroski | last post by:
Howdy - I would like my application to be able to read data from another application. Specifically, I would like my to get the text from the "client area" of another application's window whenever...
2
by: black(flashing vampire) | last post by:
hi all~ i just built a cute window with the help of a tutorial, but met some problem when try to repaint the window, my callback function is as below: LRESULT CALLBACK WndProc(HWND hwnd, UINT...
18
by: P.N. | last post by:
Hi! when i define array (any type) then compilator say that array is to large! ?? i need at least 10.000 instead 100. This is for numeric methods in "C" any sugestion? thx Greetings P
17
by: Mike | last post by:
I'm trying to create a page: Three sections (left, topright and bottomright), each with a heading and scrolling (overflow) content. The size of these sections should be based upon the size of the...
0
by: --== Alain ==-- | last post by:
Hi, i was thinkging to override WNDPROC of my ListView control, in order to control how the headers and items will be redrawn. My purpose is to : - keep the header format (horizontal and...
6
by: =?Utf-8?B?VGhvbWFzWg==?= | last post by:
Hi, Is it possible to read a file in reverse and only get the last 100 bytes in the file without reading the whole file from the begining? I have to get info from files that are in the last 100...
2
by: =?Utf-8?B?RXJpYw==?= | last post by:
Hello All, I am currently working on an issue that has a custom control that mimics a combobox that when it has focus it continues to generate endless WM_PAINT Messages. The control in itself...
3
by: ayan4u | last post by:
hi, I am using InvalidataRect(hWnd, &rect, TRUE) to clear my client rect....does this mean that a WM_PAINT message will the invoked automatically by it.... neways fot the time being lets assume...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.