-1

I would like to draw some simple rectangles and text over the window frame so it looks like Visual Studio. Can it be done or should i make a borderless window and handle moving andresizing myself?

EDIT: I wrote this. But how do I draw now?

protected override void WndProc(ref Message m)
{
    if (m.Msg == WndProcMsg.WM_PAINT) //0x000f
    {

    }
    base.WndProc(ref m);
}
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Matic Babnik
  • 43
  • 2
  • 8
  • When I Googled for your title, there were a number of results. Could you update your question with which of this techniques you have already tried? – mjwills Jun 28 '19 at 12:16
  • [Fancy Windows Forms](https://www.codeproject.com/articles/33716/fancy-windows-forms?fid=1536616&df=90&mpp=25&sort=Position&view=Normal&spc=Relaxed&fr=101). VisualStudio is a WPF application, though (with a few WinForms parts). Not the same thing. – Jimi Jun 28 '19 at 12:21
  • The standard way since Vista is with DWM (mainly **DwmExtendFrameIntoClientArea**) A test in C#/Winforms, from MSDN sample : [Custom Caption](https://i.ibb.co/2s7hc5z/Custom-Caption2.jpg) (DirectComposition can also be used, but more complicated...) – Castorix Jun 28 '19 at 13:53
  • 1
    @Castorix link to sample/code? – Matic Babnik Jun 28 '19 at 14:50
  • I converted/adapted the MS C++ code into C# from : [Custom Window Frame Using DWM](https://learn.microsoft.com/en-us/windows/desktop/dwm/customframe) – Castorix Jun 28 '19 at 16:41

2 Answers2

0

You should handle the WM_NCPAINT instead:

if (m.Msg == WM_NCPAINT) 
            { 

                IntPtr hdc = GetWindowDC(m.HWnd); 
                if ((int)hdc != 0) 
                { 
                    Graphics g = Graphics.FromHdc(hdc); 
                   .... work with graphics
                    ReleaseDC(m.HWnd, hdc); 
                } 

            } 

with the Graphics object you can do all the drawing operation you need. As far as I remember, when owner drawing the window you can possibly experience some flickering, in such a case you should consider handling WM_ERASEBACKGROUND and return false.

Felice Pollano
  • 32,832
  • 9
  • 75
  • 115
0

https://learn.microsoft.com/en-us/windows/desktop/dwm/customframe works great. It was traslated to C# by @Chris Taylor. You can download the project from his OneDrive

Just fix case Win32Messages.WM_NCHITTEST with:

int ht = NCHitText(m);
if (callDWP) 
{ 
   callDWP = (ht == Win32Constants.HTNOWHERE);
    result = new IntPtr(ht);
}
Matic Babnik
  • 43
  • 2
  • 8