Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / January 2008

Tip: Looking for answers? Try searching our database.

"classic" custom control, written in C, used in MFC, how to use in .NET?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Stuart - 25 Jan 2008 17:59 GMT
Thanks in advance for just reading this... any help or advice would be
greatly appreciated.. TIA

We have a very complex C based custom control for graphically
displaying analog information in a custom format.  It is embodied in a
DLL and the control gets registered with Windows when the DLL is loaded
by a call to:

LoadLibrary(<dll file name>)

The main entry point of the dll registers the custom control with
windows by calling RegisterClassEx.  This tells Windows among other
things what the window class ("PcsRecordingDisp") (yes this predates
C++ et al) and the WndProc that will handle all the windows messages
(e.g. WM_PAINT, WM_DESTROY...) as well as any user messages (messages
with message IDs greater than or equal to WM_USER).

In C when one of these windows gets created the main program (after
calling LoadLibrary) calls

CreateWindow(LPCTSTR lpClassName,  // the window class name registered
                                  // in the call to RegisterClassEx by
                                  // the DLL ("PcsRecordingDisp")
            LPCTSTR windowname,   // window title or window text... we
                                  // use NULL
            DWORD  dwStyle,       // window styles e.g.  WS_VISIBLE...
            int    x,             // x position of where to draw in
                                  // the parent window
            int    y,             // y position of where to draw in
                                  // the parent window
            int    nWidth,        // control width
            int    nHeight,       // control height
            HWND   hwndParent,    // windows handle of the parent
                                  // window (in which this control
                                  // resides)
            HWND   hMenu,         // is the control ID of this control
            HINSTANCE hInstance,  // ignored for NT and up so we use
                                  // NULL
            LPWOID lpParam        // pointer to a CLIENTCREATESTRUCT,
                                  // can use NULL because this is NOT
                                  // a multiple-document interface
                                  // client window)
            );

When we decided to also use the custom control in an MFC app we found
that getting it linked in was not too bad:

1) call LoadLibrary
2) any instances of the custom control were added to the resource
section for any dialog:
       
IDD_RIGHT_SIDE_DETAILS DIALOGEX 0, 0, 330, 333 STYLE DS_SETFONT |
DS_MODALFRAME | DS_CONTROL | WS_CHILD FONT 10, "MS Sans Serif", 0, 0,
0x1

BEGIN
   // an example of a standard right justified text box)
   RTEXT           "Model:",IDC_MODEL_LABEL,
                14,12,30,8,0,WS_EX_TRANSPARENT // IDC_MODE_LABEL
                                               // is a unique
                                               // integer identifier

   // an example of how a standard list view was declared
   CONTROL   "List2",IDC_ATTACHED_FILES,"SysListView32",  //
                 LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS |
                 WS_BORDER | WS_TABSTOP,0,200,329,31

   
   // ... other controls

   // one of the custom controls:
   CONTROL    "",IDC_RECORDING,
                 "PcsRecordingDisp",    // "PcsRecordingDisp" was
                                        // registered by the DLL
                                        // calling RegisterClassEx
                 WS_TABSTOP,
                 0,104,48,40  

   // other controls...

END

After the dialog would come up any interactions with the custom control
could be handled by calling <custom control variable>.SendMessage

It seemed to me that with all the flexibility of .NET that a similar
migration and integration should be reasonably easy.  I am now stumped.
There seems to be no way to specify a windows class.  I cannot call
CreateWindow (because adding an #include <windows> to the source drives
the compiler nuts).  Obviously the standard windows controls are there
and I am assuming that deep under the hood they are still GDI windows.
Yes I see that there is a capability to add "user control"
(System::Windows::Forms::UserControl) which is largely intended for
creating a custom control written in .NET C++ and consists for one or
more standard controls bound together in a nice package.   I am looking
for a technique to link in an existing old school custom control.  I
could do it in C, I could do it in MFC but .NET (forms)  has me stumped
and confused.  Regarding C#: For now our group is sticking to .NET
instead of going into C#.  I would prefer to keep my attempts limited
to .NET if possible.

Thanks again

Stuart
Kevin Spencer - 28 Jan 2008 11:29 GMT
See the following and related MSDN articles:

http://msdn2.microsoft.com/en-us/library/sd10k43k(VS.71).aspx

Signature

HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP

> Thanks in advance for just reading this... any help or advice would be
> greatly appreciated.. TIA
[quoted text clipped - 99 lines]
>
> Stuart

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.