Howdy, Stranger!

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

Categories

How do I put an icon on a Single Document screen??

grahamojgrahamoj Member Posts: 366
How do I put an icon on a Single Document screen and then be able to click on the icon to call my dialog??

Thanks,
grahamoj.

Comments

  • grahamojgrahamoj Member Posts: 366
    : How do I put an icon on a Single Document screen and then be able to click on the icon to call my dialog??
    :
    : Thanks,
    : grahamoj.
    :
    Does anyone have any ideas on this??

    Thanks,
    grahamoj.
  • Anita GundalaAnita Gundala Member Posts: 20
    If the base class of your single document application is "CVIEW" then,
    the easy way to do that is:
    add a new tool to the existing tool bar(in resources). Go to the properties of tool by double clicking on that tool, change the ID of tool to your desired name. Add a "command" function for that tool from class wizard.
    In that function write the following, to show your dialog when you click on the tool you just added:
    YourDlg dlg1
    dlg1.DoModal();

    If the base class of your single document application is "CFormView" then you add a command on window then load bitmap or icon on to that button. Let me know if you need the code for loading bitmap or icon on to a button.
    Write the following in onClick function of button:
    YourDlg dlg1;
    dlg1.DoModal();

    Anita.

  • grahamojgrahamoj Member Posts: 366
    : If the base class of your single document application is "CVIEW" then,
    : the easy way to do that is:
    : add a new tool to the existing tool bar(in resources). Go to the properties of tool by double clicking on that tool, change the ID of tool to your desired name. Add a "command" function for that tool from class wizard.
    : In that function write the following, to show your dialog when you click on the tool you just added:
    : YourDlg dlg1
    : dlg1.DoModal();
    :
    : If the base class of your single document application is "CFormView" then you add a command on window then load bitmap or icon on to that button. Let me know if you need the code for loading bitmap or icon on to a button.
    : Write the following in onClick function of button:
    : YourDlg dlg1;
    : dlg1.DoModal();
    :
    : Anita.
    :
    :
    Hiya thanks for that. I went with the CView idea. What I am trying to do is load a static button onto the client area, I have created a static button with CStatic create, but I still can't see the button on the client area??

    So could u please show me how to create a static button onto the CView ( client area ) and then load a icon onto it??

    Thanks,
    grahamoj.
  • Anita GundalaAnita Gundala Member Posts: 20
    Yes, the samething happened to me also. I wrote code to create CStatic, compiled with no errors but couldn't see the CStatic control on the screen.
    If you are interested in using a bitmap instead of an icon, then you can do the following to load a bitmap on to the client area and get LbuttonClick on that bitmap to show your dialog:

    //write the following in public section of your view header file:
    //////////////////////
    #define m_bitmap1 1

    /* bitmap's row, col, position etc */
    //It is a row number
    //You can always change these numbers to your requirement
    #define bmp_row 50 //
    #define bmp_x 100 //
    #define bmp_width 120 //width
    #define bmp_height 120 //height

    /* resource dimenstion */
    #define res_x 0//resource row number
    #define res_y 0//resource column number
    #define res_width 70//resourcce width of the connection picture
    #define res_height 40//resourcce height of the connection picture
    ////////////////////

    //Add a bitmap to your workspace resource
    //If you don't have OnDraw function already in your View cpp file, go to classwizard and add it. Then write the following code in your OnDraw function
    //Your OnDraw function should look like this:
    void CSdoc1View::OnDraw(CDC* pDC)
    {
    CSdoc1Doc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);

    ///////////////////////
    CBitmap* m_pB[2];//array of bitmaps
    pDC = GetDC();//define pDC
    CDC *pMemDC = new CDC;//allocate dynamic memory
    pMemDC ->CreateCompatibleDC(pDC);

    //Load bitmap "IDB_BITMAP1"
    m_pB[m_bitmap1] = new CBitmap;
    m_pB[m_bitmap1]->LoadBitmap(IDB_BITMAP1);

    // Draw bitmap1 picture
    pMemDC->SelectObject(m_pB[m_bitmap1]);
    pDC->StretchBlt(bmp_x,bmp_row,bmp_width,bmp_height,
    pMemDC,res_x, res_y, res_width, res_height,SRCCOPY);

    delete pMemDC; //deallocate dynamic memory
    ReleaseDC(pDC);//release DC
    //////////////////////
    }

    //Add LButtonDown(WM_LBUTTONDOWN) function from classwizard and write the following code:
    void CSdoc1View::OnLButtonDown(UINT nFlags, CPoint point)
    {
    //This is just an example. You can play with these point.x
    //and point.y values (according to the the size of your bitmap
    if( (point.x > 100 && point.x<125)
    && (point.y > 50 && point.y<125) )
    {
    YourDlg dlg1;
    dlg1.DoModal();
    }
    CView::OnLButtonDown(nFlags, point);
    }

    I will post the code if I find anything on CStatic and loading icon to CStatic in Single Document Applicaton.

    Anita.


Sign In or Register to comment.