Wm_paint

This is a discussion on Wm_paint within the Windows Programming forums, part of the Platform Specific Boards category; it draws the txt on the screen but it doesnt seem to redraw is there any way i could fix ...

  1. #1
    Banned
    Join Date
    Oct 2004
    Posts
    250

    Wm_paint

    it draws the txt on the screen but it doesnt seem to redraw
    is there any way i could fix this ?
    Code:
    #include <windows.h>
    
    LRESULT CALLBACK WindProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
    
    INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                       LPSTR lpCmdLine, int nCmdShow)
    {
        WNDCLASSEX  WndCls;
        static char szAppName[] = "GDISuite";
        MSG         Msg;
    
        WndCls.cbSize        = sizeof(WndCls);
        WndCls.style         = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
        WndCls.lpfnWndProc   = WindProcedure;
        WndCls.cbClsExtra    = 0;
        WndCls.cbWndExtra    = 0;
        WndCls.hInstance     = hInstance;
        WndCls.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
        WndCls.hCursor       = LoadCursor(NULL, IDC_ARROW);
        WndCls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
        WndCls.lpszMenuName  = NULL;
        WndCls.lpszClassName = szAppName;
        WndCls.hIconSm       = LoadIcon(hInstance, IDI_APPLICATION);
        RegisterClassEx(&WndCls);
    
        CreateWindowEx(WS_EX_OVERLAPPEDWINDOW,
                              szAppName,
                              "GDI Accessories and Tools",
                              WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                              CW_USEDEFAULT,
                              CW_USEDEFAULT,
                              CW_USEDEFAULT,
                              CW_USEDEFAULT,
                              NULL,
                              NULL,
                              hInstance,
                              NULL);
    
        while( GetMessage(&Msg, NULL, 0, 0) )
        {
            TranslateMessage(&Msg);
            DispatchMessage( &Msg);
        }
    
        return static_cast<int>(Msg.wParam);
    }
    
    LRESULT CALLBACK WindProcedure(HWND hWnd, UINT Msg,
    			   WPARAM wParam, LPARAM lParam)
    {
    HDC hDC;
    PAINTSTRUCT Ps;
    HWND hwnd = FindWindow(NULL, "Age of Empires");
    
    	switch(Msg)
    	{
    case WM_PAINT:
    	while(1)
    	{
    		hDC = BeginPaint(hwnd, &Ps);
    		TextOut(hDC, 50, 42, "Test", 13);
    		EndPaint(hwnd, &Ps);
    	}
    		break;
    
    	case WM_DESTROY:
    		PostQuitMessage(WM_QUIT);
    		break;
    	default:
    		return DefWindowProc(hWnd, Msg, wParam, lParam);
    	}
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    What are you hoping to accomplish with this code snippet?

    Code:
    case WM_PAINT:
    	while(1)
    	{
    		hDC = BeginPaint(hwnd, &Ps);
    		TextOut(hDC, 50, 42, "Test", 13);
    		EndPaint(hwnd, &Ps);
    	}
    		break;
    ??
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Banned
    Join Date
    Oct 2004
    Posts
    250
    im trying to draw on another screen, i need to know how to do it

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    123
    I haven't analysed your code, but you may need to use an API such as InvalidateRect to invalidate the area to be redrawn. Then the wm_paint message is generated, the area should be redrawn.

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    remove the while, it is not needed and will cause problems.

    Use InvalidateRect() and UpdateWindow() to call for a paint and then tell the app to process the paint immediately. Do this when you want the text to change.

    In your paint use GetUpdateRect() and IsRectEmpty() BEFORE the BeginPaint() to ensure you have an area to draw.


    Code:
    RECT              Rect;
    GetUpateRect(hWnd, &Rect);
    if(IsRectEmpty(&Rect))
            GetClientRect(hWnd,&Rect); // fill Rect with entire screen
    
    BeginPaint(hWnd, &ps);
    //ensure nothing is on the screen by painting it white
    FillRect( ps.hdc , &Rect, GetStockObject(WHITE_BRUSH) );
    //print text
    GetTextExtentPoint32() can be used to find the area the actual text will take up as strings containing different characters take up diff amounts of space.
    "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

Popular pages Recent additions subscribe to a feed

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