Solved

Move a Window Without A Titlebar

Posted on 1997-08-30
18
467 Views
Last Modified: 2013-11-20
MSVC 1
How do I move a window without a title bar?
0
Comment
Question by:Adrian031197
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 6
  • 3
18 Comments
 
LVL 4

Accepted Solution

by:
mbhakta earned 30 total points
ID: 1305289
By default implementation of Windows API's moving a window without the title bar  is not possible. But there is a way of doing this. Firstly, you need to override the WM_NCPAINT or OnNCPaint() windows message. When the user clicks and drags determine the POINT location of the window and if the point position lies on the valid client area of the window ( and not on the border ) perform a MoveWindow().

This is a more professional approach and needs some bit of brain storming and smart coding. You might be able to find some information in the MSDN. If u are new to Visual C++/Windows programming I would suggest spending some time reading some Win32 SDK documentation and if you are in a real hurry , then rely on some freeware OCX /VBX tool available on the net.
0
 

Author Comment

by:Adrian031197
ID: 1305290
Well, I had that basic idea, but how do I convert where the mouse click is to a screen coord? I know how how to do the rest of it.

And I'm having another difficulty with this topic as well. Even though I turn off the title bar in the App Studio, I still get one!
0
 
LVL 4

Expert Comment

by:mbhakta
ID: 1305291
To convert mouse clicks to screen co-ordinates you have reliable API's like ClientToScreen(), GetCursorPos() etc.

If u want to remove the title bar of the application window. You can either disable it in the PreCreateWindow() method. Or also , run SetWindowLong() to disable the title bar. Surprisingly, App Wiz is not that exhaustive to disable the Window styles properly.



0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 4

Expert Comment

by:mbhakta
ID: 1305292
To convert mouse clicks to screen co-ordinates you have reliable API's like ClientToScreen(), GetCursorPos() etc.

If u want to remove the title bar of the application window. You can either disable it in the PreCreateWindow() method. Or also , run SetWindowLong() to disable the title bar. Surprisingly, App Wiz is not that exhaustive to disable the Window styles properly.



0
 

Author Comment

by:Adrian031197
ID: 1305293
I'm using a dialog as my main window. In the InitInstance() function I deleted the command to create a new window and inserted my dialog command.
In the App Studio, I unchecked title bar. When I test the dialog, there is no bar, but when I run the program, there is a bar, and everything is pushed down, some of it off the window. Very annoying.
0
 
LVL 1

Expert Comment

by:cnasarre
ID: 1305294
First, you can move a window with no caption. You just have to write a handler for the WM_NCHITTEST message and reply HTCAPTION

For your dialog problem, how do you use a dialog as your main window ? Are you using a CFormView ? If you are just calling DoModal() in your InitInstance(), your dialog should be displayed  with no caption. Otherwise, the dialog is wrapped by a frame.
A frame with a caption...



0
 

Author Comment

by:Adrian031197
ID: 1305295
I use a CDialog as my main view.
0
 
LVL 1

Expert Comment

by:cnasarre
ID: 1305296
You should create a new project and choose a dialog based one.
Unselect the "titlebar" style for the dialog and write a handler for WM_NCHITTEST :

UINT CDlgnotitleDlg::OnNcHitTest(CPoint point)
{
   return(HTCAPTION);
}

I have done it myself and it is working fine.
If you want it, send me a mail at nasarre@col.bsf.alcatel.fr and I'll send it to you

0
 

Author Comment

by:Adrian031197
ID: 1305297
There isn't such a thing as a dialog based program in MSVC 1. I have to do it myself, but when I compare what I've done to what the App Wizard does in future versions, it's the same.
0
 
LVL 1

Expert Comment

by:cnasarre
ID: 1305298
So, implement your dialog class

Unselect the "
0
 
LVL 1

Expert Comment

by:cnasarre
ID: 1305299
So, implement your dialog class

Unselect the "
0
 
LVL 1

Expert Comment

by:cnasarre
ID: 1305300
Sorry but my comment seems to be always truncated :-(


So, implement your dialog class

Unselect t
0
 
LVL 1

Expert Comment

by:cnasarre
ID: 1305301
Sorry but my comment seems to be always truncated :-((((

So, implement your dialog class, unselect the titlebar style for the
0
 
LVL 1

Expert Comment

by:cnasarre
ID: 1305302
Arrrggg !!!!!!!

Impossible to answer :-(

(1) no titlebar style for the dialog
(2) handler for WM_NCHITTEST and return HTCAPTION
(3) change your InitInstance() : DoModal() and return FALSE


0
 

Author Comment

by:Adrian031197
ID: 1305303
I HAVE done 1 & 3. And I guess 2 is for moving it without a bar.
0
 
LVL 1

Expert Comment

by:cnasarre
ID: 1305304
Right.
You have to add a handler for WM_NCHITTEST

BEGIN_MESSAGE_MAP(CDlgnotitleDlg, CDialog)
//{{AFX_MSG_MAP(CDlgnotitleDlg)
   ON_WM_NCHITTEST()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

with this implementation

UINT CDlgnotitleDlg::OnNcHitTest(CPoint point)
{
//      return CDialog::OnNcHitTest(point);
   return(HTCAPTION);
}

0
 

Author Comment

by:Adrian031197
ID: 1305305
Ok, but why do I still have a title bar?
0
 
LVL 1

Expert Comment

by:cnasarre
ID: 1305306
Take a look at your RC file and check that the dialog definition is done without WS_CAPTION style. Here is my own :

IDD_DLGNOTITLE_DIALOG DIALOGEX 0, 0, 185, 92
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE
EXSTYLE WS_EX_APPWINDOW
FONT 8, "MS Sans Serif"
BEGIN
    DEFPUSHBUTTON   "OK",IDOK,128,7,50,14
    PUSHBUTTON      "Cancel",IDCANCEL,128,23,50,14
    LTEXT           "TODO: Place dialog controls here.",IDC_STATIC,5,34,113,
                    8
END

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question