Results 1 to 13 of 13

Thread: 2 Views

  1. #1

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471

    2 Views

    My application (SDI) currently has two views seperated by a splitter.
    The two views (listview and treeview) take up the height of
    the frame minus the height of the menu and status
    bar of course. I would like to insert another view above both the
    listview and treeview that extends the width of the frame.
    This can also be done easily.....my question is, how do i create this view so i can place objects on such as checkboxes,
    edit boxes, etc......

    Another words, the regular gray background of a frame window
    that i can place objects on above the listview and treeview.

    Thanks for any help
    Bababooey
    Tatatoothy
    Mamamonkey

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Why not rather create a toolbar with the controls you want? It's far less work.

    To create the view you'd need a second splitter. The upper pane of this splitter contains your view, the lower contains the splitter that contains the other two views.
    Code:
    Code:
    // Assuming the frame wnd class has two CSplitterWnd members.
    // m_wndSplitVert and m_wndSplitHorz
    BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT pCS, CCreateContext* pContext)
    {
      if(!m_wndSplitHorz.CreateStatic(this, 2, 1) ||
        !m_wndSplitHorz.CreateView(0,0, RUNTIME_CLASS(CToolView),
          CSize(0,80), pContext) ||
        !m_wndSplitVert.CreateStatic(&m_wndSplitHorz, 1, 2,
          WS_CHILD | WS_VISIBLE, m_wndSplitHorz.IdFromRowCol(1,0)) ||
        !m_wndSplitVert.CreateView(0,0,RUNTIME_CLASS(CYourTreeView),
          CSize(128,0), pContext) ||
        !m_wndSplitVert.CreateView(0,1,RUNTIME_CLASS(CYourListView),
          CSize(0,0), pContext))
        return FALSE;
      return TRUE;
    }
    But a view is not a good place for a control. Better to create a toolbar with a lot of seperators (you have to edit the resource script manually for this) which you later replace with real controls. This way you can get controls inside a toolbar. I can give you code for this too.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471
    thx, before i didn't have access to vs6 but now i do so I'm
    probably gonna use a toolbar like you suggested.

    thx ;P
    Bababooey
    Tatatoothy
    Mamamonkey

  4. #4

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471
    CornedBee, can you show me or direct me someplace that
    explains adding the controls to a toolbar? I found a couple of
    different resources that touch on this subject but do not
    explain it well.

    Thanks
    Bababooey
    Tatatoothy
    Mamamonkey

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Ok.
    You need to edit the resource script directly, so load it into an external text editor. Search for your toolbar template and add a SEPERATOR everywhere you want a control (the items are ordered from left to right). Then you need to derive a class from CToolBar. Let's call it CAdvToolBar. Add one member variable for each control you want of the appropriate type (CEditBox, CComboBox, ...). Then add an OnCreate handler (handle the WM_CREATE message) and add code like this:
    Code:
    int CAdvToolbar::OnCreate(LPCREATESTRUCT lpCS)
    {
      if(CToolBar::OnCreate(lpCS) == -1)
        return -1;
      // do this for every control:
      SetButtonInfo(index, id, TBBS_SEPERATOR, width);
      CRect rect;
      GetItemRect(index, &rect);
      rect.bottom = rect.top + height;
      m_wndSomeControl.Create(WS_CHILD | WS_VISIBLE | styles,
        rect, this, id);
    
      return 0;
    }
    index is the zero-based index of the seperator you want to replace in the toolbar template. You must count it yourself and keep track of changes. Sorry, there is no easy way to do that.
    id is the control id you want the control to have. This is the id you can later use to handle messages from this control (in the frame window).
    width and height are the dimensions of the control.
    style is the style you want the control to have (window styles like borders, control-specific styles (e.g. ES_PASSWORD))

    You can also add tooltips and status messages to the control: just define a string resource with the same id as the control. It needs to have the usual format:
    Status message\nTooltip message

    BTW to replace OnUpdate* functions (you can't use them for non-button controls) override OnUpdateCmdUI and do it manually.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471
    MFC only lets me derive a class from CToolBarCtl yuck.

    do i have to derive a non-MFC class and name the base class
    CToolBar?
    Bababooey
    Tatatoothy
    Mamamonkey

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Probably. This means you can't use the wizard to add message handlers and virtual functions, but I fear there's no other way (the wizard is by no means perfect).
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471
    sigh, i can't get this to work

    SetButtonInfo requires an image where you specified a width

    my id is "unidentified" so i added it to the string table (will
    that work?)

    then i get assertion errors about the button (on the toolbar)
    not actually being a button

    do you have specific code that you can possibly send that
    shows exactly what you did or am i missing something?
    Bababooey
    Tatatoothy
    Mamamonkey

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    For separators, which have the style TBBS_SEPARATOR, this function sets the separator's width in pixels to the value stored in iImage.
    That seems ok to me. Maybe post your project? Or is it private?

    By adding it to the string table, VC++ should add the define to resource.h, so that should be ok (otherwise you'd have to add that define yourself)

    Which button? It isn't a button, it's a separator.

    I did that once and it worked, but I later realized I don't need it and deleted it again, so I don't have it now, sorry.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  10. #10

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471
    when i run it, i get an error with an assertion on the VERIFY
    line:


    Code:
    void CToolBar::_GetButton(int nIndex, TBBUTTON* pButton) const
    {
         CToolBar* pBar = (CToolBar*)this;
         VERIFY(pBar->DefWindowProc(TB_GETBUTTON, nIndex, (LPARAM)pButton));
         // TB_STATE_ENABLED == TBBS_DISABLED so inver it
         pButton->fsState ^= TBSTATE_ENABLED;
    }
    this is in the bartool.cpp file included in MFC, this is not my file
    obviously
    Bababooey
    Tatatoothy
    Mamamonkey

  11. #11

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471
    here's the zipped up project if you need it

    it's just a short test project to see if it works, so nothing is
    private :P

    thx for any help
    Bababooey
    Tatatoothy
    Mamamonkey

  12. #12

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471
    hmmmm, i added it, ,wonder why it didnt show up,

    try again?
    Bababooey
    Tatatoothy
    Mamamonkey

  13. #13

    Thread Starter
    Hyperactive Member noble's Avatar
    Join Date
    Nov 2000
    Location
    Philly
    Posts
    471
    ok well it looks as though it didnt work again

    if you would like to see the short code,
    PM me and i can possibly email or transfer it to you using
    some other medium

    thx
    Bababooey
    Tatatoothy
    Mamamonkey

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width