Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2005.12.04;
Скачать: CL | DM;

Вниз

Как обновить изображение нарисованное на окне?   Найти похожие ветки 

 
kDenis   (2005-09-30 20:47) [0]

Великие мастера! У меня тут большой трабл...
Рассказываю все по порядку...

Вобщем, создаю окно (WS_POPUPWINDOW) функцией CreateWindowEx, создаю кисть,

закрашиваю весь экран в черный цвет (функцией FillRect), запускаю таймер

функцией SetTimer. Через указанные промежутки времени (60мс), по таймеру

прямоугольник меняет цвет. А точнее, цвет остается тот-же, а меняется

яркость. Ну, короче, цвет меняется в диапазоне от $000000h до $00FF00h с

шагом $100h (тоесть через каждые 60мс код цвета увеличивается или уменьшается

на $100h).

А проблема в том, что все эти изменения на экране не отображаются! Вот, если

нажать Alt+Tab и перейти на другую прогу, а потом вернутся назат к этой, то

экран обновляется. Я пробовал его обновить функцией UpdateWindow (вызывая ее

каждые 60мс), пробовал посылать окну сообщение WM_PAINT. Ничего не помогает.

Перед началом рисования я вызываю  BeginPaint, а по завершении рисования -

EndPaint. Тоесть, они каждые 60мс вызываются.

ПОМОГИТЕ МНЕ ОБНОВИТЬ ЭТО ПАКОСНОЕ ОКНО!!!
Всем заранее спасибо за помощь.


 
kDenis   (2005-09-30 23:29) [1]

Че, никто не поможет? Плиз! Подскажите что-то!


 
kDenis   (2005-10-01 11:41) [2]

Всем спасибо за сотрудничество. :)
Я уже разобрался...
После Вызова EndPaint нужно вызывать InvalidateRect.


 
Eraser ©   (2005-10-01 12:08) [3]


> kDenis   (01.10.05 11:41) [2]

Да вообще неплохо бы всё прорисовку осуществлять в OnPaint


 
kDenis   (2005-10-01 23:00) [4]

Я пишу без VCL. То, что происходит OnPaint я ловлю, когда окно получает сообщение WM_PAINT (Это в принципе одно и то-же). А оно получает это сообщение в следующих случаях:
1. Была активной другая программа, и пользователь переключился на мою.
2. Пользователь изменил размер окна.
3. Была вызвана функция InvalidateRect, которую нужно вызывать после прорисовки.
Кстати, если перерисовывать экран при получении WM_PAINT, то прога скорее всего повиснет. Потому что после перерисовки автоматически повторно посылается WM_PAINT, выходит бесконечный цыкл...


 
Eraser ©   (2005-10-01 23:37) [5]


> kDenis   (01.10.05 23:00) [4]

Как понимать функция InvalidateRect, которую нужно вызывать после прорисовки, эту функцию как раз таки нужно вызывать, чтобы перерисовать нужный участок.

Кстати, если перерисовывать экран при получении WM_PAINT, то прога скорее всего повиснет.

An application sends the WM_PAINT message when Windows or another application makes a request to paint a portion of an application"s window.


 
Sashka ©   (2005-10-01 23:39) [6]

InvalidateRect надо бы вызывать не после отрисовки, а по таймеру... Отрисовку по таймеру делать не следует, её действительно лучше запихать в обработчик WM_PAINT и больше никуда.


 
kDenis   (2005-10-02 10:25) [7]

>InvalidateRect надо бы вызывать не после отрисовки, а по таймеру... >Отрисовку по таймеру делать не следует, её действительно лучше запихать >в обработчик WM_PAINT и больше никуда.

Ладно, попробую. Спасибо.


 
acc15 ©   (2005-10-03 14:10) [8]

Рисовать можно и по таймеру. Microsoft по этому поводу даже пример написал... Если в сях никак, то скажи, переведу :))

> Drawing at Timed Intervals
> You can draw at timed intervals by creating a timer with
> the SetTimer function. By using a timer to send WM_TIMER
> messages to the window procedure at regular intervals, an
> application can carry out simple animation in the client
> area while other applications continue running.
>
> In the following example, the application bounces a star
> from side to side in the client area. Each time the window
> procedure receives a WM_TIMER message, the procedure erases
> the star at the current position, calculates a new position,
>  and draws the star within the new position. The procedure
> starts the timer by calling SetTimer while processing the
> WM_CREATE message.
>
> RECT rcCurrent = {0,0,20,20};
> POINT aptStar[6] = {10,1, 1,19, 19,6, 1,6, 19,19, 10,1};
>  
> int X = 2, Y = -1, idTimer = -1;
> BOOL fVisible = FALSE;
> HDC hdc;
>  
> LRESULT APIENTRY WndProc(HWND hwnd, UINT message, WPARAM
> wParam, LPARAM lParam)
> {
>     PAINTSTRUCT ps;
>     RECT rc;
>  
>     switch (message)
>     {
>         case WM_CREATE:
>  
>             // Calculate the starting point.
>  
>             GetClientRect(hwnd, &rc);
>             OffsetRect(&rcCurrent, rc.right / 2, rc.bottom
> / 2);
>  
>             // Initialize the private DC.
>  
>             hdc = GetDC(hwnd);
>             SetViewportOrgEx(hdc, rcCurrent.left,
>                 rcCurrent.top, NULL);
>             SetROP2(hdc, R2_NOT);
>  
>             // Start the timer.
>  
>             SetTimer(hwnd, idTimer = 1, 10, NULL);
>             return 0L;
>  
>         case WM_DESTROY:
>             KillTimer(hwnd, 1);
>             PostQuitMessage(0);
>             return 0L;
>  
>         case WM_SIZE:
>             switch (wParam)
>             {
>                 case SIZE_MINIMIZED:
>  
>                     / Stop the timer if the window is minimized.
>  
>  
>                     KillTimer(hwnd, 1);
>                     idTimer = -1;
>                     break;
>  
>                 case SIZE_RESTORED:
>  
>                     // Move the star back into the client
> area
>                     // if necessary.
>  
>                     if (rcCurrent.right > (int) LOWORD(lParam))
>
>                     {
>                         rcCurrent.left =
>                             (rcCurrent.right =
>                                 (int) LOWORD(lParam)) -
> 20;
>                     }
>                     if (rcCurrent.bottom > (int) HIWORD(lParam))
>
>                     {
>                         rcCurrent.top =
>                             (rcCurrent.bottom =
>                                 (int) HIWORD(lParam)) -
> 20;
>                     }
>  
>                     // Fall through to the next case.
>  
>                 case SIZE_MAXIMIZED:
>  
>                     // Start the timer if it had been stopped.
>  
>  
>                     if (idTimer == -1)
>                         SetTimer(hwnd, idTimer = 1, 10,
> NULL);
>                     break;
>             }
>             return 0L;
>  
>         case WM_TIMER:
>  
>             // Hide the star if it is visible.
>  
>             if (fVisible)
>                 Polyline(hdc, aptStar, 6);
>  
>             // Bounce the star off a side if necessary.
>
>  
>             GetClientRect(hwnd, &rc);
>             if (rcCurrent.left + X < rc.left ||
>                 rcCurrent.right + X > rc.right)
>                 X = -X;
>             if (rcCurrent.top + Y < rc.top ||
>                 rcCurrent.bottom + Y > rc.bottom)
>                 Y = -Y;
>  
>             // Show the star in its new position.
>  
>             OffsetRect(&rcCurrent, X, Y);
>             SetViewportOrgEx(hdc, rcCurrent.left,
>                 rcCurrent.top, NULL);
>             fVisible = Polyline(hdc, aptStar, 6);
>  
>             return 0L;
>  
>         case WM_ERASEBKGND:
>  
>             // Erase the star.
>  
>             fVisible = FALSE;
>             return DefWindowProc(hwnd, message, wParam,
> lParam);
>  
>         case WM_PAINT:
>  
>             // Show the star if it is not visible. Use BeginPaint
>
>             // to clear the update region.
>  
>             BeginPaint(hwnd, &ps);
>             if (!fVisible)
>                 fVisible = Polyline(hdc, aptStar, 6);
>             EndPaint(hwnd, &ps);
>             return 0L;
>     }
>     return DefWindowProc(hwnd, message, wParam, lParam);
>  
> }
> This application uses a private device context to minimize
> the time required to prepare the device context for drawing.
>  The window procedure retrieves and initializes the private
> device context when processing the WM_CREATE message, setting
> the binary raster operation mode to allow the star to be
> erased and drawn using the same call to the Polyline function.
>  The window procedure also sets the viewport origin to allow
> the star to be drawn using the same set of points regardless
> of the star"s position in the client area.
>
> The application uses the WM_PAINT message to draw the star
> whenever the window must be updated. The window procedure
> draws the star only if it is not visible; that is, only
> if it has been erased by the WM_ERASEBKGND message. The
> window procedure intercepts the WM_ERASEBKGND message to
> set the fVisible variable, but passes the message to DefWindowProc
> so that the system can draw the window background.
>
> The application uses the WM_SIZE message to stop the timer
> when the window is minimized and to restart the timer when
> the minimized window is restored. The window procedure also
> uses the message to update the current position of the star
> if the size of the window has been reduced so that the star
> is no longer in the client area. The application keeps track
> of the star"s current position by using the structure specified
> by rcCurrent, which defines the bounding rectangle for the
> star. Keeping all corners of the rectangle in the client
> area keeps the star in the area. The window procedure initially
> centers the star in the client area when processing the
> WM_CREATE message.



Страницы: 1 вся ветка

Текущий архив: 2005.12.04;
Скачать: CL | DM;

Наверх




Память: 0.51 MB
Время: 0.043 c
6-1125327416
VadimX
2005-08-29 18:56
2005.12.04
WinSock SEND,RECV слепляются команды


6-1125046155
Cyberdemon
2005-08-26 12:49
2005.12.04
Нужно идея по рганизации Client/Server приложения


2-1131996087
Тоня
2005-11-14 22:21
2005.12.04
Решение СЛАУ


4-1128052314
Roughneck
2005-09-30 07:51
2005.12.04
Как получить полное имя запущенного файла если известен только PI


3-1129525632
Кудрявцев Павел
2005-10-17 09:07
2005.12.04
Глюки IBEvents