Thread: SetTimer().. WM_TIMER window flickers

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Are these rectangles windows? If not, it's best to make them labels.
    Then just invalidate those labels and it will redraw.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    You can also actually try to draw what you need on the invisible dc - and then just copy it - when whole buffer is ready - onto the screen dc
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #18
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    You might try overriding WM_ERASEBKGRND and just return non zero.

  4. #19
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by Elysia View Post
    Are these rectangles windows? If not, it's best to make them labels.
    Then just invalidate those labels and it will redraw.
    No they not, they are drawn on one window... How do you make them labels?

  5. #20
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by vart View Post
    You can also actually try to draw what you need on the invisible dc - and then just copy it - when whole buffer is ready - onto the screen dc
    Just read through some tutorial... Is this Double buffering you talking about? If so, i'm busy adding some code... Not sure how it works but will update you on my progress...

    The idea is...

    1. Create a DC on buffer
    2. Add/draw rectangles on Buffer DC
    3. Copy back to DC to client area using BitBlt()...

  6. #21
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by csonx_p View Post
    No they not, they are drawn on one window... How do you make them labels?
    You would just add labels to your window. They're called "static," I think. Create them just like any other windows. Labels are made to contain text and appears invisible to the dialog.

    So you could make labels and seeing as they are windows, draw upon them and invalidate them.

    Quote Originally Posted by csonx_p View Post
    Just read through some tutorial... Is this Double buffering you talking about? If so, i'm busy adding some code... Not sure how it works but will update you on my progress...

    The idea is...

    1. Create a DC on buffer
    2. Add/draw rectangles on Buffer DC
    3. Copy back to DC to client area using BitBlt()...
    Yep, it's double buffer and the general idea you have is correct.
    Basically, it's to avoid drawing anything on the window until you've finished drawing at which time you copy the data over to the window.
    It's similar to games which also tend to use some double buffering technique.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #22
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by Elysia View Post
    You would just add labels to your window. They're called "static," I think. Create them just like any other windows. Labels are made to contain text and appears invisible to the dialog.

    So you could make labels and seeing as they are windows, draw upon them and invalidate them.
    Will check this later.. now am busy wif double buffering....

    Yep, it's double buffer and the general idea you have is correct.
    Basically, it's to avoid drawing anything on the window until you've finished drawing at which time you copy the data over to the window.
    It's similar to games which also tend to use some double buffering technique.
    Q. Is it essential to first delete the DC on buffer only after you copied it to client area DC? Thing is i have about 5 rectangles. Currently i draw each on DC created by BegingPaint(), then delete after drawing it, draw next Rec, then delete until i finish drawing all... The example i have draws object(s) on Memory DC on a buffer, then copies the buffer DC to Client DC, then only after copying deletes the Buffer DC.... To clear my question, is it safe to draw all five rectangles without deleting each separately on Buffer DC, then delete all after copying back to Client DC... (Hope this question is clear)

  8. #23
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes. The easiest way is to create a memory DC that mirrors your dialog. Then draw everything on the memory DC where you would draw on your dialog.
    When done drawing everything, you can request BeginPaint, get your DC, blit over, End Paint and release your memory DC.
    Note that dynamically creating a memory DC for each paint may have a performance impact, so you might want to create a global memory DC and overwrite the information on it and blit it.

    I'm not an expert in the area, but this is how it works, I think.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #24
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by Elysia View Post
    Yes. The easiest way is to create a memory DC that mirrors your dialog. Then draw everything on the memory DC where you would draw on your dialog.
    When done drawing everything, you can request BeginPaint, get your DC, blit over, End Paint and release your memory DC.
    Note that dynamically creating a memory DC for each paint may have a performance impact, so you might want to create a global memory DC and overwrite the information on it and blit it.

    I'm not an expert in the area, but this is how it works, I think.
    Hang on, think i got myself mixed up here... Noticed i have two things to delete... First Brushes & Pens, Then the DC (rather releasing MemDC)... My concern is deleting brushes and pens for each rectangle before BitBlt'ing to Window DC!.... would that have an effect? Shoudn' be a prob deleting/releasing DC on buffer after copying, but need to delete brushes before coping...

  10. #25
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Init:
    Create memory DC.
    Select proper pens/brushes on memory DC.

    Paint:
    Draw rectangle 1 on memory DC.
    Draw rectangle 2 on memory DC.
    Draw rectangle 3 on memory DC.
    Draw rectangle 4 on memory DC.
    Draw rectangle 5 on memory DC.
    Etc.
    BeginPaint
    Blit memory DC to window DC
    EndPaint

    End:
    Free memory DC

    Blit copies the information from one DC to another. Pens/brushes are used when drawing on the DC, so when using blit, you don't need them.
    Also about brushes / pens. If you create them, then you must free them. If you don't create them (you can select already existing, stock objects), then you don't need to free them.

    This is about how I would see the code.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #26
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by Elysia View Post
    Init:
    Create memory DC.
    Select proper pens/brushes on memory DC.

    Paint:
    Draw rectangle 1 on memory DC.
    Draw rectangle 2 on memory DC.
    Draw rectangle 3 on memory DC.
    Draw rectangle 4 on memory DC.
    Draw rectangle 5 on memory DC.
    Etc.
    BeginPaint
    Blit memory DC to window DC
    EndPaint

    End:
    Free memory DC

    Blit copies the information from one DC to another. Pens/brushes are used when drawing on the DC, so when using blit, you don't need them.
    Also about brushes / pens. If you create them, then you must free them. If you don't create them (you can select already existing, stock objects), then you don't need to free them.

    This is about how I would see the code.
    Cool, good direction here... thnx

  12. #27
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by DaveH View Post
    You might try overriding WM_ERASEBKGRND and just return non zero.
    The examples of this i've seen only in MFC

    Code:
     
      BOOL CRecordList::OnEraseBkgnd(CDC* pDC)
       {
          return FALSE;
       }
    How would one do this in WinAPI C? how do u override functions in C

  13. #28
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by csonx_p View Post
    How would one do this in WinAPI C? how do u override functions in C
    You don't.
    WM_ERASEBKGRND arrives via your WindowProc. if you recieve a WM_ERASEBKGRND message, just return non-zero from your WindowProc.
    This is pretty fundamental to Win32 programming. This is how you respond to windows messages.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #29
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by Elysia View Post
    Init:
    Create memory DC.
    Select proper pens/brushes on memory DC.

    Paint:
    Draw rectangle 1 on memory DC.
    Draw rectangle 2 on memory DC.
    Draw rectangle 3 on memory DC.
    Draw rectangle 4 on memory DC.
    Draw rectangle 5 on memory DC.

    Etc.
    BeginPaint
    Blit memory DC to window DC
    EndPaint

    End:
    @Elysia, i have a feeling that putting the lines in blue outside WM_PAINT rather in WM_CREATE may improve the code efficiency (or reduce flickers as well)... In fact ASAIC the only thing that should now be within WM_PAINT is the bitblt function.... Do you know what the following language in red is/means

    Code:
    	case WM_PAINT:
    		hdc = BeginPaint(hWnd, &ps);
    		// TODO: Fügen Sie hier den Zeichnungscode hinzu...
    		EndPaint(hWnd, &ps);
    		break;

  15. #30
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by Elysia View Post
    You don't.
    WM_ERASEBKGRND arrives via your WindowProc. if you recieve a WM_ERASEBKGRND message, just return non-zero from your WindowProc.
    This is pretty fundamental to Win32 programming. This is how you respond to windows messages.
    will just return 1

    Code:
    	case WM_ERASEBKGRND:
    		return 1;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  3. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  4. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  5. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM