Question

Completely Remove Window Title Bar (Caption) Buttons Without Removing WS_SYSMENU

Asked by: bdunz19

Hi Experts!

My task is to get rid of the caption buttons ie: min, max, and close. I need to still have the window menu (formerly the system menu). I cannot come up with any way of doing this without using "ModifyStyle(WS_SYSMENU, 0, 0);".

Now, if I need to do that, then I need some way of hooking the mouse event when it right clicks on the window's taskbar button to display a popup menu. So basically, I'm looking for a way to accomplish removing (not disabled, but gone) all caption buttons, while preserving the window menu.

I hope some one knows a solution for this, as I'm stumped!

Thanks guys,
Brandon

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2007-01-05 at 15:08:31ID22112964
Tags

bar

,

title

,

window

,

remove

Topic

Windows MFC Programming

Participating Experts
3
Points
500
Comments
19

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. No Sysmenu
    Is it possible to create a WIN32 app with a window having a title bar and a [X] close button BUT NO system menu. Or do I have to have a dialog box as my main. Thanks,
  2. caption
    how can I change the caption of a object with another value of a variable
  3. An own caption bar
    I need a component who display an own caption . Replace the standard caption with an yellow bar . Just a simple bar . Without buttons or icons . I will make myself . I read a lots of codes for that ,but I don't understand how to replace the standar caption with my own .
  4. Display Taskbar Icon in Dialog without WS_CAPTION & WS…
    Hi, In my application I have several popup dialogs with custom skins. The skins means that the dialogs cannot have a border. However, I would still like to display icons for the dialog in their taskbar captions. I've tried everything I can think of without success and so w...
  5. WS_SYSMENU, not getting menu
    Wrote CreateWindow() with option to create menu. Menu not appearing. Part of code; hwndMain = CreateWindowEx(0, "MY_WINDOW1", "WINDOW EXERCISE", WS_SYSMENU | WS_CAPTION | WS_OVERLAPPEDWINDOW | WS_VSCROLL | WS_SIZEBOX | WS_HSCROLL, CW_USEDEFAULT, CW_USED...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: bdunz19Posted on 2007-01-05 at 15:12:52ID: 18255656

Also, now that I think about it, keeping the buttons from being drawn at all would work to, but I don't know where that is done either as it does not apear to be in WM_NCPAINT. Just a thought...

 

by: mahesh1402Posted on 2007-01-05 at 21:04:52ID: 18257111

>>I need some way of hooking the mouse event when it right clicks on the window's taskbar button to display a popup menu
>>I need to still have the window menu

No need to hook mouse..... for titleless dialog/window just add WS_SYSMENU style on 'PreSubclassWindow()' handler.....

Something like this :

void CMyDlg::PreSubclassWindow()
{
 // TODO: Add your specialized code here and/or call the base class
 
// Attach a system menu to this window
 LONG lStyle = GetWindowLong( this->GetSafeHwnd(), GWL_STYLE );

 SetWindowLong( this->GetSafeHwnd(), GWL_STYLE, lStyle | WS_SYSMENU );

 CDialog::PreSubclassWindow();
}

This will invoke system menu when you right click on window's taskbar button .

-MAHESH

 

by: bdunz19Posted on 2007-01-06 at 01:13:43ID: 18257552

Thanks Mahesh, but it seems what you are describing is a dialog window with no title bar? I still need to have a title bar and caption, just no buttons on it.

Let me know if I'm wrong with what I think you are describing.

Thanks man!

Brandon

 

by: AndyAinscowPosted on 2007-01-06 at 01:59:58ID: 18257630

You should be able to remove the maximise and minimise buttons without a problem.  The close button ('x') is linked with the WM_SYSMENU as you have found out.

Howwever you could disable it - put this into the OnCreate of the main frame (after the base class has been called)

      CMenu* pSysMenu = GetSystemMenu(FALSE);
      if (pSysMenu != NULL)
      {
            pSysMenu->RemoveMenu(SC_CLOSE,MF_BYCOMMAND);
      }

 

by: AndyAinscowPosted on 2007-01-06 at 02:18:11ID: 18257667

Just drawing over the buttons in response to an NCPAINT might hide them - but it probably would not stop the user action of a user clicking on them.  You would have to disable it as well.

 

by: bdunz19Posted on 2007-01-06 at 21:33:13ID: 18260998

Well, what happens is when you paint over the disabled close button is; it'll hide it completly, but when the user right clicks on the task bar button to display the window menu it the draws the disabled close button above the NCPAINT drawing. Then the only way to get ride of it is to minimize the window and restore it. I find it weird that moving the close button off screen does not cause it to be removed though...

If we know the close button is not drawn in WM_NCPAINT, then where the heck is it drawn?

The best solution would be to get rid of it entirely! But then there is no window menu!

 

by: AndyAinscowPosted on 2007-01-07 at 00:20:07ID: 18261275

My first comment will disable the 'x' (unfortunately still visible) but still leave the windows menu (right click support). If you need a close command on the menu then add your own menu item and perform the closing when that is selected.

As to where it come from - that may not be part of MFC, it could be deep in windows itself.

 

by: bdunz19Posted on 2007-01-07 at 02:37:21ID: 18261445

Hmm... I think you are right about it being deep inside windows. Because I cannot figure out how to stop it from drawing itself.

>>My first comment will disable the 'x' (unfortunately still visible) but still leave the windows menu (right click support). If you need a close command on the menu then add your own menu item and perform the closing when that is selected.

This would work for any normal circumstances, the problem is these are not normal circumstances haha! I need the 'x' to be gone completly, not just disabled.

I wish we had somone who wrote the win32 api on experts-exchange... maybe they would know how to get rid of it!

 

by: AndyAinscowPosted on 2007-01-07 at 08:34:54ID: 18262207

If it is disabled then you should be able to paint it over.  (You don't have to stop windows acting upon a mouse click on it).

You will probably have to trap quite a few events for the repainting to work properly.  

 

by: bdunz19Posted on 2007-01-07 at 11:43:36ID: 18262841

I see what you're saying and hopefully you know what other events to trap, because like I said, when I paint over it, everything looks good, untill the user right clicks on the task bar button. At that point windows redraws the disabled close button over my WM_NCPAINT paintings.

This is begining to make me sad... But thanks for still giving it a shot Andy!

 

by: AndyAinscowPosted on 2007-01-07 at 13:38:50ID: 18263199

You could remove the caption bar  (ModifyStyle) in the OnCreate.
The window will look odd but the system menu is still in place for the 'button' on the windows task bar.

Now you ought to be able to modify the non-client area  to provide your own space for drawing a caption bar in the non-client paint.  

That should give you what you want.

 

by: meenasreePosted on 2007-01-07 at 22:04:11ID: 18264996

Set your dialogframe property to None

 

by: meenasreePosted on 2007-01-07 at 22:05:56ID: 18265001

Sorry its not dialogframe but
Border property to NONE

 

by: bdunz19Posted on 2007-01-08 at 05:27:56ID: 18266522

Then the problem I get is I have no border. I need to handle sizing the window, ect...

 

by: AndyAinscowPosted on 2007-01-08 at 06:39:43ID: 18266988

If you remove the caption bar you get a border, just no caption with the buttons on it.  The frame is still there and can be resized.  Make space for the 'caption' and then draw your own caption.

 

by: bdunz19Posted on 2007-01-08 at 07:37:17ID: 18267447

Hi Andy,
That was actually the way I had attempted it to begin with and had a CTitleBar derived from a CWnd as my title bar control. I can't exactly remember why, as it was 4 months ago, but I ended up giving up on that as a solution. I suppose I'll give that a try again.

One more thing though (because I think it might be easier), If I hook the mouse do you know if there is a way to detect when the user right clicks over the taskbar button of a window? I really think this would be the easiest solution, rather than rewriting all my title bar code. It really makes me wonder how other programmers have created their own windows skins.

Let me know if you know how that can be done!

Thanks again!

Brandon

 

by: AndyAinscowPosted on 2007-01-08 at 07:46:35ID: 18267525

<CTitleBar derived from a CWnd as my title bar control>
I am talking about drawing in the non-client area yourself.  I don't think you can have a child window appearing outside of the client area.


right-click on task bar button, if the app has a sysmenu then windows will invoke it for you.


Look, do a quick test.  Make a new SDI app with thickframe (for resizing) and sysmenu and caption.  In the OnCreate of the frame use ModifyStyle to remove the caption bar and check you get the functionality you want re resizing and the sys menu.

 

by: bdunz19Posted on 2007-01-08 at 13:31:59ID: 18270686

>> I am talking about drawing in the non-client area yourself.  I don't think you can have a child window appearing outside of the client area.

Yeah, but the problem there is that you would have no nonclient area except the border, would you?

But that just gave me an idea!... If I removed the caption and then changed the client area on WM_NCCALCSIZE that would alow me to alocate some space for the nonclient caption that I need to draw! I really think this could work... I'm already modifying the client area a little as it is in WM_NCCALCSIZE...

Hey thanks again Andy, and hey no hard feelings about me using unathorized lanuguage on the board, alight? Haha, thanks again mate!

Brandon

 

by: AndyAinscowPosted on 2007-01-08 at 23:34:09ID: 18273774

<But that just gave me an idea!... If I removed the caption and then changed the client area on WM_NCCALCSIZE that would alow me to alocate some space for the nonclient caption that I need to draw! I really think this could work... I'm already modifying the client area a little as it is in WM_NCCALCSIZE...>


I think you missed the relevance of
'Now you ought to be able to modify the non-client area  to provide your own space for drawing a caption bar in the non-client paint.'
from an earlier comment of mine.


<hey no hard feelings about me using unathorized lanuguage on the board>
If I had then I wouldn't have made any comments here.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...