Sign in to follow this  

VC++: WM_Paint Timer problem

This topic is 3574 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a problem using timer triggered wm_paint. I create a main window and inside three other child-windows, one of these is DataPanel (hwdata), where i would like to display data which is changing over time (right now i have a rectangle which is expanding). I figured it would be good enough to refresh data every 100ms, so i set the timer to 100ms, which would send message WM_TIMER for this DataPanel window. I post the relevant parts of the code below (all the code is too big). The problem is that the code like now does not work - it does not refresh data (in this case, expand the rectangle) every 100ms, it works only if i hide and then reopen (alt-tab) my application. Thanks for any comment or solution, Boris int i = 0; HINSTANCE hInst; HWND hmwnd; HWND hwdata; LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch(msg) { // CREATE case WM_CREATE: // create menus AddMenus(hwnd); ... // create new child-window for data and timer to redraw RegisterDataPanel(); hwdata = CreateWindow(TEXT("DataPanel"), NULL, WS_CHILD | WS_VISIBLE, 2, 264, 345, 450, hwnd, (HMENU) 2, NULL, NULL); SetTimer(hwdata,IDT_TIMER1,100,(TIMERPROC) NULL); break; // DESTROY - post a quit message and return case WM_DESTROY: KillTimer(hwdata, IDT_TIMER1); PostQuitMessage(0); break; } return DefWindowProc(hwnd, msg, wParam, lParam); } void RegisterDataPanel(void) { HBRUSH hbrush = CreateSolidBrush(RGB(236, 233, 216)); WNDCLASS rwc = {0}; rwc.style = CS_HREDRAW | CS_VREDRAW; rwc.lpszClassName = TEXT( "DataPanel" ); rwc.hbrBackground = hbrush; rwc.lpfnWndProc = DataProc ; rwc.hCursor = LoadCursor(0,IDC_ARROW); RegisterClass(&rwc); } LRESULT CALLBACK DataProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) { HDC hdc; PAINTSTRUCT ps; DWORD color; switch(msg) { case WM_CREATE: { CreateWindow(TEXT("button"), TEXT("Real Object"), WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 0, 0, 345, 110, hwnd, (HMENU) 0, 0, NULL); } case WM_TIMER: case WM_PAINT: { hdc = BeginPaint(hwnd, &ps); color = GetSysColor(COLOR_BTNFACE); SetBkColor(hdc, color); Rectangle(hdc, 50, 50, i++, 100); EndPaint(hwnd, &ps); break; } } return DefWindowProc(hwnd, msg, wParam, lParam); }

Share this post


Link to post
Share on other sites
Your WM_TIMER handler should update the rectangle size, and call InvalidateRect(hWnd, NULL);, which tells Windows that you want it to refresh the window and send a new WM_PAINT.

Share this post


Link to post
Share on other sites

This topic is 3574 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this