Solved

Move a Window Without A Titlebar

Posted on 1997-08-30
18
453 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 4

Expert Comment

by:mbhakta
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I use a CDialog as my main view.
0
 
LVL 1

Expert Comment

by:cnasarre
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 1

Expert Comment

by:cnasarre
Comment Utility
So, implement your dialog class

Unselect the "
0
 
LVL 1

Expert Comment

by:cnasarre
Comment Utility
So, implement your dialog class

Unselect the "
0
 
LVL 1

Expert Comment

by:cnasarre
Comment Utility
Sorry but my comment seems to be always truncated :-(


So, implement your dialog class

Unselect t
0
 
LVL 1

Expert Comment

by:cnasarre
Comment Utility
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
Comment Utility
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
Comment Utility
I HAVE done 1 & 3. And I guess 2 is for moving it without a bar.
0
 
LVL 1

Expert Comment

by:cnasarre
Comment Utility
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
Comment Utility
Ok, but why do I still have a title bar?
0
 
LVL 1

Expert Comment

by:cnasarre
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now