|
Hi Chris,
Thanx for your reply.
I am facing one issue. In my application, I have one edit control and one static box control. While user types some text in edit box, I am displaying the same text character by character in the static box control. But after adding the code for making static box control movable, when I run the application, its not displaying the text in static control. If I remove the code for moving static control, it works fine.
Actually what I want is that after user types the text in the edit box, at the same time text will be entered in the static control also. User should be able to move the static box with the text.
Can you help me with this issue if you have any idea that either the text entered in the static box or edit box, user should be able to drag/move that contorl along with the text.
If u have any sample code for this, will be helpful.
Thanx in advance.
Regards,
Mbatra
|
|
|
|
|
i can't think of any reason why code to move a control via mouse would affect the text it displays...
1) does the text display work until you move the control, or does it not work even if you don't move it?
2) what are you using to update the text in the static control?
|
|
|
|
|
Hi Chris,
I am using OnChange event notificaTION OF Edit control. In that I am updating the text simultaneously in static control as user types in. If I don't use the moving code, I can see text being updated in static control. If I am using the code to move the static control, when I run the application, I can't see the text being updated in the static control as user types in. Given below is the sample code which I am using to update the text in the static control.
<br />
void ChageTextDyn::OnChangeInputtext()<br />
{<br />
<br />
CString inText;<br />
m_InputEditText.GetWindowTextW(inText);<br />
m_OutputStaticText.SetWindowTextW(inText);<br />
}<br />
Regards,
Mbatra
|
|
|
|
|
what does your OnMouseMove code look like?
|
|
|
|
|
Hi Chris,
Given below is the code I am using for moving the static control.
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;
m_OutputStaticText.GetWindowRect(&rc);
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);
}
CDialogEx::OnMouseMove(nFlags, point);
}
Regards,
Mbatra
|
|
|
|
|
that all looks reasonable.
are you initializing m_bButtonDown to false somewhere ?
|
|
|
|
|
Hi Chris,
No, Except in OnLButtonUp, Nowhere I am initializing m_bButtonDown to false;
I don't If I comment out OnLButtonDown, OnLButtonUp, OnMouseMove code, it works fine, text will be entered in static text box.
But if I uncomment the code for these three handlers, It will not even display the text being updated in the static control as user types in the edit control.
Regards,
Mbatra
|
|
|
|
|
Hi Chris,
Below is the complete code in the file.
// 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)
{
}
ChageTextDyn::~ChageTextDyn()
{
}
void ChageTextDyn::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_INPUTTEXT, m_InputEditText);
DDX_Control(pDX, IDC_OUTPUTTEXT, m_OutputStaticText);
}
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);
}
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;
m_OutputStaticText.GetWindowRect(&rc);
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);
}
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
}
Regards,
Mbatra
|
|
|
|
|
1. you should initialize m_bButtonDown to false, in the ChageTextDyn constructor
2. what happens if you just comment-out the MoveWindow call?
|
|
|
|
|
Hi Chris,
If I comment out the Move window call, it will display the text, but will not move the static box.
I got the idea, what was happening was, if I don't move the mouse on when dialog box pops up, and only use the keyboard controls, it will display the text being updated in the static box, but as soon as I'ii move the mouse on the static text box, static text got disappear.
I think it may be that the position I am getting in the on mouse move is away from the dialog boundary.
Please let me know if I am correct or not.?
Regards,
Mbatra
|
|
|
|
|
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
|
|
|
|
|
|
Hi Chris,
One issue. Now I am able to move the static text control. mouse co-ordinates differs. I want to move the static control by clicking the mouse on the control. But now when I click the mouse away from the control, control starts moving. I want user should be able to drag it by holding the static control.
Please let me know how to check if user has clicked on the control and drags the control.
Regards,
Mbatra
|
|
|
|
|
in your OnLButtonDown, you can check to see if the click happens inside the static control. get the window rect, then see if 'point' is inside the rect.
also, you might want to make a class that's derived from CStatic, and put the button/mouse code in there. so, the control will be responsible for moving itself, and not the dialog.
|
|
|
|
|
Hi Chris,
Thanx for the reply.
I did the same way, I have checked in the OnMouseMove. Getting window rect, then checking to if point is in rect.
But even if I use in OnLButtonDown, still I am not able to move the control by clicking the mouse on it. I have used the below code.
<br />
CRect rct;<br />
m_edtext.GetWindowRect(&rct);<br />
if(rct.PtInRect(point))<br />
MessageBox(_T("Yes"));<br />
Please give me a sample code what u have explained earlier: (you might want to make a class that's derived from CStatic, and put the button/mouse code in there. so, the control will be responsible for moving itself, and not the dialog.
).
Will be helpful for me.
Regards,
Mbatra
|
|
|
|
|
mbatra31 wrote: But even if I use in OnLButtonDown, still I am not able to move the control by clicking the mouse on it.
you can move the control if you click outside of it, but not directly on it?
|
|
|
|
|
Hi Chris,
I have one requirement. I want to draw text on an image. I have seen one software, in that on clicking a button, it will display a text field box, where user types the text, that text will be parallely drawn on the image. And also user can move that box in whcih text is being drawn.
I want to do the same in MFC dialog based app. I was able to move the static/edit box, but I want the user should be able to move the control by holding the mouse on it.
Any idea about this. I will be thankful for your reply.
Regards,
mbatra
|
|
|
|
|
and what are you able to do right now?
|
|
|
|
|
Hi Chris,
I was able to move the control, but when I click away from the control, not by clicking on the control and holding the mouse and then drag the control. Actually I want to drag the control by holding the mouse on it.
Regards,
Mbatra
|
|
|
|
|
I use the PictureBOX control to display *.png image, but there is blank when the form startup, I cannot see the picturebox control. I use the spy++ to move over the PictureBox control place, there indeedly is a Picturebox control. Does it need to write code in the OnPaint function of this Dialog?
Could someone can give me a example? Thank you very very much.
|
|
|
|
|
This looks like a Managed C++ issue, you may be better posting in the Managed C++ forum[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
No managed c++,
It's a MFC problem.
|
|
|
|
|
Strange, I cannot find a reference to the PictureBox class in MFC. Do you have a link to it?
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Hi Richard MacCutchan,
Sorry, I found that I print a wrong name. Its name should be Picture Cotnrol (IPictEditor).
I use a CStatic variable to binding this control.
|
|
|
|
|
The PictureBox will be invisible until you set its Image member to an Image/Bitmap. You could also write an OnPaint method for the PictureBox; either approach would work.
"Microsoft -- Adding unnecessary complexity to your work since 1987!"
|
|
|
|
|