我从CStatic 派生了一个CMyCtrl,相应了CLicked!
在CView动态创建了一个CMyCtrl,但是在Click地时候没有办法响应.
大致程序如下:
BEGIN_MESSAGE_MAP(CMyCtrl, CStatic)
ON_CONTROL_REFLECT(BN_CLICKED, OnClicked)
END_MESSAGE_MAP()
void CMyCtrl::OnClicked()
{
MessageBox(_T("ok"),_T("be cliked"));
TRACE("\nHELLO\n");
}
int CTestView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
m_ctrl.Create(_T ("ddddd"),WS_CHILD|WS_VISIBLE|SS_CENTER/*|SS_WHITERECT|SS_WHITEFRAME*/,
CRect(10,10,500,300),this,ID_CTRL);
return 0;
}
在CView动态创建了一个CMyCtrl,但是在Click地时候没有办法响应.
大致程序如下:
BEGIN_MESSAGE_MAP(CMyCtrl, CStatic)
ON_CONTROL_REFLECT(BN_CLICKED, OnClicked)
END_MESSAGE_MAP()
void CMyCtrl::OnClicked()
{
MessageBox(_T("ok"),_T("be cliked"));
TRACE("\nHELLO\n");
}
int CTestView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
m_ctrl.Create(_T ("ddddd"),WS_CHILD|WS_VISIBLE|SS_CENTER/*|SS_WHITERECT|SS_WHITEFRAME*/,
CRect(10,10,500,300),this,ID_CTRL);
return 0;
}
解决方案 »
- 如何通过系统来改变editbox中的字的字号和颜色?
- 一个CDialog窗体,只要用popoup(stytle)方式打开就报错退出,贴出类结构,大家看看有什么问题?
- 求一个二进制数据块中简单00模式识别的算法
- 请教:关于VC控制word编程
- 如何将其它程序显示的窗口嵌入到自己的SDI窗口中?(内空)
- 找朋友!
- 请教一个关于键盘识别的问题:
- 一个很奇怪的问题:请先看一下我的源码:我在win98下使用树控件的setbkcolor()函数可以但是到95下好象就没有用了,不知如何解决?请 各位
- vs2008新建一个项目,怎么么有外部依赖项呢?
- 请问Visual c++ 第四版第316页的类CStudentDoc类是怎么产生的
- 已结的贴子前有个 红色 的勾是什么意思?(注意是"红色"!)
- 关于accept的问题
CRect(10,10,500,300),this,ID_CTRL);
请别怀疑我答案的权威性!MSDN的MFC参考中没有,是漏掉了...
platform sdk文档中:
Static Control Styles
To create a static control using the CreateWindow or CreateWindowEx function, specify the STATIC class, appropriate window style constants, and a combination of the following static control styles. Style Description
SS_BITMAP Specifies a bitmap is to be displayed in the static control. The text is the name of a bitmap (not a filename) defined elsewhere in the resource file. The style ignores the nWidth and nHeight parameters; the control automatically sizes itself to accommodate the bitmap.
SS_BLACKFRAME Specifies a box with a frame drawn in the same color as the window frames. This color is black in the default color scheme.
SS_BLACKRECT Specifies a rectangle filled with the current window frame color. This color is black in the default color scheme.
SS_CENTER Specifies a simple rectangle and centers the text in the rectangle. The text is formatted before it is displayed. Words that extend past the end of a line are automatically wrapped to the beginning of the next centered line. Words that are longer than the width of the control are truncated.
SS_CENTERIMAGE Specifies that a bitmap is centered in the static control that contains it. The control is not resized, so that a bitmap too large for the control will be clipped. If the static control contains a single line of text, the text is centered vertically in the client area of the control.
Windows XP: This style bit no longer results in unused portions of the control being filled with the color of the top left pixel of the bitmap or icon. Unused portions of the control will remain the background color.
SS_ENDELLIPSIS Windows NT/2000/XP: If the end of a string does not fit in the rectangle, it is truncated and ellipses are added. If a word that is not at the end of the string goes beyond the limits of the rectangle, it is truncated without ellipses.
Compare with SS_PATHELLIPSIS and SS_WORDELLIPSIS.
SS_ENHMETAFILE Specifies an enhanced metafile is to be displayed in the static control. The text is the name of a metafile. An enhanced metafile static control has a fixed size; the metafile is scaled to fit the static control's client area.
SS_ETCHEDFRAME Draws the frame of the static control using the EDGE_ETCHED edge style. For more information, see the DrawEdge function.
SS_ETCHEDHORZ Draws the top and bottom edges of the static control using the EDGE_ETCHED edge style. For more information, see the DrawEdge function.
SS_ETCHEDVERT Draws the left and right edges of the static control using the EDGE_ETCHED edge style. For more information, see the DrawEdge function.
SS_GRAYFRAME Specifies a box with a frame drawn with the same color as the screen background (desktop). This color is gray in the default color scheme.
SS_GRAYRECT Specifies a rectangle filled with the current screen background color. This color is gray in the default color scheme.
SS_ICON Specifies an icon is to be displayed in the dialog box. If the control is created as part of a dialog box, the text is the name of an icon (not a filename) defined elsewhere in the resource file. If the control is created via CreateWindow or a related function, the text is the name of an icon (not a filename) defined in the resource file associated with the module specified by the hInstance parameter to CreateWindow. The icon can be an animated cursor. The style ignores the nWidth and nHeight parameters; the control automatically sizes itself to accommodate the icon.
SS_LEFT Specifies a simple rectangle and left-aligns the text in the rectangle. The text is formatted before it is displayed. Words that extend past the end of a line are automatically wrapped to the beginning of the next left-aligned line. Words that are longer than the width of the control are truncated.
SS_LEFTNOWORDWRAP Specifies a simple rectangle and left-aligns the text in the rectangle. Tabs are expanded, but words are not wrapped. Text that extends past the end of a line is clipped.
SS_NOPREFIX Prevents interpretation of any ampersand (&) characters in the control's text as accelerator prefix characters. These are displayed with the ampersand removed and the next character in the string underlined. This static control style may be included with any of the defined static controls. You can combine SS_NOPREFIX with other styles. This can be useful when filenames or other strings that may contain an ampersand (&) must be displayed in a static control in a dialog box.
SS_NOTIFY Sends the parent window STN_CLICKED, STN_DBLCLK, STN_DISABLE, and STN_ENABLE notification messages when the user clicks or double-clicks the control.
SS_OWNERDRAW Specifies that the owner of the static control is responsible for drawing the control. The owner window receives a WM_DRAWITEM message whenever the control needs to be drawn.
SS_PATHELLIPSIS Windows 2000/XP: Replaces characters in the middle of the string with ellipses so that the result fits in the specified rectangle. If the string contains backslash (\) characters, SS_PATHELLIPSIS preserves as much as possible of the text after the last backslash.
Compare with SS_ENDELLIPSIS and SS_WORDELLIPSIS.
SS_REALSIZECONTROL Windows XP: Fits the bitmap to the size of the control by stretching or shrinking the bitmap. As a result of using a different locale setting for the system, a change in the system font may result in controls being resized so that static controls housing bitmaps no longer fit the bitmaps assigned to them. This style bit is provided to allow automatic redimensioning of bitmaps to fit their controls.
Note that the redimensioning in the two axes are independent, and the result may have a changed aspect ratio.
SS_REALSIZEIMAGE Prevents a static icon or bitmap control (that is, static controls that have the SS_ICON or SS_BITMAP style) from being resized as it is loaded or drawn. If the bitmap is not the same size as the control, the control will be resized to fit the bitmap, without centering.
SS_RIGHT Specifies a simple rectangle and right-aligns the text in the rectangle. The text is formatted before it is displayed. Words that extend past the end of a line are automatically wrapped to the beginning of the next right-aligned line. Words that are longer than the width of the control are truncated.
SS_RIGHTJUST Specifies that the lower right corner of a static control with the SS_BITMAP or SS_ICON style is to remain fixed when the control is resized. Only the top and left sides are adjusted to accommodate a new bitmap or icon.
SS_SIMPLE Specifies a simple rectangle and displays a single line of left-aligned text in the rectangle. The text line cannot be shortened or altered in any way. Also, if the control is disabled, the control does not gray its text.
SS_SUNKEN Draws a half-sunken border around a static control.
SS_WHITEFRAME Specifies a box with a frame drawn with the same color as the window background. This color is white in the default color scheme.
SS_WHITERECT Specifies a rectangle filled with the current window background color. This color is white in the default color scheme.
SS_WORDELLIPSIS Windows NT/2000/XP: Truncates any word that does not fit in the rectangle and adds ellipses.
Compare with SS_ENDELLIPSIS and SS_PATHELLIPSIS.
这个可恨地MFC呀!
真是又爱又恨呀!!