CEdit cursor

I know I've seen the code for this somewhere.  I have a class derived from CEdit and I want to eliminate the I-Beam cursor.  Do I use OnNCHitTest?
LVL 1
sosedadaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pagladasuCommented:
Try the following code in the PreTranslateMessage() function of the view or dialog.
if(pMsg->hwnd==(GetDlgItem(IDC_EDIT1))->GetSafeHwnd())
  GetDlgItem(IDC_EDIT1)->HideCaret();

thanks,
pagladasu
0
sosedadaAuthor Commented:
Didn't work.  Sorry.
0
sosedadaAuthor Commented:
Silly me, I didn't even look at the definition of HideCarat.   I'm not talking about the cursor in the edit box, I mean the mouse cursor.
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

JPMartineauCommented:
Yes - You must call SetCursor() in the WM_NCHITTEST handler. If you want to know when the cursor exits the CEdit, you can also use SetCapture() (This is especially useful in some cases of cursor management...)

Good Luck

JPM
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SteveGTRCommented:
This is pretty easy and it work -- process the WM_SETCURSOR message and return FALSE:

BOOL CMyWindow::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
  return FALSE;
}

Good Luck,
Steve
0
sosedadaAuthor Commented:
Normally, I will be setting back to IDC_ARROW, but what if the cursor is currently an hour glass and the user passes through the edit box?  How can I detect the cursor state before they entered the box so that I can maintain it?
0
sosedadaAuthor Commented:
I'm thinking your answer may be better Steve, I'll try it out.  If so I'll give you some points.
0
SteveGTRCommented:
Not necessary --- I just hope it helps you out.
0
JPMartineauCommented:
SetCursor returns a HCURSOR (the old one), so if you store it, you can set it later.

Steve's answer is more straightforward though.
0
JPMartineauCommented:
SetCursor returns a HCURSOR (the old one), so if you store it, you can set it later.

Steve's answer is more straightforward though.
0
sosedadaAuthor Commented:
Steve's answer appears not to work. I believe that this is because the cursor type is part of the CEdit's registered class type. ... And my build just finished and JPM's didn't work either!  You'd think I would know better than to accept an answer before I tried it :)  Do I need to call SetCursor after the base call to OnNCHitTest?
0
sosedadaAuthor Commented:
I'm not even getting to the breakpoint in OnNCHitTest for my class.  This is in a formview, do I have to handle it there?
0
SteveGTRCommented:
No problem doing this in a CFormView -- I just tried it out. Firstly, you said in your original message that you have a CEdit class that you want to put this functionality in. Is this class properly subclassed to the control on your CFormView? I do this by going into the class wizard, selecting my CFormView, press the member variables tab, highlighting the control I want to add this functionality to, press add variable, enter name, select category control, and select variable type of my CEdit class.
0
sosedadaAuthor Commented:
I did put the CMyEdit into the CFormView in the manner you describe.  However, I didn't do anything special about subclassing it, just derived from CEdit.  All of my handling of messages like button click works fine.  I put in OnSetCursor, returning false, but it was never called, hence my thought about the registered wnd class.  I don't need to call SubclassDlgItem, right?
0
SteveGTRCommented:
Sounds like you hooked up the CFormView and the Edit control correctly.

Did you install OnSetCursor using the class wizard? You should have ON_WM_SETCURSOR() in your Edit control's message map.
0
sosedadaAuthor Commented:
DOH!!! I broke the class wizard for this class by DDX-ing the CString for this edit control to a string in another class.  Dang nab it!!!  Thanks alot for your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.