Solved

Move a Window Without A Titlebar

Posted on 1997-08-30
18
458 Views
Last Modified: 2013-11-20
MSVC 1
How do I move a window without a title bar?
0
Comment
Question by:Adrian031197
  • 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

860 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