|
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!"
|
|
|
|
|
I had set a image to the picture. At a simple project, this way is OK. I guess it need to draw the image in OnPaint function.
|
|
|
|
|
Hi,
on win7, if you open Notepad and write.exe and paste a long text, the notepad will scroll quickly with the mouse wheel.
The RichEdit control in the write.exe, however, uses some sort of "smooth scrolling", which is totally disturbing.
In my program, I want to make the CRichEditCtrl as snappy a CEditCtrl. Any ideas?
Many thanks,
-Gernot
|
|
|
|
|
Does this behaviour happen also in your code or is it specific to write.exe?
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I'd say it happens in any CRichEditCtrl you make unless you find a way to disable it. Yes, my program suffers from this behaviour.
|
|
|
|
|
I would guess then, that it is a feature of the control so unless there is a method in the class to disable it then you are stuck with it. You could try subclassing[^] the control to see if there is a way to improve it.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|