Click here to Skip to main content
15,903,201 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: how to make a static box movable in MFC.? Pin
Chris Losinger7-Sep-12 1:28
professionalChris Losinger7-Sep-12 1:28 
GeneralRe: how to make a static box movable in MFC.? Pin
mbatra317-Sep-12 1:36
mbatra317-Sep-12 1:36 
GeneralRe: how to make a static box movable in MFC.? Pin
Chris Losinger7-Sep-12 1:39
professionalChris Losinger7-Sep-12 1:39 
GeneralRe: how to make a static box movable in MFC.? Pin
mbatra317-Sep-12 1:47
mbatra317-Sep-12 1:47 
GeneralRe: how to make a static box movable in MFC.? Pin
mbatra317-Sep-12 1:48
mbatra317-Sep-12 1:48 
GeneralRe: how to make a static box movable in MFC.? Pin
Chris Losinger7-Sep-12 1:54
professionalChris Losinger7-Sep-12 1:54 
GeneralRe: how to make a static box movable in MFC.? Pin
mbatra317-Sep-12 2:03
mbatra317-Sep-12 2:03 
GeneralRe: how to make a static box movable in MFC.? Pin
mbatra317-Sep-12 2:07
mbatra317-Sep-12 2:07 
Hi Chris,

I got it, the problem was in OnMouseMove, Now the complete code is as below:
I changed the position co-ordinates in OnMouseMove.

// ChageTextDyn.cpp : implementation file
//

#include "stdafx.h"
#include "MBFirst.h"
#include "ChageTextDyn.h"
#include "afxdialogex.h"


// ChageTextDyn dialog

IMPLEMENT_DYNAMIC(ChageTextDyn, CDialogEx)

ChageTextDyn::ChageTextDyn(CWnd* pParent /*=NULL*/)
: CDialogEx(ChageTextDyn::IDD, pParent)
{
m_bButtonDown = false;
}

ChageTextDyn::~ChageTextDyn()
{
}

void ChageTextDyn::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_INPUTTEXT, m_InputEditText);
DDX_Control(pDX, IDC_OUTPUTTEXT, m_OutputStaticText);
DDX_Control(pDX, IDC_STTEXT, m_text);
}


BEGIN_MESSAGE_MAP(ChageTextDyn, CDialogEx)
ON_BN_CLICKED(IDTEXTEXIT, &ChageTextDyn::OnBnClickedTextexit)
ON_EN_CHANGE(IDC_INPUTTEXT, &ChageTextDyn::OnChangeInputtext)
ON_BN_CLICKED(IDCREATETEXTBOX, &ChageTextDyn::OnBnClickedCreatetextbox)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()


// ChageTextDyn message handlers


void ChageTextDyn::OnBnClickedTextexit()
{
ChageTextDyn::DestroyWindow();
}


void ChageTextDyn::OnChangeInputtext()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialogEx::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.

CString inText;
m_InputEditText.GetWindowTextW(inText);
m_OutputStaticText.SetWindowTextW(inText);
m_text.SetWindowTextW(inText);
}


void ChageTextDyn::OnBnClickedCreatetextbox()
{
pStatic = new CStatic();
pStatic->Create(_T(""), WS_CHILD | WS_VISIBLE | SS_RIGHT,CRect(30,130,130,150), this);
}


void ChageTextDyn::OnLButtonDown(UINT nFlags, CPoint point)
{
m_bButtonDown = true;
m_StartPoint = point.x;
m_endPoint = point.y;
CDialogEx::OnLButtonDown(nFlags, point);
}


void ChageTextDyn::OnLButtonUp(UINT nFlags, CPoint point)
{
m_bButtonDown = false;
//m_endPoint = point;
ReleaseCapture();

CDialogEx::OnLButtonUp(nFlags, point);
}


void ChageTextDyn::OnMouseMove(UINT nFlags, CPoint point)
{
CRect rc, rct;
m_OutputStaticText.GetWindowRect(&rc);
m_text.GetWindowRect(&rct);

if( m_bButtonDown )
{
int newX = /*rc.left +*/ point.x - m_StartPoint;
int newY = /*rc.top +*/ point.y - m_endPoint;
int width = rc.right - rc.left;
int height = rc.bottom - rc.top;

SetCapture();
m_OutputStaticText.MoveWindow(newX, newY, width, height);
m_text.MoveWindow(newX, newY, width, height);
}

CDialogEx::OnMouseMove(nFlags, point);
}


BOOL ChageTextDyn::OnInitDialog()
{
CDialogEx::OnInitDialog();

//m_InputEditText.SetFocus();

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}


I am able to move the static text box.


Regards,
Mbatra
GeneralRe: how to make a static box movable in MFC.? Pin
Chris Losinger7-Sep-12 2:18
professionalChris Losinger7-Sep-12 2:18 
GeneralRe: how to make a static box movable in MFC.? Pin
mbatra317-Sep-12 2:23
mbatra317-Sep-12 2:23 
GeneralRe: how to make a static box movable in MFC.? Pin
Chris Losinger7-Sep-12 2:31
professionalChris Losinger7-Sep-12 2:31 
GeneralRe: how to make a static box movable in MFC.? Pin
mbatra317-Sep-12 2:37
mbatra317-Sep-12 2:37 
GeneralRe: how to make a static box movable in MFC.? Pin
Chris Losinger7-Sep-12 3:10
professionalChris Losinger7-Sep-12 3:10 
GeneralRe: how to make a static box movable in MFC.? Pin
mbatra3110-Sep-12 23:14
mbatra3110-Sep-12 23:14 
GeneralRe: how to make a static box movable in MFC.? Pin
Chris Losinger11-Sep-12 0:57
professionalChris Losinger11-Sep-12 0:57 
GeneralRe: how to make a static box movable in MFC.? Pin
mbatra3111-Sep-12 1:35
mbatra3111-Sep-12 1:35 
QuestionWhy not display the image in the PICTUREBOX Pin
yu-jian5-Sep-12 21:05
yu-jian5-Sep-12 21:05 
AnswerRe: Why not display the image in the PICTUREBOX Pin
Richard MacCutchan5-Sep-12 23:17
mveRichard MacCutchan5-Sep-12 23:17 
GeneralRe: Why not display the image in the PICTUREBOX Pin
yu-jian6-Sep-12 5:18
yu-jian6-Sep-12 5:18 
GeneralRe: Why not display the image in the PICTUREBOX Pin
Richard MacCutchan6-Sep-12 5:59
mveRichard MacCutchan6-Sep-12 5:59 
GeneralRe: Why not display the image in the PICTUREBOX Pin
yu-jian6-Sep-12 15:18
yu-jian6-Sep-12 15:18 
AnswerRe: Why not display the image in the PICTUREBOX Pin
Alan Balkany6-Sep-12 5:04
Alan Balkany6-Sep-12 5:04 
GeneralRe: Why not display the image in the PICTUREBOX Pin
yu-jian6-Sep-12 5:22
yu-jian6-Sep-12 5:22 
QuestionDisable smooth scrolling for CRichEditCtrl Pin
Gernot Frisch4-Sep-12 22:41
Gernot Frisch4-Sep-12 22:41 
QuestionRe: Disable smooth scrolling for CRichEditCtrl Pin
Richard MacCutchan4-Sep-12 23:53
mveRichard MacCutchan4-Sep-12 23:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.