[ winapi ] Direct2D and scrollbar control and GUI questions RRS feed

  • Question

  • I have idea create GUI with direct2d. As I looked at documentation about direct2d and winapi, I discover similarities with WPF. My idea is subclass window controls (buttons, scrollbar, listbox etc...) and paint it with direct2d like vector graphics in WPF. But I can't find info, how to do that.

    For example it is very simple to change button with WM_PAINT, because button is very simple component. But scrollbar contains buttons, thumbs and area where is content. If I edit control in WPF designer (Blend) scrollbar I get each object and can apply / change style for each component in scrollbar. In winapi I can't find any info about that. I have several ideas how to do that, one of them is create own scrollbar control with composed subclassed button with own draw and other controls (content area and layout) created by me. Or do it everything in Direct2D?

    My second question is about GUI in Direct2d. As I read documentation about window and controls, I get Idea subclass each control and replace their draw / paint with Direct2d. I think this is how WPF is created. Is it a good idea? Or it is better everything draw in to one window with Direct2D and not use controls?

    Friday, August 14, 2020 4:27 PM

All replies

  • I think it is simpler to embed WPF controls, which can be easily customizable
    (I use ElementHost in C++ (/clr) or Winforms, and controls designed in XAML can also be loaded with XamlReader.Load)

    Friday, August 14, 2020 4:46 PM
  • Yes, I know about this solution, but I want do it everything in C++ and without .NET . Btw simpler solution can be use whole WPF for gui.
    Friday, August 14, 2020 5:04 PM
  • Yes, I know about this solution, but I want do it everything in C++ and without .NET . Btw simpler solution can be use whole WPF for gui.

    Yes, but C++/clr allows to use a standard Win32 app (_tWinMain, WndProc, etc...)

    and just add ElementHost as a child control to embed WPF controls

    WPF uses DirectX and it would need a huge amount of C++ code in Direct2D to re-create similar controls...

    (I use Direct2D mainly for graphic effects and fast animations)

    There is also the Visual Layer for advanced GUI

    Friday, August 14, 2020 5:40 PM
  • Is VisualLayer working in windows 7? I can't find any info about it.

    If not, I still waiting for answers for my questions. I am not looking for alternatives with UWP or .NET

    Friday, August 14, 2020 6:02 PM
  • Subclassing each control to replace WM_PAINT has no real sense, as many controls use Owner-Draw or Custom Draw to customize painting, because their original WM_PAINT is very complex (like ListViews or TreeViews)
    Friday, August 14, 2020 8:35 PM
  • Hi,

    Thank you for posting here.

    According to the issue, it is more related to the winapi. I suggest you should ask it in Winapi-General forum for better help.

    Best Regards,

    Jeanine Zhang

    "Visual c++" forum will be migrating to a new home on Microsoft Q&A !
    We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A !
    For more information, please refer to the sticky post.

    Monday, August 17, 2020 2:26 AM
  • And for a "control" sample (not really a control), you can see the MS SDK

    Direct2D List View Sample

    but it is not great (very slow to list and display items...)

    • Edited by Castorix31 Monday, August 17, 2020 8:54 AM
    Monday, August 17, 2020 8:48 AM