• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 420
  • Last Modified:

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?
0
sosedada
Asked:
sosedada
  • 8
  • 4
  • 3
  • +1
1 Solution
 
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
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
 
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

  • 8
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now