locked
hiding and showing an icon RRS feed

  • Question

  • Hi,

     

    In my application I have two edit boxes for Password and confirm Password on a dialog box. I will do Password strength validation On kill focus of Password edit box. Similarly, I will do verify identical passwords on Confirm password edit box.

    Now, as soon as i validate the password, I want show "Success" or "Failure" icon onkillfocus inside the dialog box itself.

    Is it possible? If its possible, I would like to know how can i do it?

     

    thx,

    pc


    Prabakaran
    Monday, June 27, 2011 5:58 AM

All replies

  • The easiest would be:

    1. Place a picture control in resource view to your dialog.
    2. Create a variable to get access to the picture control (i.e. name ist m_IConStatic_ics)
    3. Insert the icons you need to the resources (i.e. IDI_OKICON, IDI_ERRORICON)
    4. Insert a member variable to your dialog class with a HICON as type:

    HICON m_StatusIcon_h;

    5. Load and show the icon:

    // I use LoadImage instead of LoadIcon, since LoadImage is able to load specific sized icons, in my case 16x16 icons
    m_StatusIcon_h=(HICON)::LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_OKICON), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
    m_IconStatic_ics.SetIcon(m_StatusIcon_h);

    6. If you want to change a icon you can do something like that:

    DestroyIcon(m_StatusIcon_h);
    // m_OkStatus_b is a variable of type bool
    if (m_OkStatus_b==true)
    {
     m_StatusIcon_h=(HICON)::LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_OKICON), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
    }
    else
    {
     m_StatusIcon_h=(HICON)::LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ERRORICON), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
    }
     
    m_IconStatic_ics.SetIcon(m_StatusIcon_h);

     

    Monday, June 27, 2011 7:05 AM
  • You could use CStatic::SetIcon() when success.


    Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.
    Tuesday, June 28, 2011 1:08 AM
  • I tried the following:

    In my application, I have a resource bitmap with id IBD_SUCCESS defined in resource.h

    I created a picture contol on My dialog with type as "bitmap" and pointing to no image.

    I created a member variable CStatic::picture_ and filling the variable at

    DDX_CONTROL(pDX, IDC_STATIC, picture_);

    Then I need to show the picture at OnKillFocus().

    So, inside the killfocus handler,

    m_StatusIcon_h=(HICON)::LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_success), IMAGE_BITMAP, 16, 16, LR_DEFAULTCOLOR);

    picture_.setIcon(m_statusIcon_h);

    But still I am not able to visualize the icon. Its empty only.

     

    Pls let me know how could i do it? Is it possible to show and hide icons at runtime.?

     

    thx,


    Prabakaran
    Tuesday, June 28, 2011 7:10 AM
  • Does your static control has the style SS_ICON set? If you inserted a static control in your dialog resource that the icon will not be displayed (ther SS_ICON style is missing). If you add a picture control (that is also a static control) the style SS_ICON is set if you select as Type - Icon.

    Oh I also see, you must rename your static control. The ID IDC_STATIC is used for all static controls. You can not do any changed on controls with the ID IC_STATIC. Please rename it to i.e. IDC_STATUSICON_STATIC.


    Edit:

    If you would like to use bitmaps that you must select as Type - Bitmap and the style SS_BITMAP should be set as additional style.

    You are talking about bitmaps. You should be sure what you are doing. If the resource IDB_success is a bitmap you should not cast it to a HICON! You should use a HBITMAP and tha use CStatic::SetBitmap().

    Tuesday, June 28, 2011 9:35 AM