用ATL创建了一个基于Button的控件,想使用BS_OWNERDRAW进行自绘,但在MFC程序中使用CreateControl创建ActiveX控件时无法设置style.请高手帮忙.
m_btnWnd.CreateControl(CLSID_ABCDE, NULL, WS_VISIBLE|BS_OWNERDRAW, rcWnd, this, 1111);
ATL中的OnCreate函数.
LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
RECT rc;
GetWindowRect(&rc);
rc.right -= rc.left;
rc.bottom -= rc.top;
rc.top = rc.left = 0;
LPCREATESTRUCT cs = reinterpret_cast<LPCREATESTRUCT>(lParam);
if (cs->style & BS_OWNERDRAW)//这里style的值与CreateControl时传入的style不同
m_ctlButton.Create(m_hWnd, rc, 0, BS_OWNERDRAW);
else
m_ctlButton.Create(m_hWnd, rc, 0); return 0;
}

解决方案 »

  1.   

    我的本意是通过CreateControl时传入的style参数(BS_OWNERDRAW)来判断是否需要自绘.为什么这个参数没有传到OnCreate消息中?
      

  2.   

    CreateControl is a direct analog of the CWnd::Create function, which creates the window for a CWnd. CreateControl creates an ActiveX control instead of an ordinary window.Only a subset of the Windows dwStyle flags are supported for CreateControl: WS_VISIBLE   Creates a window that is initially visible. Required if you want the control to be visible immediately, like ordinary windows.WS_DISABLED   Creates a window that is initially disabled. A disabled window cannot receive input from the user. Can be set if the control has an Enabled property.WS_BORDER   Creates a window with a thin-line border. Can be set if control has a BorderStyle property.WS_GROUP   Specifies the first control of a group of controls. The user can change the keyboard focus from one control in the group to the next by using the direction keys. All controls defined with the WS_GROUP style after the first control belong to the same group. The next control with the WS_GROUP style ends the group and starts the next group.WS_TABSTOP   Specifies a control that can receive the keyboard focus when the user presses the TAB key. Pressing the TAB key changes the keyboard focus to the next control of the WS_TABSTOP style.
      

  3.   

    CreateControl 只支持一部分style
      

  4.   

    WS_CHILD|。。这样应该就可以了把