15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


3D look edit box in tool bar

Dong Chen -- d_chen@ix.netcom.com
Wednesday, January 15, 1997


Environment: VC++ 4.2b, Win95, WinNT 4.0

I have a MDI application where I have a tool bar using the CToolBar derived
class. I am trying to put several buttons and an edit box on it. Everything
works except that I can't get the 3D look of the edit box. If I replace the
edit box with a combo box, the 3D look is there. Although I can make the
height of combo box to only one row to simulate the edit box, I don't think
this is the right way to it. Besides, I like to set the edit box as
read-only somethimes.
Here is my code segment.

class CMainToolBar : public CToolBar
{
     //......
    CEdit   m_editSelected;
    afx_msg int OnCreate (LPCREATESTRUCT);
    DECLARE_MESSAGE_MAP ()
}

int CMainToolBar::OnCreate (LPCREATESTRUCT lpcs)
{
    //......
    if (CToolBar::OnCreate (lpcs) == -1)
        return -1;
    //......
    if( !LoadBitmap(IDB_MAINBTNS) )
        return -1;
    // nMainButtons is an array holds the IDs, in position 13 is a ID_SEPARATOR
    SetButtons(nMainButtons, sizeof(nMainButtons)/sizeof(UINT));
    //...
    // cxChar is the average width determined for a single character
    CRect rect;
    SetButtonInfo(13, IDC_EDIT_SELECTED, TBBS_SEPARATOR, cxChar*15);
    GetItemRect (13, &rect);

    if (!m_editSelected.Create (WS_CHILD | WS_VISIBLE | WS_BORDER, 
                rect, this, IDC_EDIT_SELECTED));
}

class CMainFrame : public CMDIFrameWnd
{
    //......
   CMainToolBar	m_wndMainToolBar;
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
  if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
	return -1;
  //......
  // create the mainframe toolbar
  if (!m_wndMainToolBar.Create (this, WS_CHILD | WS_VISIBLE | CBRS_TOP |
        CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC))
        return -1;
}

Thanks.
--
Dong
d_chen@ix.netcom.com




Greg D. Tighe -- gdt@eng.aisinc.com
Friday, January 17, 1997

[Mini-digest: 4 responses]

> 
> Environment: VC++ 4.2b, Win95, WinNT 4.0
> 
> I have a MDI application where I have a tool bar using the CToolBar derived
> class. I am trying to put several buttons and an edit box on it. Everything
> works except that I can't get the 3D look of the edit box
-----From: "Virendra, Prasad" 


In CMainToolBar, add message map OnCtlColor() for WM_CTLCOLOR.
Inside OnCtlColor, Draw a 3D frame for edit controls.

HBRUSH CMainToolBar::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
 HBRUSH hbr = CToolBar::OnCtlColor(pDC, pWnd, nCtlColor);
 
 // TODO: Change any attributes of the DC here
 if (nCtlColor==CTLCOLOR_EDIT)
 {
     CRect rect;
     pWnd.GetWindowRect(&rect);
     ScreenClient(&Rect);
     rect.InflateRect(1,1);   
     DrawFrame3D(&rect);
 }
 
 // TODO: Return a different brush if the default is not desired
 return hbr;
}

void CMainToolbar::DrawFrame3D(const CRect *pRect)
{
 CDC *pDC=GetDC();
 pDC->PatBlt(pRect->left,pRect->top,pRect->right-pRect->left,1,BLACKNESS);  

 pDC->PatBlt(pRect->left,pRect->top,1,pRect->bottom-pRect->top,BLACKNESS);  

 pDC->PatBlt(pRect->left,pRect->bottom,pRect->right-pRect->left,1,WHITENES  
S);
 pDC->PatBlt(pRect->right,pRect->top,1,pRect->bottom-pRect->top,WHITENESS)  
;
 ReleaseDC(pDC);
}

 --Viren

___    _______
 __ |  / /___(_)_____________ _______
 __ | / / __  / __  ___/_  _ \__  __ \
 __ |/ /  _  /  _  /    /  __/_  / / /
 _____/   /_/   /_/     \___/ /_/ /_/

Virendra Prasad
GE Fanuc Automation North America, Inc.
1 Columbia Circle,
Albany, New York-12203-5189.
Phone: (518) 464-4573/ 8*687-4573
Fax: (518) 464-4613 / 8*687-4613



 ----------
From:  owner-mfc-l[SMTP:owner-mfc-l@majordomo.netcom.com]
Sent:  Wednesday, January 15, 1997 7:45 PM
To:  mfc-l
Subject:  3D look edit box in tool bar


Environment: VC++ 4.2b, Win95, WinNT 4.0

I have a MDI application where I have a tool bar using the CToolBar   
derived
class. I am trying to put several buttons and an edit box on it.   
Everything
works except that I can't get the 3D look of the edit box. If I replace   
the
edit box with a combo box, the 3D look is there. Although I can make the
height of combo box to only one row to simulate the edit box, I don't   
think
this is the right way to it. Besides, I like to set the edit box as
read-only somethimes.
Here is my code segment.

class CMainToolBar : public CToolBar
{
     //......
    CEdit   m_editSelected;
    afx_msg int OnCreate (LPCREATESTRUCT);
    DECLARE_MESSAGE_MAP ()
}

int CMainToolBar::OnCreate (LPCREATESTRUCT lpcs)
{
    //......
    if (CToolBar::OnCreate (lpcs) == -1)
        return -1;
    //......
    if( !LoadBitmap(IDB_MAINBTNS) )
        return -1;
    // nMainButtons is an array holds the IDs, in position 13 is a
ID_SEPARATOR
    SetButtons(nMainButtons, sizeof(nMainButtons)/sizeof(UINT));
    //...
    // cxChar is the average width determined for a single character
    CRect rect;
    SetButtonInfo(13, IDC_EDIT_SELECTED, TBBS_SEPARATOR, cxChar*15);
    GetItemRect (13, &rect);

    if (!m_editSelected.Create (WS_CHILD | WS_VISIBLE | WS_BORDER,
                rect, this, IDC_EDIT_SELECTED));
}

class CMainFrame : public CMDIFrameWnd
{
    //......
   CMainToolBar m_wndMainToolBar;
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
  if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
        return -1;
  //......
  // create the mainframe toolbar
  if (!m_wndMainToolBar.Create (this, WS_CHILD | WS_VISIBLE | CBRS_TOP |
        CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC))
        return -1;
}

Thanks.
 --
Dong
d_chen@ix.netcom.com


-----From: Rob Mensching 

At 07:45 PM 1/15/97 -0600, you wrote:
>Environment: VC++ 4.2b, Win95, WinNT 4.0
>
>I have a MDI application where I have a tool bar using the CToolBar derived
>class. I am trying to put several buttons and an edit box on it. Everything
>works except that I can't get the 3D look of the edit box. If I replace the
--< snip >---

>Here is my code segment.
--< snip >---

>int CMainToolBar::OnCreate (LPCREATESTRUCT lpcs)
>{
>    //......
>    if (CToolBar::OnCreate (lpcs) == -1)
>        return -1;
>    //......
>    if( !LoadBitmap(IDB_MAINBTNS) )
>        return -1;
>    // nMainButtons is an array holds the IDs, in position 13 is a ID_SEPARATOR
>    SetButtons(nMainButtons, sizeof(nMainButtons)/sizeof(UINT));
>    //...
>    // cxChar is the average width determined for a single character
>    CRect rect;
>    SetButtonInfo(13, IDC_EDIT_SELECTED, TBBS_SEPARATOR, cxChar*15);
>    GetItemRect (13, &rect);
>
>    if (!m_editSelected.Create (WS_CHILD | WS_VISIBLE | WS_BORDER, 
>                rect, this, IDC_EDIT_SELECTED));

...Right here is your problem.  To create a 3D-CEdit control you have to use
.CreateEx() with the WS_EX_CLIENTEDGE (I believe that's the flag).  Look up
.CreateEx() in the on-line help to be sure about the syntax.

...Also, Microsoft's Knowledge Base online has an article that shows you
EXACTLY what you want.  You can do a search for "3D" and come up with it I
believe.

l8r,
        Rob Mensching
      .- - - - - - - - - - - - - - - - - - - - - -.
 .- -' _/_/_/_/_/  _/_/_/    _/_/_/_/  _/_/_/_/_/  ` - - - - - - - -.
|         _/     _/     _/  _/            _/      _/_/_/_/  _/   _/  |
|        _/     _/         _/_/_/        _/      _/        _/  _/    |
|       _/     _/         _/            _/      _/_/_/    _/_/       |
|      _/     _/     _/  _/            _/      _/        _/  _/      |
| _/_/_/_/_/  _/_/_/    _/_/_/_/      _/      _/_/_/_/  _/    _/     |
`- -. _ .- - - - - - - - - - - - -._.- - - - -. E n t e r p r i s e .'
      | Rob "IceMan" Mensching     `.ICETek R&D`- - - - - -. _ .- -'
      | iceman@umr.edu              `. Suite 569, TJ Hall   |
      `. Computer Science Undergrad    `.  Rolla, MO  65401  |
        `. University of Missouri - Rolla`.   (573) 341-9589 |
          `- - - - - - - - - - - - - - - -'`- - - - - - - - -'

-----From: Roger Onslow/Newcastle/Computer Systems Australia/AU

>I have a MDI application where I have a tool bar using the CToolBar derived
>class. I am trying to put several buttons and an edit box on it. Everything
>works except that I can't get the 3D look of the edit box. If I replace the
>edit box with a combo box, the 3D look is there. Although I can make the
>height of combo box to only one row to simulate the edit box, I don't think
>this is the right way to it. Besides, I like to set the edit box as
>read-only somethimes.
[snip]

I had a similar requirement - however, I decided on a combo box instead (not 
because of 3D) because it allowed me to keep a history of last-n entries so the 
user could pick a recently used entry and do it agin without re-typing.  Of 
course ,you can always disable the Combo box so the user cannot eter into it 
(similar to making edit box read-only).  I thikn you may find that this sort of 
interface works as well as if not better than just a bare entry box.  It is 
faily easy to have a Combo box which automatically maintains a history buffer 
(removing duplicates if you like, or maybe sorting alphabetically or by MRU)

Hope this helps

============================================================
   Roger Onslow
 Software Development Manager - Quisine Division
  Computer Systems Australia
------------------------------------------------------------
Ph:   +61 49 675266
Fax:   +61 49 675554
Personal  mailto:Roger_Onslow@compsys.com.au
Quisine info mailto:Quisine@compsys.com.au
Visit us at  http://www.compsys.com.au/Quisine.html
============================================================
  Quisine - Designing for the Future
============================================================



Dulepov Dmitry -- dima@ssm6000.samsung.ru
Monday, January 20, 1997

[Mini-digest: 2 responses]

        [Mailer: "Groupware E-Mail". Version 1.02.055]

>        [From: Dong Chen
>
>I have a MDI application where I have a tool bar using the CToolBar derived
>class. I am trying to put several buttons and an edit box on it. Everything
>works except that I can't get the 3D look of the edit box. If I replace the
>edit box with a combo box, the 3D look is there. Although I can make the
>height of combo box to only one row to simulate the edit box, I don't think
>this is the right way to it. Besides, I like to set the edit box as
>read-only somethimes.
>
>Here is my code segment.
>

Use WS_EX_CLIENTEDGE window style in your code. Replace

>    if (!m_editSelected.Create (WS_CHILD | WS_VISIBLE | WS_BORDER, 
>                rect, this, IDC_EDIT_SELECTED));

with

    if (!m_editSelected.Create (WS_CHILD | WS_VISIBLE | WS_BORDER | WS_EX_CLIENTEDGE, 
                rect, this, IDC_EDIT_SELECTED));


Dmitry A. Dulepov
Samsung Electronics Co., Ltd.
Russian Research Center
Phone: +7 (095) 213-9207
Fax: +7 (095) 213-9196
E-mail: dima@src.samsung.ru
====================================

-----From: PRosen 

>    if (!m_editSelected.Create (WS_CHILD | WS_VISIBLE | WS_BORDER,
>                rect, this, IDC_EDIT_SELECTED));
	
I had a similiar problem which I fixed with the following:

if (!m_editSelected.CreateEx(WS_EX_OVERLAPPEDWINDOW, _T("EDIT"), NULL,
		WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL, rect.left, rect.top,
		rect.Width(), rect.Height(), GetSafeHwnd(), HMENU(IDC_EDIT_SELECTED)))










| Вернуться в корень Архива |