将窗口移到屏幕外部时,Winapi编辑控件消失

时间:2018-07-20 17:39:12

标签: c++ winapi controls edit

我正在使用EDIT循环创建几个for元素。当我将窗口移到屏幕外然后移回内部时,EDIT控件以及WM_PAINT事件中的一行都消失了。

“创建”事件:

case WM_CREATE:
    for( int i =0; i < 4; i++ ){
        text = CreateWindow("EDIT","text",WS_VISIBLE | WS_CHILD , 0,i*40+100,100,10, hwnd , NULL, NULL, NULL);
    }

    // Other elements
    break;

“绘画”事件:

case WM_PAINT:
    {
        hdc = GetDC(hwnd);
        SetRect(&secondbackground, 0, 70, 800, 500);
        FillRect(hdc, &secondbackground, CreateSolidBrush(RGB(0,200,200)) );
        ReleaseDC(hwnd, hdc);

        hdc = GetDC(hwnd);
        SetRect(&secondbackground, 0, 0, 800, 20);
        FillRect(hdc, &secondbackground, CreateSolidBrush(RGB(0,100,200)) );
        ReleaseDC(hwnd, hdc);

        hdc = BeginPaint( hwnd, &ps );
        MoveToEx(hdc,1,52,NULL);
        LineTo(hdc,100,200);
        EndPaint( hwnd, &ps );

        hdc = GetDC(hwnd);
        SetPixel(hdc,300,300,RGB(255,255,255));
        EndPaint( hwnd, &ps );
    }
    break;

1 个答案:

答案 0 :(得分:0)

在处理WM_PAINT时使用BeginPaint / EndPaint,这将强制执行背景绘制,而GetDC则不执行。