Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Edit box properties

bogdanul2003bogdanul2003 Posts: 153Member
How can I foind out if an editbox has the readonly property when I know it's ID or it's handle?
10x

Comments

  • DB1DB1 Posts: 1,142Member
    : How can I foind out if an editbox has the readonly property when I know it's ID or it's handle?
    : 10x
    :


    Use GetStyle() and check for ES_READONLY.


    [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]

  • bogdanul2003bogdanul2003 Posts: 153Member
    [b][red]This message was edited by bogdanul2003 at 2005-12-13 14:6:32[/red][/b][hr]
    : : How can I foind out if an editbox has the readonly property when I know it's ID or it's handle?
    : : 10x
    : :
    :
    :
    : Use GetStyle() and check for ES_READONLY.
    :
    :
    : [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]
    :
    :

    How do I assign an edit box to a CEdit object if I know the edit box's ID ?I monitor the WM_COMMAND msg and when I receive EN_SETFOCUS I want to see if the edit box that send's this message is readonly and for this I have to use a CEdit.How do I make a conection between the edit box's ID and a cedit object ?
    10x


  • stoberstober Posts: 9,765Member ✭✭✭
    [b][red]This message was edited by stober at 2005-12-13 15:48:43[/red][/b][hr]
    :
    : How do I assign an edit box to a CEdit object if I know the edit box's ID ?I monitor the WM_COMMAND msg and when I receive EN_SETFOCUS I want to see if the edit box that send's this message is readonly and for this I have to use a CEdit.How do I make a conection between the edit box's ID and a cedit object ?
    : 10x
    :
    :
    :
    You could call GetDlgItem(hWnd, ID) to get HWND of edit control. Then call CWnd::FromHandle(hWnd) to get CEdit* pointer. Verify that it is really CEdit using the pointer's IsKindOf(CEdit).
    [code]
    UINT ID; // parameter from WM_COMMAND
    HWND hWnd = ::GetDlgItem(m_hWnd, ID); // m_hWnd is HWND of dialog box
    CEdit* pEdit = (CEdit*)CWnd::FromHandle(hWnd);
    if( pEdit->IsKindOf(RUNTIME_CLASS(CEdit)) )
    {
    // blabla
    }
    [/code]


  • DB1DB1 Posts: 1,142Member
    : [b][red]This message was edited by stober at 2005-12-13 15:48:43[/red][/b][hr]
    : :
    : : How do I assign an edit box to a CEdit object if I know the edit box's ID ?I monitor the WM_COMMAND msg and when I receive EN_SETFOCUS I want to see if the edit box that send's this message is readonly and for this I have to use a CEdit.How do I make a conection between the edit box's ID and a cedit object ?
    : : 10x
    : :
    : :
    : :
    : You could call GetDlgItem(hWnd, ID) to get HWND of edit control. Then call CWnd::FromHandle(hWnd) to get CEdit* pointer. Verify that it is really CEdit using the pointer's IsKindOf(CEdit).
    : [code]
    : UINT ID; // parameter from WM_COMMAND
    : HWND hWnd = ::GetDlgItem(m_hWnd, ID); // m_hWnd is HWND of dialog box
    : CEdit* pEdit = (CEdit*)CWnd::FromHandle(hWnd);
    : if( pEdit->IsKindOf(RUNTIME_CLASS(CEdit)) )
    : {
    : // blabla
    : }
    : [/code]
    :
    :
    :


    CWnd::GetDlgItem() returns a CWnd object, so you don't need FromHandle()

    CEdit* pEdit = (CEdit*)GetDlgItem(ID);


    Also, checking IsKindOf() on it does no good if you have more than one CEdit control in your dialog... I think you should be able to just check if( ID == IDC_MY_EDIT ) to find a command from a specific edit control.






    [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]

  • bogdanul2003bogdanul2003 Posts: 153Member
    [b][red]This message was edited by bogdanul2003 at 2005-12-14 4:57:14[/red][/b][hr]
    : : [b][red]This message was edited by stober at 2005-12-13 15:48:43[/red][/b][hr]
    : : :
    : : : How do I assign an edit box to a CEdit object if I know the edit box's ID ?I monitor the WM_COMMAND msg and when I receive EN_SETFOCUS I want to see if the edit box that send's this message is readonly and for this I have to use a CEdit.How do I make a conection between the edit box's ID and a cedit object ?
    : : : 10x
    : : :
    : : :
    : : :
    : : You could call GetDlgItem(hWnd, ID) to get HWND of edit control. Then call CWnd::FromHandle(hWnd) to get CEdit* pointer. Verify that it is really CEdit using the pointer's IsKindOf(CEdit).
    : : [code]
    : : UINT ID; // parameter from WM_COMMAND
    : : HWND hWnd = ::GetDlgItem(m_hWnd, ID); // m_hWnd is HWND of dialog box
    : : CEdit* pEdit = (CEdit*)CWnd::FromHandle(hWnd);
    : : if( pEdit->IsKindOf(RUNTIME_CLASS(CEdit)) )
    : : {
    : : // blabla
    : : }
    : : [/code]
    : :
    : :
    : :
    :
    :
    : CWnd::GetDlgItem() returns a CWnd object, so you don't need FromHandle()
    :
    : CEdit* pEdit = (CEdit*)GetDlgItem(ID);
    :
    :
    : Also, checking IsKindOf() on it does no good if you have more than one CEdit control in your dialog... I think you should be able to just check if( ID == IDC_MY_EDIT ) to find a command from a specific edit control.
    :
    :
    :
    :
    :
    :
    : [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]
    :
    :

    I can't check if( ID == IDC_MY_EDIT ) because I have 20 dialog boxes from whitch 10 are readonly.I need to know when the focus is received by one of the readonly editboxes.For this I monitor WM_COMMAND event but I only receive an ID of the edit box that received the focus and I have to check if it is readonly.Checking if( ID == IDC_MY_EDIT ) will not be that nice because I'll have to compare ID with 10 editboxes IDs.I think something with GetDlgItem()
    10x


  • stoberstober Posts: 9,765Member ✭✭✭
    [b][red]This message was edited by stober at 2005-12-14 5:9:6[/red][/b][hr]
    :
    : Also, checking IsKindOf() on it does no good if you have more than one CEdit control in your dialog... I think you should be able to just check if( ID == IDC_MY_EDIT ) to find a command from a specific edit control.
    :

    The idea here is to make sure the pointer is really a CEdit and not something else, such as maybe CButton, CComboBox, etc. But if there are no other type controls on the dialog, then that check is not necessary. The OP doesn't care which edit control it is, just that it is read-only. So, after getting the CEdit pointer, just get its style and check for ES_READONLY, as you originally posted.




  • bogdanul2003bogdanul2003 Posts: 153Member
    : [b][red]This message was edited by stober at 2005-12-14 5:9:6[/red][/b][hr]
    : :
    : : Also, checking IsKindOf() on it does no good if you have more than one CEdit control in your dialog... I think you should be able to just check if( ID == IDC_MY_EDIT ) to find a command from a specific edit control.
    : :
    :
    : The idea here is to make sure the pointer is really a CEdit and not something else, such as maybe CButton, CComboBox, etc. But if there are no other type controls on the dialog, then that check is not necessary. The OP doesn't care which edit control it is, just that it is read-only. So, after getting the CEdit pointer, just get its style and check for ES_READONLY, as you originally posted.
    :
    :
    :
    :
    :

    When an editbox receives focus it send's EN_SETFOCUS to the dialog box ... so when I receive WM_COMMAND I check the HIWORD(wParam) to see if the notification message is EN_SETFOCUS.Are there other controls that send this message?If not it means that there is no need to check the type of the pointer right ?
    10x
  • stoberstober Posts: 9,765Member ✭✭✭
    : : [b][red]This message was edited by stober at 2005-12-14 5:9:6[/red][/b][hr]
    : : :
    : : : Also, checking IsKindOf() on it does no good if you have more than one CEdit control in your dialog... I think you should be able to just check if( ID == IDC_MY_EDIT ) to find a command from a specific edit control.
    : : :
    : :
    : : The idea here is to make sure the pointer is really a CEdit and not something else, such as maybe CButton, CComboBox, etc. But if there are no other type controls on the dialog, then that check is not necessary. The OP doesn't care which edit control it is, just that it is read-only. So, after getting the CEdit pointer, just get its style and check for ES_READONLY, as you originally posted.
    : :
    : :
    : :
    : :
    : :
    :
    : When an editbox receives focus it send's EN_SETFOCUS to the dialog box ... so when I receive WM_COMMAND I check the HIWORD(wParam) to see if the notification message is EN_SETFOCUS.Are there other controls that send this message?If not it means that there is no need to check the type of the pointer right ?
    : 10x
    :


    I think you're right about that. But why not just enable the OnSetFocus() event handler for the edit controls -- they can all use the same function?
  • bogdanul2003bogdanul2003 Posts: 153Member
    : : : [b][red]This message was edited by stober at 2005-12-14 5:9:6[/red][/b][hr]
    : : : :
    : : : : Also, checking IsKindOf() on it does no good if you have more than one CEdit control in your dialog... I think you should be able to just check if( ID == IDC_MY_EDIT ) to find a command from a specific edit control.
    : : : :
    : : :
    : : : The idea here is to make sure the pointer is really a CEdit and not something else, such as maybe CButton, CComboBox, etc. But if there are no other type controls on the dialog, then that check is not necessary. The OP doesn't care which edit control it is, just that it is read-only. So, after getting the CEdit pointer, just get its style and check for ES_READONLY, as you originally posted.
    : : :
    : : :
    : : :
    : : :
    : : :
    : :
    : : When an editbox receives focus it send's EN_SETFOCUS to the dialog box ... so when I receive WM_COMMAND I check the HIWORD(wParam) to see if the notification message is EN_SETFOCUS.Are there other controls that send this message?If not it means that there is no need to check the type of the pointer right ?
    : : 10x
    : :
    :
    :
    : I think you're right about that. But why not just enable the OnSetFocus() event handler for the edit controls -- they can all use the same function?
    :

    I could use OnSetFocus() if it would give me an ID or handler to the window that received the focus because I need to put a text in that dialogbox when the user click's it.
Sign In or Register to comment.