Click here to Skip to main content
15,922,325 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Scroll a CListCtrl? Pin
Dominik Reichl3-Jul-03 3:45
Dominik Reichl3-Jul-03 3:45 
GeneralRe: Scroll a CListCtrl? Pin
Ryan Binns3-Jul-03 4:03
Ryan Binns3-Jul-03 4:03 
GeneralRe: Scroll a CListCtrl? Pin
Dominik Reichl3-Jul-03 5:56
Dominik Reichl3-Jul-03 5:56 
GeneralRe: Scroll a CListCtrl? Pin
Ryan Binns3-Jul-03 14:55
Ryan Binns3-Jul-03 14:55 
GeneralSelecting multiple CEdit Boxes Pin
K. Shaffer2-Jul-03 9:18
K. Shaffer2-Jul-03 9:18 
GeneralRe: Selecting multiple CEdit Boxes Pin
John R. Shaw2-Jul-03 11:16
John R. Shaw2-Jul-03 11:16 
GeneralRe: Selecting multiple CEdit Boxes Pin
Ryan Binns3-Jul-03 1:43
Ryan Binns3-Jul-03 1:43 
GeneralHaving some trouble subclassing dynamically created CButtons Pin
Flack2-Jul-03 8:57
Flack2-Jul-03 8:57 
Hello,

I was trying out one of the articles I read here about subclassing. The article can be found at http://www.codeproject.com/miscctrl/subclassdemo.asp#xx524121xx


I have subclassed CButton and have a new class, CMyButton. Now, I added all of the functionality that I want to CMyButton and want to subclass my CButtons.

In my app I have some CButtons that are dynamically created. The user hits "Add Button" in the menu and the button appears. This is what I tried to do in order to subclass the button:

//First the button is created (I am using an array of CButtons)<br />
m_buttons[m_numButtons].Create(Source,WS_VISIBLE|WS_TABSTOP|BS_FLAT|<br />
BS_PUSHBUTTON|BS_ICON|BS_VCENTER, r, MainWnd,IDC_MAIN_BUTTON + m_numButtons);<br />
<br />
//Now I try to subclass it<br />
CWnd *pWnd = GetDlgItem(IDC_MAIN_BUTTON + m_numButtons); <br />
ASSERT(pWnd && pWnd->GetSafeHwnd());<br />
m_btnMyButton.SubclassWindow(pWnd->GetSafeHwnd());<br />


However, the bold line gives me an assertion error in WinCore.cpp:
ASSERT(FromHandlePermanent(hWndNew) == NULL);
// Must not be already in permanent map

I read at Microsoft that this implies that the control that I am attempting to subclass has already been subclassed.

Does anyone know how I can resolve this problem?


Also, in CMyButton::DrawItem I have the button turn yellow, just as the article says. However, how can I make it so the button is drawn with all of the styles I have indicated when I created the button? What I have in DrawItem is exactly as in the article but button styles are not handled in the article. For example, I want a flat, icon button that is a tab stop, but the button is drawn as a usual button and unable to be tabbed to. What do I have to add to my DrawItem function to get it to make the button flat, display the icon, and be a tab stop and have any other styles that I added when I created the original CButton, before it was subclassed?

If you have any questions please let me know.

Thanx,
-Flack
GeneralRe: Having some trouble subclassing dynamically created CButtons Pin
basementman2-Jul-03 9:38
basementman2-Jul-03 9:38 
GeneralRe: Having some trouble subclassing dynamically created CButtons Pin
Flack2-Jul-03 10:14
Flack2-Jul-03 10:14 
GeneralRe: Having some trouble subclassing dynamically created CButtons Pin
Ryan Binns2-Jul-03 16:08
Ryan Binns2-Jul-03 16:08 
QuestionCreate and Access Hardware? Pin
Selevercin2-Jul-03 8:28
Selevercin2-Jul-03 8:28 
AnswerRe: Create and Access Hardware? Pin
John M. Drescher2-Jul-03 8:51
John M. Drescher2-Jul-03 8:51 
GeneralRe: Create and Access Hardware? Pin
Selevercin2-Jul-03 9:13
Selevercin2-Jul-03 9:13 
GeneralRe: Create and Access Hardware? Pin
John M. Drescher2-Jul-03 9:18
John M. Drescher2-Jul-03 9:18 
GeneralRe: Create and Access Hardware? Pin
David Crow2-Jul-03 10:01
David Crow2-Jul-03 10:01 
GeneralRe: Create and Access Hardware? Pin
Selevercin2-Jul-03 10:54
Selevercin2-Jul-03 10:54 
GeneralRe: Create and Access Hardware? Pin
David Crow2-Jul-03 16:54
David Crow2-Jul-03 16:54 
GeneralRe: Create and Access Hardware? Pin
jhwurmbach3-Jul-03 1:19
jhwurmbach3-Jul-03 1:19 
AnswerRe: Create and Access Hardware? Pin
Trollslayer2-Jul-03 11:14
mentorTrollslayer2-Jul-03 11:14 
GeneralRe: Create and Access Hardware? Pin
Selevercin2-Jul-03 12:33
Selevercin2-Jul-03 12:33 
GeneralRe: Create and Access Hardware? Pin
Trollslayer2-Jul-03 13:02
mentorTrollslayer2-Jul-03 13:02 
GeneralRe: Create and Access Hardware? Pin
Selevercin2-Jul-03 14:38
Selevercin2-Jul-03 14:38 
GeneralRe: Create and Access Hardware? Pin
Trollslayer3-Jul-03 4:42
mentorTrollslayer3-Jul-03 4:42 
GeneralRe: Create and Access Hardware? Pin
Trollslayer2-Jul-03 13:05
mentorTrollslayer2-Jul-03 13:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.