|
Effectively I didn't registered it. Since this custom control works when used in the main application, I was guessing that it would dirctly run.
I'm not very close to DLLs, can you quickly explain me how to register it and why it's needed ?
Thank you very much BB, I begin to see the light at the end of the tunnel
|
|
|
|
|
There's an important issue here: MFC extension DLLs maintain their own resource handle.
Personally I call such function in the C++ constructor of all my custom controls (I modified it slightly to fit your question):
BOOL CMyCustomCtrl::RegisterClass()<br />
{<br />
WNDCLASS wndcls;<br />
HINSTANCE hInst = AfxGetResourceHandle();<br />
<br />
if(!(GetClassInfo(hInst, "MyWndClassName", &wndcls)))<br />
{<br />
wndcls.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;<br />
wndcls.lpfnWndProc = ::DefWindowProc;<br />
wndcls.cbClsExtra = wndcls.cbWndExtra = 0;<br />
wndcls.hInstance = hInst;<br />
wndcls.hIcon = NULL;<br />
wndcls.hCursor = LoadCursor(NULL, IDC_ARROW);<br />
wndcls.hbrBackground = NULL;<br />
wndcls.lpszMenuName = NULL;<br />
wndcls.lpszClassName = "MyWndClassName";<br />
<br />
if(!AfxRegisterClass(&wndcls))<br />
{<br />
AfxThrowResourceException();<br />
return FALSE;<br />
}<br />
}<br />
return TRUE;<br />
}
The function checks whether the control is registered with current resource handle, and registers it if not yet done. This way we cover both the application and DLL case. The function can be universal if you derive your custom controls from the common base class and use "MyWndClassName" as a function argument.
You may read in the MSDN what the several WNDCLASS members mean, and the code is self-commenting I guess. I hope I didn't miss anything in this explanation, but ask if there's turn out wrong.
Regards,
BB
|
|
|
|
|
Thank you BB you're great, I'll try this as soon as possible and I'll post the result here in order to let users and you know if it works.
Thank you again !
|
|
|
|
|
Dear BB,
Your solution doesn't work for the moment. After some debug, it appears that the Form View window handle is not valid. According to http://www.cpp.atfreeweb.com/MFC/LoadFrame/Index.asp[^], AfxHookWindowCreate() does the following things :
- CFrameWnd::OnCreate
- Calls CWnd::OnCreate
- Calls OnCreateClient, which, if a context with a new view class is supplied, calls CreateView (and that is where the view is created) with the context and an id of AFX_IDW_PANE_FIRST
- Sends (using PostMessage) a WM_SETMESSAGESTRING message to set the status bar message to the string with a resource id of AFX_IDS_IDLEMESSAGE
- Calls RecalcLayout
I'm sure the problem cames from CWnd::OnCreate but I don't know why it return a NULL window handle...
|
|
|
|
|
When you are to create the form view, set the resource handle to the DLL one. These are the steps required (file and variable names assumed, use your own):
1. Near the DllMain function in YourDllName.cpp, find a declaration like: AFX_EXTENSION_MODULE YourDLL = { NULL, NULL };
2. In YourDllName.h (if it doesn't exist, create it), declare:
extern AFX_EXTENSION_MODULE YourDLL;
3. Before form creation, set the handle:
HINSTANCE hPrevHandle = AfxGetResourceHandle();<br />
AfxSetResourceHandle(YourDLL);
// TODO: create view here
AfxSetResourceHandle(hPrevHandle);
If the handle is not set to a module where you defined a dialog template, it cannot be loaded and thus creation fails.
Additionally, you may use a class that encapsulates above functionality and restores the original handle in its destructor (when going out of scope):
class CResourceHandler<br />
{<br />
public:<br />
HINSTANCE m_prevHandle;<br />
<br />
public:<br />
CResourceHandler(AFX_EXTENSION_MODULE &module);<br />
{<br />
m_prevHandle = AfxGetResourceHandle()<br />
AfxSetResourceHandle(module.hModule);<br />
}<br />
<br />
CResourceHandler(HINSTANCE &handle)<br />
{<br />
m_prevHandle = AfxGetResourceHandle();<br />
AfxSetResourceHandle(handle);<br />
}<br />
<br />
virtual ~CResourceHandler()<br />
{<br />
AfxSetResourceHandle(m_prevHandle);<br />
}<br />
};
4. With the class, the creation code simplifies as follows:
<br />
void CreateMyFormView()<br />
{<br />
CResourceHandler rh(YourDLL.hModule);
// TODO: create view here
}
Of course, the CreateMyFormView() function has to be located in a DLL.
Regards,
BB
|
|
|
|
|
Hi,
I have a problem. I have to read the name of a class in a data base and then try to instanciate a object of that class. How can i do it?
Example:
CString className = "CMyClass";
CRuntimeClass* ptr = RUNTIME_CLASS(class); -> Error
CObject* o = ptr->CreateObject()
|
|
|
|
|
Use a class factory to instantiate the class, given its name.
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
|
I have a dialog application and would like to have a menu selection up in the title bar pull down menu for an "about" box. How do I add this?
My dialog has the following options selected:
Popup
Thin
title bar
system menu
Thanks for the help
|
|
|
|
|
Add this code in your dialog's OnInitDialog() handler:
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
IDM_ABOUTBOX is a string resource with the value "About MyApp..."
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
I just figured this was missing by doing a compare.
Now I just have to get it to call the dialog I want.
Thanks for the timely responce.
Jim
|
|
|
|
|
Thought I had this wipped, but I can't seem to intercept the OnSystemCommand.
How does the drop down menu on the system title bar get called and where is it located?
It's like it just magically does it on its own.
|
|
|
|
|
Hi All,
I was wondering what would be the difference and why would I want to use either type. The application wizard let's me make a standard dll using mfc shared/static or an MFC extension dll.
Any clarification would be helpfull.
Cheers,
Clint
|
|
|
|
|
|
I'm using CButtonST(posted there too) and am trying to make my buttons transparent, but can't seem to get it to work. Because the controls under the button are more than one color I can't just make it the same color. Is there a way I can set the icons back ground color so it doesn't display it or any other way to get around this?
Thanks
|
|
|
|
|
Look at the CSTButton class members, you'll find what your are searching for.
Florian
|
|
|
|
|
Hi,
my name is Juan and I develop software since 1996 on Visual C++. Recently I try to decode the mouse protocol, so I develop a service and open one serial port and received this data, now I want to send this message from user side to kernel side, I mean, I do not want to do a driver I try to use a service. So, my problem now is how to send this information to kernel side in order to dispatch the data to the application on the user side.
I wait for any help.
Thank you so much.
Juan
|
|
|
|
|
|
Anyone got a little script how to count the lines of my RichEdit-based MDI application such as they do in HTML Editors?
Thanks
|
|
|
|
|
There's a line counter add in on the site somewhere - probably the add-ins section.
Christian
NO MATTER HOW MUCH BIG IS THE WORD SIZE ,THE DATA MUCT BE TRANSPORTED INTO THE CPU. - Vinod Sharma
Anonymous wrote:
OK. I read a c++ book. Or...a bit of it anyway. I'm sick of that evil looking console window.
I think you are a good candidate for Visual Basic. - Nemanja Trifunovic
|
|
|
|
|
Can somebody tell me whats is the difference between UDP and TCP/IP protocol.I'd be sp please if you guide me to some tutorial or links about them.
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
Quite simple really...
UDP is like fire and forget, meaning that you do not need acknowledgement of the packet getting to its destination i.e. video streaming.
TCP/IP needs to have acknowledgements meaning you are guaranteed delivery.
I do not know of any tutorials, this was from my Cisco courses.
BD
|
|
|
|
|
Well,I didn't know it. Thanks.
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
Hello!
I have a small problem I use the DHTMLEdit control and to get the HTML code using GetDocumentHTML but it gives me a code in this format:
....
Is there a way to get this code in this format:
.....
Thank you very much!
|
|
|
|
|
Scolinks wrote:
Is there a way to get this code in this format:
.....
I doubt it. If you really don't want the new lines you will need to massage the returned text to get rid of them.
Neville Franks, Author of ED for Windows. www.getsoft.com
Make money with our new Affilate program
|
|
|
|