请问VC怎么做复合控件,网上基本上没有这方面的资料
解决方案 »
- 如何在windows平台下实现高效绘图、动画效果?
- C++怎么让DialogBar上的按钮灰显啊
- 向各位大哥请教几个入门级(应该是还没有入门)的问题,谢谢!
- 问个简单问题,谢谢帮助!
- 不知道为什么信誉分这么低?
- BUTTON_WIDTH,BUTTON_HEIGHT
- 登录对话框Login的问题
- 高手都去哪儿了?贴了5次,去了500分,但没人答????关于串口
- 我用VB,觉得她实在不怎的,想向转 高手给个建议是C++ BUIDLER 还是MSVC++????
- 如何加一个CStatic 到菜单行(不是菜单条)的右边,类似Internet Explorer右上角的那个动画控件,但MS使用的是菜单条?
- 关于屏幕刷新的问题~?
- 如何将隐藏的窗口上的图像显示出来
//#include "stdafx.h"
#include "CPic.h"
#include "MySearchBox.h"#define IDC_EDIT 1
#define IDC_BTN 2
// CMySearchBoxIMPLEMENT_DYNAMIC(CMySearchBox, CWnd)CMySearchBox::CMySearchBox()
{}CMySearchBox::~CMySearchBox()
{
}
BEGIN_MESSAGE_MAP(CMySearchBox, CWnd)
ON_WM_CREATE()
ON_WM_SIZE()
ON_BN_CLICKED(IDC_BTN, OnButtonClick)
ON_WM_NCPAINT()
END_MESSAGE_MAP()// CMySearchBox 消息处理程序
int CMySearchBox::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
m_pEdit.Create(WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL, CRect(0, 0, 0, 0),this, IDC_EDIT);
m_pBtn.Create(_T("S"),WS_CHILD | WS_VISIBLE, CRect(0, 0, 0, 0),this, IDC_BTN);
//设置字体
HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
CFont* pFont = CFont::FromHandle(hFont);
m_pEdit.SetFont(pFont);
m_pBtn.SetFont(pFont);
LOGFONT lf;
pFont->GetLogFont(&lf);
return 0;
}
void CMySearchBox::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize(nType, cx, cy);
//调整两控件大小
int nBtnWidth = 30;
m_pEdit.MoveWindow(5,(cy-12)/2,cx-nBtnWidth-10,12);
m_pBtn.MoveWindow(cx - nBtnWidth, 1, nBtnWidth, cy - 2);
}
void CMySearchBox::OnNcPaint()
{
CPaintDC dc(this);
CRect rcWnd;
GetWindowRect(&rcWnd);
rcWnd.SetRect(0, 0, rcWnd.Width(), rcWnd.Height());
dc.SelectStockObject(BLACK_PEN);
dc.SelectStockObject(WHITE_BRUSH);
dc.Rectangle(&rcWnd);
}
void CMySearchBox::OnButtonClick()
{
// TODO: Add your message handler code here and/or call default
::SendMessage(::GetParent(m_hWnd), UM_BEGINSEARCH, 0, 0);
}BOOL CMySearchBox::Create(DWORD dwStyle, const RECT &rcLayout,CWnd *pParentWnd, UINT nID)
{
int nRight = rcLayout.right;
if(nRight - rcLayout.left < 24)
nRight = rcLayout.left + 28;
CRect rect(rcLayout.left,rcLayout.top,nRight,rcLayout.bottom);
WNDCLASS wndcls;
memset(&wndcls, 0, sizeof(WNDCLASS)); // start with NULL
// defaults
wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW | CS_NOCLOSE; //you can specify your own window procedure
wndcls.lpfnWndProc = ::DefWindowProc;
wndcls.hInstance = AfxGetInstanceHandle();
wndcls.hIcon = NULL; // or load a different icon
wndcls.hCursor =NULL;
wndcls.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);//(HBRUSH) (COLOR_WINDOW + 1);
wndcls.lpszMenuName = NULL;// Specify your own class name for using FindWindow later
wndcls.lpszClassName = _T("likebeta_SearchBox");
LPCTSTR lpszClassName = _T("likebeta_SearchBox"); // Register the new class and exit if it fails
if(!AfxRegisterClass(&wndcls))
{
lpszClassName= AfxRegisterWndClass(0);
}
return CWnd::Create(lpszClassName, _T("likebeta_SearchBox"),dwStyle, rect, pParentWnd, nID, NULL);
}这个是 编辑框+按钮 的复合控件!!