Home > Blockchain >  What is the correct way to call Win32 InvalidateRect to clear the client area using the Rust Crate f
What is the correct way to call Win32 InvalidateRect to clear the client area using the Rust Crate f

Time:11-30

The following code leaves the client area unchanged.

fn ResetGame(hwnd: &HWND, next_char: &mut u32, game_grid: &mut [u32; 9], X: u32) {
    unsafe {
        *next_char = X;
        //println!("in ResetGame and next_char is {}", next_char);

        for i in 0..9 {
            game_grid[i] = 0;
        }
        InvalidateRect(hwnd, std::ptr::null_mut(), BOOL(1)); // TRUE ?
    }
}

CodePudding user response:

InvalidateRect

adds a rectangle to the specified window's update region. The update region represents the portion of the window's client area that must be redrawn.

It does not, by itself, change the contents of a window. It merely causes the system to generate a WM_PAINT message when no higher priority messages are in the message queue. It is the WM_PAINT (and WM_ERASEBKGND) message that's responsible for rendering the contents.

The actual call itself can be simplified by passing a bool value instead; a conversion from bool to BOOL is provided by the crate. The second argument is of type *const RECT so you can pass std::ptr::null(). In other words:

InvalidateRect(hwnd, std::ptr::null(), true);

It's probably also a good idea to check the return value of type BOOL.

CodePudding user response:

Thank you for your help. The problem turned out to be a device context null brush.

  • Related