Subclassing CWinThread

I created a subclass of CWinThread - no big deal! Now, what I would like to 
do is use that subclass as a base class for a couple of other, more 
specialized classes. How can I do this?

If I create a subclass as a generic C++ class, then I'm running into the 
assertion, "Invalid Address specified to RtlValidateHeap( 00940000, 0042DBA0 
)" when I post the quit message to the thread. I assume this might have 
something to do with the virtual/non-virtual constructor combination of the 
MFC class and the generic C++ class. 

Any thoughts?
0
Ken1 (215)
8/18/2005 2:32:05 PM
vc.mfc 33608 articles. 0 followers. Follow

1 Replies
706 Views

Similar Articles

[PageSpeed] 7

Create more subclasses of CWinThread, then hand-edit them to replace all instances of
CWinThread with the name of the superclass you want to subclass them from.

IT would have been fairly straightfoward for Microsoft to have supported this; I have no
idea why they do not.

Of course, it would have made sense to support this in VS.NET, but instead of solving REAL
problems they just took the time to systematically destroy the user interface...

The invalid address assertion sounds like a bug; I've done this multilevel subclassing
many times with no problems (there's even an essay on my site about how to do it for
dialogs and property pages).  If you accidentally delete the CWinThread object before the
thread finishes, you could have problems.  Make sure you aren't a victim of premature
deletion in some form.

				joe

On Thu, 18 Aug 2005 07:32:05 -0700, Ken <Ken@discussions.microsoft.com> wrote:

>I created a subclass of CWinThread - no big deal! Now, what I would like to 
>do is use that subclass as a base class for a couple of other, more 
>specialized classes. How can I do this?
>
>If I create a subclass as a generic C++ class, then I'm running into the 
>assertion, "Invalid Address specified to RtlValidateHeap( 00940000, 0042DBA0 
>)" when I post the quit message to the thread. I assume this might have 
>something to do with the virtual/non-virtual constructor combination of the 
>MFC class and the generic C++ class. 
>
>Any thoughts?
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15972)
8/20/2005 10:12:13 PM
Reply:

Similar Artilces:

Subclassing
Hello, Im very new to c++ programming so pardon me if this is a dumb question and my bad english. I made a subclass from CListBox. I want to handle all the list controls derived from this class on one function, for example, void CListBox_SC::OnRButtonUp(UINT nFlags, CPoint point) { ..... } on this function I want to manage the OnRButtonUp event, and with a switch or if statement, select the code to execute. The following does work: SetCurSel(ItemFromPoint(point, ifp)); but the following comparison is never true, (IDC_LST_TIPO is a resource for one of the ListBoxes) UINT currLst = It...

Custom Drawing CEdit : Subclassing
Hello experts, My objective is simple, but I'm not entirely sure what needs tweaking. I am using MSVC 6, and I would like to subclass the CEdit box so that it appears as the color-picker editbox of a PropertyGrid. There is a color box followed by three values. Like this: [###] 255; 192; 192 Where ### is just a color box representation of the value. So thus far, I've made a masked CEdit box, where I can edit the numbers (or click a button that visually sets the numbers from a different window), and I'm happy with that - but what I would like to do next is to subclass the dra...

Help with subclassing a RichEditCtrl
Hi folks, I could use some help. As a side project I am trying to write a DLL that will extend the functionality of an existing application that I do not have source code for, i.e., some autocompletion functionality, word lookup, etc. In the actual DLL, I am going to have to inject it into the existing app and then use FindWindow or something like that to subclass the existing RichEditCtrl. I need to be able to process the WM_CHAR and WM_KEYDOWN messages only. I started out by creating my own sample project using a RichEditCtrl in my project to code my object. I've now moved everythin...

WM_CREATE for a subclass
Hi All, I am fairly new to C++, although I have developed OO windows applications in the past using CTD and Power Builder. I am developeing an edit class based on a CEdit. I am trying to trap the WM_CREATE message to modify the style of the window (i.e. to make is multiline). For some reason the control does not appear to be getting the WM_CREATE message ( or at least it is not implementing the handler I have for it). At present I create an edit control on a form and the Subclass the edit. This appears to work as my user defined menu is used and my color modifications appear as requir...

Subclassing CWinThread
I created a subclass of CWinThread - no big deal! Now, what I would like to do is use that subclass as a base class for a couple of other, more specialized classes. How can I do this? If I create a subclass as a generic C++ class, then I'm running into the assertion, "Invalid Address specified to RtlValidateHeap( 00940000, 0042DBA0 )" when I post the quit message to the thread. I assume this might have something to do with the virtual/non-virtual constructor combination of the MFC class and the generic C++ class. Any thoughts? Create more subclasses of CWinThread, then ...

Subclassing TreeView
I created a class derived from a TreeView (ShellTree) that displays the Shell directory structure . I changed the LeftView class so that it is derived from my ShellTree class, and everything works as expected, except I cannot add any TreeView specific message handlers to my LeftView class any more eg. NM_DBLCLICK. Basically in a nutshell what i want to do is display the directory name (which is stored in a variable in the ShellTree class) when the LeftView is Double clicked Check out http://www.codeproject.com/treectrl/enumdeskclones.asp Which isn't perfect.. but is a good star...

Subclassing a subclass of CDialog, for cross-platform compilation
Hi people, I've been working on porting an app from PC to Mac. What I'm trying to do, is separate out the PC specific components into it's own subclass. So there are the PC specific functions like PCAppDlg::OnBtnClicked1, and mac specific functions like MacAppDlg::BlaBlaBla. Of course the Mac subclass doesn't compile on the PC, and the same the other way around. I've had to write my own CDialog wrapper for Mac but that's another story. Now anyhow, this leads me to a question. How to subclass a subclass? Specifically, how does the message maps work? Will there be any p...

Xml Serializing subclass problem
Hi guys. I've come across a problem when I tried to serialize a class into xml, only to discover that the parent class's XML Serialization properties weren't included in the output xml. Actually, the class I'm serializing is two steps down in the inheritance ladder. It's got a parent class which also has a parent class :( All those classes in the hierarchy are Xml Serializable, and I'd think that it should be obvious that all attributes/properties of the parents should be serialized for any given subclass, no ? Here's the two classes, subclass first, parent class...

Subclassing problem???
Hi there, I've got: LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ switch(uMsg){ case WM_NCACTIVATE: if((BOOL)wParam==FALSE){ DefWindowProc(hwnd, uMsg, wParam, lParam); CreateText(hwnd); return TRUE; } case WM_NCPAINT: DefWindowProc(hwnd, uMsg, wParam, lParam); CreateText(hwnd); break; } DefWindowProc(hwnd, uMsg, wParam, lParam); } void CreateText(HWND hwnd){ HDC hDC = GetWindowDC(hwnd); int x,y; RECT rc1,rc2; GetWindowRect(hwnd, (LPRECT)&rc2 ); x = GetSystemMetrics(SM_CXSIZE) + GetSystemMetrics(SM_CXBORDE...

subclassing CStatic
Hi, I have subclassed a few CStatic ctrls so i can quickly change their font, BG and FG colors etc... I have also handled the CFormView's CtlColor message and painted the form white and text blue. The problem that im having is the subclassed objects are painting themselves the colors i specify, then the CFormView::OnCtlColor is painting them again. This isnt too much of a problem as i can simply exclude the subclassed items from the painting using: HBRUSH CSmartMXEditLangView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { // create white brush: m_DlgBrush.DeleteObject(); ...

VC
I need a way to come up with a simple (free) combobox activeX control I can use in a third party development tool. I tried just subclassing ComboBoxEx using the ActiveX control wizard in VC6. It clearly creates the control, but it doesn't seem to be created with the properties and methods (like AddItem/New) and when I plop on a VB6 form it doesn't look like a combobox. Granted I am newbie working way over my head, by why would the ActiveX control wizard ask me which control to inherit from if it isn't going to give me _roughly_ the same functionality? Can anyone point me in a di...

subclassing CComboBox
compiler: VC++ 6.0 SP 6, running XP Pro SP 2. I subclassed CComboBox into CMyComboBox, then setup up event handlers for several of the reflected events -- one being CBN_CLOSEUP reflected event. I have an object of type CMyComboBox in an MFC program, which also needs to catch the CBN_CLOSEUP event. I used ClassWizard to create all event handlers. Problem: The event handler in CMyComboBox works ok, but the handler in the application program never gets called. Is there a way around this problem? I tried posting a message to the parent window but that didn't seem to work either (pare...

WM_CLOSE, CWinThread, and access violation in Run()
Hi, At the very beginning of my app's InitInstance() I create and start a UI thread (CWinThread derived) that in turn creates and displays a window. The window is closed on a mouse click which usually takes place after the app's frame is displayed. The click is detected in PreTranslate() method and is then followed by posting WM_CLOSE message to the window (i.e. self). In turn, the messages shuts down the UI thread that created the window. The problem is that I get access violation in CWinThread::Run() method. I can't figure out what is going on there because the "t...

Moving subclasses to different classes
I'm having trouble figuring out how to move subclasses to different classes (to re-assign budget categories to differnt umbrella budget areas). I see a "MOVE" button at the bottom of the list of Classes but can't figure out how to make it active. Anyone know the secret to moving classes without deleting them, recreating them under a new high level class, and re-assigning the transactions? Thanks in Advance!! Never mind -- you just delete the class and ask it to reassign things to a new subclass bucket. PRODUCT WISHLIST: Have the "MOVE" button active...

Subclassing AfxControlBar80su
I have a CDialogBar derived class which has a bitmap background texture. The parent's wndclass is AfxControlBar80su which still displays in gray. I'd like to give it the same background as the dialog bar and I thought it could be done by subclassing and handling the appropriate messages. But how can that be done? TIA, Hans Subclass CDialogBar and override OnPaint would be my first guess as to how to do it. The AfxControlBar80su is probably not relevant here. joe On Mon, 30 Jul 2007 01:16:15 +0200, Hans-J. Ude <news@hajue-ude.de> wrote: >I have a CDialogBar derived c...

subclassing a CTreeCtrl
All, I'm trying to subclass a CTreeCtrl control with a CHeaderCtrl derived class to obtain the result as in (http://users.pandora.be/bart.de.lathouwer/Untitled-1.jpg) I would subclass the CTreeCtrl derived class to be able to draw 'over' both the header and CTreeCtrl surface. When I subclass my CTreeCtrl derived class it reports that it is already attached. My Ctrl's live in a CWnd derived class. Question: What is the correct way to subclass my CTreeCtrl with my HeaderClass to be able to draw "over" both classes? If not possible what is an alternative? (apart from ...

Subclass question
Hi, I am writing an app in which I have a dialog bar (IDD_DLGBAR) at the top of the MDI frame window besides the standard toolbar. The dialog bar contains several controls. One of them is a combo box with id IDC_SEARCHBOX. I also created a class CSearchBox (derived from CComboBox) to process keyboard messages. My question is how do I link the combo box in the dialog bar with CSearchBox class so I can capture keyboard events (i.e., PreTranslateMessage)? Thanks in advance. >Hi, I am writing an app in which I have a dialog bar (IDD_DLGBAR) at the top >of the MDI frame window beside...

Subclass Help
During the desing of my app, I realized that I would need to have a combobox with a set of pre-defined values (collected from a database). This combobox will be used in many dialogs and for that, I decided to derive my own class. I want the combobox to be populated when created, but I can't figure out how to make it work with DDX. If I "create" it manually, I can do this in "OnCreate," but I'm attaching to a dialog. I don't know what gets called when DDX does the attaching. Any ideas? Thanks in advanced. Eddie. "Eddie Pazz" <drpazz@hotmail...

SHBrowseForFolder Subclassing.
I would like to change the name of the "cancel" button. Is that possible with Subclassing, Superclassing, etc.? ....Bruce Maybe this article can help you: http://www.codeproject.com/dialog/browse_for_folder_dialog.asp -- Mav Rossi "Bruce Arnold" <b_a_r_n_o_l_d@b_l_a_s_t.n_e_t> ha scritto nel messaggio news:cka5tv4rf6mq086b1nf6t6gom5rgds0a33@4ax.com... > I would like to change the name of the "cancel" button. Is that > possible with Subclassing, Superclassing, etc.? > ...Bruce > > And this too: http://www.codeproject.com/dialog/browse...

Re: Subclassing
Hi All I wish to create my own control for subclassing. The control will essentially contain some simple text and some minor graphics. No real control functionality is required. The question is should I derive this new control from an existing control, say CButton, or directly from CWnd? Thanks in advance LarryM wrote: > Hi All > > I wish to create my own control for subclassing. The control will > essentially > contain some simple text and some minor graphics. No real control > functionality is required. > > The question is should I derive this new control...

Subclassing controls
Hi! I'm trying to create a custom control with custom NC area, but there's an odd problem: When I create the control using .Create(...), its all fine, but when I subclass the control, the NC messages are never sent! Anyone knows why this happens?? Tnx... >I'm trying to create a custom control with custom NC area, but there's an >odd problem: >When I create the control using .Create(...), its all fine, >but when I subclass the control, the NC messages are never sent! Which WM_NC* messages in particular? Presumably the WM_NCCREATE message won't be caught...

questions of subclassing
hi all I derieved a button class called cmybutton, I want to replace all button in my application with cmybutton so I use subclass but the question is, if the button is created by my resource templates, it works, but failed in other resource templates such as Message Boxs' buttons. That is, if I use AfxmessageBox to display a dialog box, the buttons in the dialog didn't display it seems the subclassing doesn't work what can I do many thanks That's because you cannot subclass messagebox buttons. Subclassing in MFC works only because it is a fiction maintained by MFC ...

Naming CWinThread
Is there a supported method for naming a CWinThread object, such that the name appears in the threads window of the debugger? "Ken" <Ken@discussions.microsoft.com> wrote in message news:7D84B809-CCAF-4619-A979-807FD9485D3A@microsoft.com... > Is there a supported method for naming a CWinThread object, such that the > name appears in the threads window of the debugger? It seems like I got this code from codeproject: // set any thread's name // Note: SetThreadName ("MainThread", -1); to set the main thread's name void CMyThread::_SetThreadName(LPCSTR s...

Subclassed CEdit needs OnClose
I have a subclassed CEdit control. I need to GetWindowText() just before the CEdit is destroyed, but can't figure out where to do this. I've tried OnDestroy() (doesn't get called), my destructor (the m_hWnd is no longer valid), OnClose() (doesn't get called), etc. Thanks, Steve Could you grab the text in a OnKillFocus() handler? That way you'd get a message when they move off of the control as well as when it is destroyed. Just a thought. Tom "Steve" <junk@bruff.com> wrote in message news:97327c0.0309251221.35c93d02@posting.google.com... > I have...

questionn about subclass.
In a Dialog. Define these 2 member: CButton m_btnOld; CMyButton m_btnMy; Add these code in OnInitDialog: CRect rectBtn(300,10,350,40); m_btnOld.Create(_T("asdfas"),WS_CHILD|WS_VISIBLE,rectBtn,this,3000); m_btnMy.SubclassDlgItem(3000,this); I got a assert when it run to " m_btnMy.SubclassDlgItem(3000,this);" the assert is: ASSERT(FromHandlePermanent(hWndNew) == NULL); is this method right? if not, how shall I do? thanks a lot! "rokia" <rokiadd@yahoo.com.cn.discuss> wrote in message news:%23iJRUSWbEHA.3524@TK2MSFTNGP12.phx.gbl... > In a...