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
Solved

Problems with WS_THICKFRAME

Posted on 2001-08-21
2
671 Views
Last Modified: 2013-11-20
Hi!
I want to show a small window in my CView derived window in order to let the user to move and resize it. What I did was to derive a class from CWnd (CSelectWnd) and then I handled WM_LBUTTONDOWN/WM_LBUTTONUP AND WM_MOUSEMOVE.
The code I used is the following:
void CSelectWnd::OnLButtonDown(UINT nFlags, CPoint point)
{
     SetCapture();
     m_bCaptured = true;
     CWnd::OnLButtonDown(nFlags, point);
}

void CSelectWnd::OnLButtonUp(UINT nFlags, CPoint point)
{
     ReleaseCapture();
        m_bCaptured = false;
     CWnd::OnLButtonUp(nFlags, point);
}
void CSelectWnd::OnMouseMove(UINT nFlags, CPoint point)
{
     if (m_bCaptured)
     {
          CWnd* pParent = GetParent();
         
          //Retrieve the old postion (in parent client coordinates)
          CRect oldPos;
          GetClientRect(&oldPos);
          ClientToScreen(oldPos);
          pParent->ScreenToClient(&oldPos);
         
          //Work out the new position (in parent client coordinates)
          CRect newPos(point.x - m_nDragOffset.x, point.y - m_nDragOffset.y,
               point.x - m_nDragOffset.x + oldPos.Width(), point.y  - m_nDragOffset.y + oldPos.Height());
          ClientToScreen(&newPos);
          pParent->ScreenToClient(&newPos);
         
          //Only move the window if it is inside the client rect of the parent window
          CRect clientRect;
          pParent->GetClientRect(&clientRect);
          if (newPos.left >= clientRect.left && newPos.top >= clientRect.top &&
               newPos.right < clientRect.right && newPos.bottom < clientRect.bottom)
          {
               newPos.InflateRect(3,3);
               MoveWindow(newPos, FALSE);
               oldPos.InflateRect(3,3);
               pParent->InvalidateRect(oldPos, FALSE);
               Invalidate(TRUE);
               CWnd::OnMouseMove(nFlags, point);
          }


     }
     else
          CWnd::OnMouseMove(nFlags, point);
}

Then in my view class I create an instance of this class as follows:

int CMyView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
     if (CView::OnCreate(lpCreateStruct) == -1)
          return -1;

     CRect rect(100,100,500,500);
     
     m_Select.Create(NULL, "TestClass", WS_VISIBLE|WS_CHILD|WS_THICKFRAME   , rect, this, 0xFFFF);


     return 0;
}

The window is correctly creatly but when I move the CSelectWnd derived window, it is not properly repainted. However it is correctly repainted if I remove thw WS_THICKFRAME style.
Any solution?

Thanks
Carlos

0
Comment
Question by:qocarlos
2 Comments
 
LVL 9

Accepted Solution

by:
Pacman earned 200 total points
ID: 6412346
in your mousemove function you use GetClientRect().
This function gives you the coordinates of the client-area of the window. Use GetWindowRect() to get the exterior rectangle of the window.
PS: GetWindowRect() comes already with screen coordinates so you don't have to call ClientToScreen().

Pacman
0
 
LVL 3

Author Comment

by:qocarlos
ID: 6413858
Thanks Pacman,
GetWindowRect can do the job. I will try it out and let you know if it works.

Carlos
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

829 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