سؤال

I created control-derived classes using MFC ,like FolderLister derived from CListCtrl or colored rich edit control.So I want to keep them in a file because project gets very messy with this way.Can i create my own control-derived from a control then use it in toolbox ? or can i keep my class in a file so i can store it in a file? I am searching this for 2 days still no idea what to do should i use static library or create an activex control ? or use atl.

Sorry for my english. Thanks in advance.

هل كانت مفيدة؟

المحلول 2

It is an innate ability in Windows. A button control is a good example, just call CreateWindowsEx() and pass L"Button" for the class name and you've got yourself a button control. They are controls that are built into Windows.

Creating your own using this scheme is very simple. Just create a DLL project with an exported Initialize() function. Call RegisterClassEx() in that function to register your own control class. The client code can now simply call CreateWindowEx() and pass your control class name to get your control on their window. It is the window procedure you registered in your WNDCLASSEX that gives the window its custom behavior. Add your own messages to allow the client to configure your control and invoke custom features. This is exactly the way the common controls work, the initialization function is InitCommonControls, the custom messages are declared in the CommCtrl.h header file.

You can infinitely complicate that pattern with schemes to get Windows to automatically find and load your DLL and to get your controls to work in a designer. The idea behind ActiveX controls. Quite a learning curve, best to keep it simple.

نصائح أخرى

You probably want to create and ActiveX control. You can do that with MFC, or with ATL, or (if you're masochistic) on your own.

Of those three, it's generally easiest with MFC and hardest on your own. The problem with MFC is that the control tends to be quite large. ATL lets you generate controls almost as small as if you'd written them entirely by hand, and is only marginally more difficult than MFC to develop with.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top