flickering

This is a discussion on flickering within the Windows Programming forums, part of the Platform Specific Boards category; When my window is resizing ( that's while the window is being draged ), my listbox control flickers for unknown ...

  1. #1
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377

    flickering

    When my window is resizing ( that's while the window is being draged ), my listbox control flickers
    for unknown reason. All the other controls which include "richedit, edit, button, scrollbar" are
    working normaly. I'm not doing any drawing myself, i just declared listbox with this:

    Code:
    CreateWindowEx(WS_EX_CLIENTEDGE,"ListBox","........",
    	WS_CHILD | WS_VSCROLL | LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT | LBS_NOTIFY, 
    	10, 10, 200, 100, hWindow, (HMENU)(305), hinstance, NULL);
    
    // i'm adding a few strings to my listbox here, not important
    for(int i = 0; i < number_of_books; i++)
    {
    	SendMessage(lBooks, LB_ADDSTRING, NULL, (LPARAM)books.name[i]);
    }
    As you can see my listbox has few strings, one of them is selected.
    The only problem is flickering, and i'm not sure why other controls aren't flickering as well.

    bahh....
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  2. #2
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    I was concerned with the same thing once, but realized that it's is an unfortunate circumstance with GDI rendering. Try other windows and some controls will flicker as well. I just resized a Windows Explorer window around and the tree control flickered like a four-year-old's boogers (or is that "flicked?") and an FTP app I have open with list controls does the same.

    Wait for Vista to come out and maybe it'll stop (though, given MS's track record, I doubt it).

  3. #3
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    no no, this flickering is really unique. And i mean really!!!
    It will flicker always, apsolutly always while window is resized...
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,853
    Look at WM_ERASEBKGND. Try setting the return to true.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Look at WM_ERASEBKGND. Try setting the return to true.
    He can't do that unless he subclasses the EDIT control. And unless he is doing the drawing himself, this is a bad idea.

    Make sure that the parent window has the WS_CLIPCHILDREN style.

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    WM_ERASEBKGND is still an option if the child control covers the parent's client and the parent's WM_ERASEBKGND is the one handled but, equally, given this set of circumstances, setting the parent window's class brush to NULL would achieve the same result. Another factor to consider is the registered class style (as opposed to the window style ie the 'style' parameter of WNDCLASSEX) in which the presence of either the CS_VREDRAW or the CS_HREDRAW style bits can contribute to flicker when resizing the parent.

    But use WS_CLIPCHILDREN anyway, as bithub has recommended; it's a lot simpler and very effective.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  7. #7
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    I have used WS_CLIPCHILDREN from begining, setting window background brush to NULL results
    in background beeing invisible, but still my list box flickers.
    Heres how i created my main window:
    Code:
      RegisterClassEx(&objekt);
      hWindow = CreateWindowEx(
    	0,
    	"objekt",
    	" Harry Potter",
    	WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
    	50, 30, 500, 400,
    	HWND_DESKTOP,
    	NULL,
    	hinstance,
    	NULL);
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  8. #8
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    Heres a very simple application that i wrote, It has a listbox that flickers,
    and a resizeable window, compile it and test it...

    Code:
    #include <windows.h>
    #include <windowsx.h>
    
    HWND			hWindow;
    HDC 			hDC;
    
    #define		WIN32_LEAN_AND_MEAN
    #define 	KEYDOWN(vk_code) (GetAsyncKeyState(vk_code) & 0x8000 ? 1 : 0)
    
    
    LRESULT CALLBACK WndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam)
    {
        HDC hDC;
        PAINTSTRUCT ps;
        RECT rect;
        
        switch(msg)
        {
            case WM_DESTROY:
                PostQuitMessage(0);
                return(0);
                break;
        }
        return DefWindowProc(hWindow, msg, wParam, lParam);    
    }    
    
    int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
        WNDCLASSEX 		objekt;
        MSG 		msg;
    
        
        objekt.hInstance = hinstance;
        objekt.lpszClassName = "objekt";
        objekt.lpfnWndProc = WndProc;
        objekt.style = CS_HREDRAW | CS_VREDRAW;
        objekt.cbSize = sizeof(WNDCLASSEX);
        objekt.hIcon = LoadIcon(NULL, IDI_WINLOGO);
        objekt.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
        objekt.hCursor = LoadCursor(NULL, IDC_ARROW);
        objekt.lpszMenuName = NULL;
        objekt.cbClsExtra = 0;
        objekt.cbWndExtra = 0;
        objekt.hbrBackground = (HBRUSH)(COLOR_WINDOW);
        
        RegisterClassEx(&objekt);
        hWindow = CreateWindowEx(
        0,
        "objekt",
        "example",
        WS_OVERLAPPEDWINDOW | WS_SYSMENU,
        0,0,500,500,
        HWND_DESKTOP,
        NULL,
        hinstance,
        NULL);
        
        ShowWindow(hWindow, nCmdShow);
        UpdateWindow(hWindow);
        
    	CreateWindowEx(WS_EX_CLIENTEDGE,"ListBox","........",WS_VISIBLE | WS_CHILD | WS_VSCROLL | LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT | LBS_NOTIFY, 0, 0, 100, 100, hWindow, (HMENU)(305), hinstance, NULL);
        while(TRUE)
        {
            if(PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
            {
    		if(msg.message == WM_QUIT){ PostQuitMessage(0); return(0); }
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
        	}
        }
        return(int)msg.wParam;
    }
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  9. #9
    Registered User r1ck0r's Avatar
    Join Date
    Apr 2005
    Location
    UK
    Posts
    30
    As Ken already stated, CS_VREDRAW and CS_HREDRAW both contribute to window flickering, they cause the whole window to be repainted when any rezising takes place, remove them and I can say confidently that the flickering will stop.

    P.S. Also, your message loop is rather processor intensive, a better example would be like so:

    Code:
    #include <windows.h>
    
    #define LISTBOX1 1001
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
        switch(msg)
        {
    	case WM_CREATE:
    		{
    			HWND hList = CreateWindowEx(NULL, "LISTBOX", "",
    				WS_VISIBLE | WS_CHILD | WS_VSCROLL | LBS_HASSTRINGS | 
    				LBS_NOINTEGRALHEIGHT | LBS_NOTIFY | WS_BORDER, 
    				40, 40, 300, 300, hwnd, (HMENU)LISTBOX1, GetModuleHandle(0), NULL);
    			
    			SendMessage(hList, LB_ADDSTRING, NULL, (LPARAM)"String1");
    			SendMessage(hList, LB_ADDSTRING, NULL, (LPARAM)"String2");
    			SendMessage(hList, LB_ADDSTRING, NULL, (LPARAM)"String3");
    			return 0;
    		}
    	case WM_CLOSE:
    	case WM_DESTROY:
    		PostQuitMessage(0);
            return 0;
    	default:
    		return DefWindowProc(hwnd, msg, wParam, lParam);
        }
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    				   LPSTR lpCmdLine, int nCmdShow)
    {
        WNDCLASSEX wc;
        HWND hwnd;
        MSG Msg;
    	
        wc.cbSize        = sizeof(WNDCLASSEX);
        wc.style         = 0;
        wc.lpfnWndProc   = WndProc;
        wc.cbClsExtra    = 0;
        wc.cbWndExtra    = 0;
        wc.hInstance     = hInstance;
        wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
        wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
        wc.lpszMenuName  = NULL;
        wc.lpszClassName = "WindowFickerCls";
        wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
    	
        if(!RegisterClassEx(&wc))
        {
            MessageBox(NULL, "Window Registration Failed!", "Error!",
                MB_ICONEXCLAMATION | MB_OK);
            return 0;
        }
    	
        hwnd = CreateWindowEx(
            WS_EX_CLIENTEDGE,
            "WindowFickerCls",
            "No Flickering",
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT, CW_USEDEFAULT, 400, 400,
            NULL, NULL, hInstance, NULL);
    	
        if(hwnd == NULL)
        {
            MessageBox(NULL, "Window Creation Failed!", "Error!",
                MB_ICONEXCLAMATION | MB_OK);
            return 0;
        }
    	
        ShowWindow(hwnd, nCmdShow);
        UpdateWindow(hwnd);
    	
        while(GetMessage(&Msg, NULL, 0, 0) > 0)
        {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
        return Msg.wParam;
    }
    Last edited by r1ck0r; 12-23-2005 at 07:22 AM.

  10. #10
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    Ok, i did that, now it works. Thanks.
    Code:
    objekt.style = CS_HREDRAW | CS_VREDRAW;
    Should my "objekt.style" contain something or just NULL;
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  11. #11
    Registered User r1ck0r's Avatar
    Join Date
    Apr 2005
    Location
    UK
    Posts
    30
    The style property can be NULL, yes.
    Other window class styles can be found here: http://msdn.microsoft.com/library/de...boutwindow.asp

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Flickering textbox
    By Helix in forum Windows Programming
    Replies: 3
    Last Post: 06-01-2004, 06:19 AM
  2. graphics flickering problem
    By Benzakhar in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 02-23-2004, 04:15 PM
  3. TextOut() flickering
    By Xterria in forum Game Programming
    Replies: 6
    Last Post: 01-22-2004, 08:55 PM
  4. Argh! Flickering!!!
    By SMurf in forum Windows Programming
    Replies: 6
    Last Post: 03-03-2002, 09:43 AM
  5. Flickering
    By Visu A in forum C Programming
    Replies: 1
    Last Post: 02-26-2002, 11:48 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21