CRichEditCtrl in a COM object... possible?
-
Hello all, I am brand new to COM/ATL programming and am trying to figure out if what I want to do is doable. I've gone through the great DCOM tutorial by Brian Hart and it's given me a good start. Here's my situation. I've written a (free) port of the boardgame Settlers of Catan using OpenGL for 3D graphics. I recently added networking capability to it and have been cleaning up things according to user's desires. The biggest problem they all have is that my chat window, which is currently a modeless dialog box, loses the focus anytime there is an in-game event, which causes their typing to suddenly disappear in mid-sentence as the focus suddenly gets set to the main window. A screenshot of the game w/ chat window is is here. My brilliant idea was to rewrite the chat window as a COM object, which would solve the problem of it losing focus since it would be its own window. I've got the basic COM object figured out with a dialog box in it, and a connection point back to the main app for wanting to chat. However, I can't figure out how to connect a CRichEditCtrl to the dialog box, because I don't really understand how CWindow and CWnd work, and do your controls have to be CWindow classes to be used in ATL? The current chat window is a CRichEditCtrl and I'd really like to avoid creating my own control for chatting via the COM object. Can anyone explain this a little better or point me to some resources that do? Thanks. Jason
-
Hello all, I am brand new to COM/ATL programming and am trying to figure out if what I want to do is doable. I've gone through the great DCOM tutorial by Brian Hart and it's given me a good start. Here's my situation. I've written a (free) port of the boardgame Settlers of Catan using OpenGL for 3D graphics. I recently added networking capability to it and have been cleaning up things according to user's desires. The biggest problem they all have is that my chat window, which is currently a modeless dialog box, loses the focus anytime there is an in-game event, which causes their typing to suddenly disappear in mid-sentence as the focus suddenly gets set to the main window. A screenshot of the game w/ chat window is is here. My brilliant idea was to rewrite the chat window as a COM object, which would solve the problem of it losing focus since it would be its own window. I've got the basic COM object figured out with a dialog box in it, and a connection point back to the main app for wanting to chat. However, I can't figure out how to connect a CRichEditCtrl to the dialog box, because I don't really understand how CWindow and CWnd work, and do your controls have to be CWindow classes to be used in ATL? The current chat window is a CRichEditCtrl and I'd really like to avoid creating my own control for chatting via the COM object. Can anyone explain this a little better or point me to some resources that do? Thanks. Jason
Hi Jason, Using ATL CRichEditCtrl is about the same than using Win32 API call. If you have used MFC, then this is not really a problem, since it provides about the same interfaces (function name). Even though I didn't see how that would fix your problem (having ActiveX container) since your main window will still capture the focus with every event. It is better to fix that with the main window, why does it need to capture the focus? Anyway, just create it:
// one of them must be loaded
//HINSTANCE hLibRichEdit = LoadLibrary(_T("RICHED32.DLL"));
//HINSTANCE hLibRichEdit = LoadLibrary(_T("RICHED20.DLL"));
DWORD dwStyle = WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_HSCROLL;
dwStyle |= ES_MULTILINE|ES_AUTOHSCROLL|ES_AUTOVSCROLL;
// rc is position and size, and m_hWnd is parent (current dialog)
m_ctlRichEdit.Create(m_hWnd, rc, NULL, dwStyle);BTW, when do you plan to release your game? (it looks good) Last Article: Adding VBScript/JScript to C++ App
-
Hi Jason, Using ATL CRichEditCtrl is about the same than using Win32 API call. If you have used MFC, then this is not really a problem, since it provides about the same interfaces (function name). Even though I didn't see how that would fix your problem (having ActiveX container) since your main window will still capture the focus with every event. It is better to fix that with the main window, why does it need to capture the focus? Anyway, just create it:
// one of them must be loaded
//HINSTANCE hLibRichEdit = LoadLibrary(_T("RICHED32.DLL"));
//HINSTANCE hLibRichEdit = LoadLibrary(_T("RICHED20.DLL"));
DWORD dwStyle = WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_HSCROLL;
dwStyle |= ES_MULTILINE|ES_AUTOHSCROLL|ES_AUTOVSCROLL;
// rc is position and size, and m_hWnd is parent (current dialog)
m_ctlRichEdit.Create(m_hWnd, rc, NULL, dwStyle);BTW, when do you plan to release your game? (it looks good) Last Article: Adding VBScript/JScript to C++ App
Thanks for the quick reply! I was thinking about it a little more after writing it and I thought of two ways that are probably better fixes: 1) Write an actual mini-dialog app that is just the CRichEditCtrl chat dialog and have one COM interface that talks between the main app and the chat dialog. Running two different .exe files would guarantee two different windows. 2) Fix the main app (like you suggest) so that it doesn't steal the focus on game events. Honestly, I didn't actually consider it at first because I figured it would be too complex to try and find every instance where it happened, but I may look at this again. Thanks for the compliment on the game. If you go to the main site, you can download the current BETA version (0.8.8). The game itself is complete, I'm just working on some remaining UI issues and cleanup before a 1.0 release.
-
Thanks for the quick reply! I was thinking about it a little more after writing it and I thought of two ways that are probably better fixes: 1) Write an actual mini-dialog app that is just the CRichEditCtrl chat dialog and have one COM interface that talks between the main app and the chat dialog. Running two different .exe files would guarantee two different windows. 2) Fix the main app (like you suggest) so that it doesn't steal the focus on game events. Honestly, I didn't actually consider it at first because I figured it would be too complex to try and find every instance where it happened, but I may look at this again. Thanks for the compliment on the game. If you go to the main site, you can download the current BETA version (0.8.8). The game itself is complete, I'm just working on some remaining UI issues and cleanup before a 1.0 release.
Thanks, did you consider also having your chat window being able to stay on top? By the way, I noticed that the chat window didn't have 'close' button. I will wait for 1.0 release. Thanks and good luck! Last Article: Adding VBScript/JScript to C++ App