Windows Programming WITHOUT MFC

I have VC++ 6.0 and need to know how to create a simple Windows program without using MFC.  I need the example to be dialog-based (like the standard Visual Basic application) -- not an SDI or MDI application.  The other things that I need for it to do is use an ActiveX control (simply initialize and manipulate a few properties), and I need the message handler to be easily extended (i.e. please don't cut corners to shorten the code).

Basically, I just want to know how to create a simple application, with a dialog-based interface, using an ActiveX control, and with an in-depth message handler.

If you want to simply point to a web site, that's fine.

Thanks

(BTW, this is not homework, I've just been itching to know this)
LVL 3
EgoreAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gandalf32Commented:
I can recommend you an excelent book on this by Charles Petzold, titled "Programming Windows 95". It has examples in C, but they can easily be converted to C++. It shows all the basics on Windows programming.
0
Gandalf32Commented:
Another excelent book is "ActiveX controls inside out", by Microsoft Press. This should give you a good insight on how to implement ActiveX controls in your own program.
0
chensuCommented:
Unfortunately, using ActiveX controls without MFC or ATL is not trivial. You have to implement all the required interfaces from scratch yourself.

http://msdn.microsoft.com/isapi/msdnlib.idc?theURL=/library/psdk/com/ctrlgde_9var.htm
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

jhanceCommented:
Unless you're just curious, trying to implement an ActiveX or COM program in C++ without MFC is akin to trying to drive your car around without starting the engine.  Sure you can do it but why would you want to?
0
yowkeeCommented:
As said, you'd better stay with MFC/ATL if you want to use ActiveX control. For basic Windows programming, try the tutorials on http://www.relisoft.com/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GlennDeanCommented:
 But isn't Egore talking about using an ActiveX control, not implementing one.  IF so, then as long as he has all the interfaces supported by the ActiveX (quite abit I know), then he can just call the methods in those interfaces.  In terms of accessing the ActiveX control, seems like "all" he has to do is call CoCreateInstanceEx with the CLSID of the control, and then query for the interface, and then call the method.
0
chensuCommented:
>In terms of accessing the ActiveX control, seems like "all" he has to do is call CoCreateInstanceEx with the CLSID of the control, and then query for the interface, and then call the method.

You can't do that if it is a User Interface ActiveX Control. When we talk about an ActiveX Control, we usually mean a User Interface ActiveX Control. You can simply do that with a COM object.
0
AlexVirochovskyCommented:
Really, in Petzold book you can find example using OLE container without
MFC. Next is snippet: If you want
full text, write you EMail:

WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
     {
     static int       iCurLine = 0 ;
     static LPMALLOC  pMalloc = NULL ;
     static LPSTR     szLine[10] ;
     static RECT      rHit[10] ;

     switch (iMsg)
          {
          case WM_CREATE :
               // Initialize data pointer array
               ZeroMemory (szLine, sizeof (szLine)) ;
               return 0 ;

          case WM_COMMAND :
               switch (LOWORD (wParam))
                    {
                    case IDM_CREATE :
                         pMalloc = CreateAllocator () ;
                         if (pMalloc == NULL)
                              {
                              MessageBox (hwnd, "Error: No allocator",
                                          szAppName, MB_OK) ;
                              return 0 ;
                              }

                         InvalidateRect (hwnd, NULL, TRUE) ;
                         return 0 ;

                    case IDM_DESTROY :
                         {
                         int i ;

                         // Mark allocated blocks as invalid
                         for (i = 0 ; i < 10 ; i++)
                              {
                              if ((szLine[i] != NULL) &&
                                  (pMalloc->lpVtbl->DidAlloc (pMalloc,
                                                              szLine[i])))
                                   {
                                   szLine[i] = NULL ;
                                   }
                              }

                         // Disconnect from & free allocator
                         pMalloc->lpVtbl->Release (pMalloc) ;
                         pMalloc = NULL ;

                         InvalidateRect (hwnd, NULL, TRUE) ;
                         return 0 ;
                         }

                    case IDM_IUNKNOWN :
                         {
                         LPUNKNOWN pUnk ;
                         HRESULT hr =
                              pMalloc->lpVtbl->QueryInterface (pMalloc,
                                                               IID_IUnknown,
                                                               (void **) &pUnk) ;
                         if (SUCCEEDED (hr))
                              {
                              pUnk->lpVtbl->Release (pUnk) ;
                              MessageBox (hwnd, "IUnknown supported",
                                          szAppName, MB_OK) ;
                              }
                         else
                              {
                              MessageBox (hwnd, "IUnknown not supported",
                                          szAppName, MB_OK) ;
                              }
                         return 0 ;
                         }

                    case IDM_IMALLOC :
                         {
                         LPUNKNOWN pUnk ;
                         HRESULT hr =
                              pMalloc->lpVtbl->QueryInterface (pMalloc,
                                                               IID_IMalloc,
                                                               (void **) &pUnk) ;
                         if (SUCCEEDED (hr))
                              {
                              pUnk->lpVtbl->Release (pUnk) ;
                              MessageBox (hwnd, "IMalloc supported",
                                          szAppName, MB_OK) ;
                              }
                         else
                              {
                              MessageBox (hwnd, "IMalloc not supported",
                                          szAppName, MB_OK) ;
                              }
                         return 0 ;
                         }

                    case IDM_IMARSHAL :
                         {
                         LPUNKNOWN pUnk ;
                         HRESULT hr =
                              pMalloc->lpVtbl->QueryInterface (pMalloc,
                                                               IID_IMarshal,
                                                               (void **) &pUnk) ;
                         if (SUCCEEDED (hr))
                              {
                              pUnk->lpVtbl->Release (pUnk) ;
                              MessageBox (hwnd, "IMarshal supported",
                                          szAppName, MB_OK) ;
                              }
                         else
                              {
                              MessageBox (hwnd, "IMarshal not supported",
                                          szAppName, MB_OK) ;
                              }
                         return 0 ;
                         }
.......
Alex
0
luisrCommented:
Creating the dialog based app is pretty easy... using the ActiveX control is not.

To display a dialog:

#include <Windows.h>

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hinstPrev, LPSTR pszCmdLine, int nCmdShow)
{
    return DialogBox(hInstance, ID_DIALOG, NULL, DialogProc);
}

BOOL CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
        case WM_INITDIALOG:
            return TRUE;

        case WM_COMMAND:
            if(LOWORD(wParam) == IDOK)
                EndDialog(hDlg, 0);
            return TRUE;
    }
    return FALSE;
}

You also have to create the dialog template in your RC file.

As for the ActiveX control part, I think ATL has support for control containers, but I am not sure.
0
mozdikCommented:
If you are using MS Visual C++, I suppose you create new project by sequence "File \ New \ MFC AppWizard".
If you want create new project without MFC, choose "File \ New \ Win32 Application". Type name of preject and choose "A typical Hello World application".
Maybe you want this. This is the first step. But I must agree with previous comments. It is dificult make COM without MFC support.
0
EgoreAuthor Commented:
Short and sweet, thanks.  I think that this one answers my question the best and I guess I'll have to learn MFC for the ActiveX support (although that's not too bad, I was just hoping it wouldn't be necessary...).  Anyway, thanks for all of the help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.