Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 776551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:28:04+00:00 2026-05-14T19:28:04+00:00

I’m creating a custom drawn window by specifying border style NONE and custom processing

  • 0

I’m creating a custom drawn window by specifying border style NONE and custom processing of WM_NCHITTEST. I’ve defined some area as ‘my window caption’ and returning HTCAPTION result for WM_NCHITTEST in this area. When window is in normal state the behavior is expected by me. The window can be moved by dragging ‘my window caption’ and can be maximized by double clicking on it.

The problem is with the behavior of my window in maximized state. I still returning HTCAPTION result for WM_NCHITTEST in area of ‘my window caption’ and window can be restored to original size by double clicking on it again, but it’s also still can be moved and this isn’t what I want. What should I do to fix such behavior?


Fix:

    protected override void WndProc(ref Message m)
    {
        if(m.Msg == WM_NCHITTEST)
        {
            Point pos = new Point(m.LParam.ToInt32() & 0xffff, m.LParam.ToInt32() >> 16);
            pos = this.PointToClient(pos);
            if(HitTestForNC(ref m, pos))
            {
                if(WindowState != FormWindowState.Maximized || m.Result != (IntPtr)HitTestValues.HTCAPTION)
                {
                    return;
                }
            }
        }
        else if(m.Msg == WM_GETMINMAXINFO)
        {
            base.WndProc(ref m);
            MinMaxInfo mmi = (MinMaxInfo)Marshal.PtrToStructure(m.LParam, typeof(MinMaxInfo));
            mmi.ptMaxPosition = Screen.FromControl(this).WorkingArea.Location;
            mmi.ptMaxSize = Screen.FromControl(this).WorkingArea.Size;
            Marshal.StructureToPtr(mmi, m.LParam, false);
            return;
        }
        base.WndProc(ref m);
    }

    protected override void OnMouseDoubleClick(MouseEventArgs e)
    {
        if(e.Button == MouseButtons.Left)
        {
            Message m = new Message();
            if(HitTestForNC(ref m, e.Location))
            {
                if(m.Result == (IntPtr)HitTestValues.HTCAPTION && WindowState == FormWindowState.Maximized)
                {
                    WindowState = FormWindowState.Normal;
                    return;
                }
            }
        }
        base.OnMouseDoubleClick(e);
    }

HitTestForNC method is responsible for evaluation of hit test result on my custom drawn form. The implementation may look ugly, but it’s pretty simple.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T19:28:05+00:00Added an answer on May 14, 2026 at 7:28 pm

    What you describe is a bit weird – the maximized window can’t usually be moved. In particular it occupies the whole desktop area, and AFAIK the system doesn’t ‘drag’ it when its caption (i.e. – the area for which hit test was HT_CAPTION) is dragged.

    Can you please specify more info:

    1. How many desktops do you have (is it a multi-monitor system)?
    2. Do you respond on WM_GETMINMAXINFO to prevent your window from occupying the whole desktop area?

    BTW I can imagine a workaround: when your window is maximized – don’t return HT_CAPTION on hit test. Instead you may return HT_CLIENT, this will prevent your window from dragging.

    However you’ll have to manually implement “restoring” of your window when double-clicked. You should then respond on WM_LBUTTONDBLCLK and restore your position manually.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 390k
  • Answers 390k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm surprised no one has posted Inmon's definition: A warehouse… May 15, 2026 at 12:59 am
  • Editorial Team
    Editorial Team added an answer I believe it will have a major impact on your… May 15, 2026 at 12:59 am
  • Editorial Team
    Editorial Team added an answer Are you sure that you have obtained the maximum speed… May 15, 2026 at 12:59 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.