Help! If I move a window around alot, it starts to glitch graphically!

This is a discussion on Help! If I move a window around alot, it starts to glitch graphically! within the Windows Programming forums, part of the Platform Specific Boards category; If I were to say drag a window around alot, it will start to glitch. If this window has moved ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    27

    Help! If I move a window around alot, it starts to glitch graphically!

    If I were to say drag a window around alot, it will start to glitch. If this window has moved to the background once or more, it much easier to do this.

    For some reason, I can't use PrintScreen when this happens but basically:

    The top bar with the Maximize, minimize, X button dissapears.

    When I move over where one of those buttons should be, it appears, somewhere in the upper half of the screen (not where it's suppose to be)

    Nothing draws on the window. Nada. Except the background color of the window.

    If I continue to drag it, the window is repainted, but the old image of it is not erased on the screen! This creates a blur effect around the edges.

    Any help as to what is causing this?

  2. #2
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Post code?

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    27
    Code:
    #include <windows.h>
    
    HDC MapDC;
    
    HWND hWnd;
    const char ClsName[] = "Grid Test";
    const char WindowCaption[] = "Grid Test";
    LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
    INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                       LPSTR lpCmdLine, int nCmdShow)
    {
        MSG         Msg;
        WNDCLASSEX  WndClsEx;
    
        WndClsEx.cbSize        = sizeof(WNDCLASSEX);
        WndClsEx.style         = CS_HREDRAW | CS_VREDRAW;
        WndClsEx.lpfnWndProc   = WndProc;
        WndClsEx.cbClsExtra    = NULL;
        WndClsEx.cbWndExtra    = NULL;
        WndClsEx.hInstance     = hInstance;
        WndClsEx.hIcon         = LoadIcon(hInstance, IDI_APPLICATION);
        WndClsEx.hCursor       = LoadCursor(NULL, IDC_ARROW);
        WndClsEx.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
        WndClsEx.lpszMenuName  = NULL;
        WndClsEx.lpszClassName = ClsName;
        WndClsEx.hIconSm       = LoadIcon(hInstance, IDI_APPLICATION);
    
        RegisterClassEx(&WndClsEx);
    
        hWnd = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,
                              ClsName,
                              WindowCaption,
                              WS_OVERLAPPEDWINDOW,
                              100,
                              120,
                              600,
                              600,
                              NULL,
                              NULL,
                              hInstance,
                              NULL);
    
        ShowWindow(hWnd, nCmdShow);
        UpdateWindow(hWnd);
    
        while( GetMessage(&Msg, NULL, 0, 0) )
        {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
    
        return Msg.wParam;
    }
    //---------------------------------------------------------------------------
    LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
    {
        HDC hDC;
        PAINTSTRUCT Ps;
        COLORREF Red = RGB(255, 0, 0);
        COLORREF Green = RGB(0, 255, 0);
        COLORREF Blue  = RGB(0 ,0, 255);
        COLORREF Yellow = RGB(191, 196, 9);
        HPEN RedPen = CreatePen(PS_SOLID, 0, Red);
        HPEN GreenPen = CreatePen(PS_SOLID, 0, Green);
        HPEN BluePen = CreatePen(PS_SOLID, 0, Blue);
        HPEN YellowPen = CreatePen(PS_SOLID, 0, Yellow);
    
        int y = 0;
    
        switch(Msg)
        {
        case WM_CREATE:
    	HDC windowDC;
    	windowDC = GetDC(hWnd);
    	MapDC = CreateCompatibleDC(windowDC);
    	SelectObject(MapDC, CreateCompatibleBitmap(windowDC, 310, 310));
    	return 0;
        case WM_PAINT:
    	hDC = BeginPaint(hWnd, &Ps);
    	SelectObject(MapDC, YellowPen);
    	for (double i = 0; i <= 310; i = i + 30.9) {
    		MoveToEx(MapDC, i, 0, NULL);
    		LineTo(MapDC, i, 368);
    		MoveToEx(MapDC, 0, i, NULL);
    		LineTo(MapDC, 310, i);
    	}
    	BitBlt(hDC, 264, 20, 310, 310, MapDC, 0, 0, SRCCOPY);
    	EndPaint(hWnd, &Ps);
    	break;
        case WM_DESTROY:
    	DeleteDC(MapDC);
            PostQuitMessage(WM_QUIT);
            break;
        default:
            return DefWindowProc(hWnd, Msg, wParam, lParam);
        }
        return 0;
    }
    //---------------------------------------------------------------------------
    This is a quick test I made. Just grab it and drag like crazy for a minute or so. I took out the custom ICON.

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    27
    Another SideEffect: Black Pop up menus for ALL Apps after this glitch has happened.

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,630
    You're system is running out of GDI resources.

    Read this article: GDI Objects

    gg

  6. #6
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,259
    Do you realise you're creating pens with every message sent to your window, whether it's a WM_PAINT or not?

    Move your CreatePen schiznitch to your WM_PAINT code and release the bloody things with DeleteObject(...) when at the end of that message!

  7. #7
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    You could do what the smurf said, or you could just make them all static.

  8. #8
    Registered User
    Join Date
    Mar 2004
    Posts
    27
    I made the pens Global because if I put them into the WM_PAINT message I keep getting "case bypasses declaration of local variable"

  9. #9
    Registered User
    Join Date
    Nov 2003
    Posts
    28
    Originally posted by vulcan_146
    I made the pens Global because if I put them into the WM_PAINT message I keep getting "case bypasses declaration of local variable"
    Use..

    Code:
    case WM_PAINT:
    {
            //CODE HERE
    }
    Using the '{' & '}' will stop the "case bypass" error.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 07:14 AM
  2. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  3. Formatting Output
    By Aakash Datt in forum C++ Programming
    Replies: 2
    Last Post: 05-16-2003, 08:20 PM
  4. How To move the Window?!!
    By c-- in forum Windows Programming
    Replies: 2
    Last Post: 09-01-2002, 07:41 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

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