GithubHelp home page GithubHelp logo

Question concerning creating a DC, getting a ListBox's selected font, and invoking GetSystemMetrics(SM_SM_CXBORDER) about winsafe HOT 2 CLOSED

jerrywrice avatar jerrywrice commented on June 10, 2024
Question concerning creating a DC, getting a ListBox's selected font, and invoking GetSystemMetrics(SM_SM_CXBORDER)

from winsafe.

Comments (2)

rodrigocfd avatar rodrigocfd commented on June 10, 2024

Yes, it is possible.

In your C++ example, you used CClientDC, which is an MFC class that simply manages GetDC/ReleaseDC calls. In WinSafe, GetDC itself returns a guard which calls ReleaseDC, so the whole thing is transparent and you don't need to worry about it.

Your code has a mistake: you must save the old font returned by SelectObject and re-select it after using. This is also done automatically by a guard in WinSafe.

Another difference is that MFC calls GetTextExtent, but the actual Win32 function is GetTextExtentPoint32. They chose to rename it for some reason.

So, your translated code appears to be like this:

use winsafe as w;

let dc = my_list.hwnd().GetDC()?;

let f = my_list.hwnd().SendMessage(w::msg::wm::GetFont {}).unwrap();
let _old_font = dc.SelectObject(&f);

let mut sz = dc.GetTextExtentPoint32("my text")?;
sz.cx += 3 * w::GetSystemMetrics(co::SM::CXBORDER);
if sz.cx > width {
    width = sz.cx;
    my_list.hwnd().SendMessage(
        w::msg::lb::SetHorizontalExtent { width },
    );
}

from winsafe.

jerrywrice avatar jerrywrice commented on June 10, 2024

from winsafe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.