?
Solved

Windows Programming WITHOUT MFC

Posted on 1999-12-07
11
Medium Priority
?
435 Views
Last Modified: 2013-11-25
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)
0
Comment
Question by:Egore
11 Comments
 
LVL 2

Expert Comment

by:Gandalf32
ID: 2263155
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
 
LVL 2

Expert Comment

by:Gandalf32
ID: 2263162
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
 
LVL 23

Expert Comment

by:chensu
ID: 2263216
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 32

Expert Comment

by:jhance
ID: 2263485
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
 
LVL 4

Accepted Solution

by:
yowkee earned 600 total points
ID: 2263879
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
 
LVL 3

Expert Comment

by:GlennDean
ID: 2264201
 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
 
LVL 23

Expert Comment

by:chensu
ID: 2264230
>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
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 2265496
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
 
LVL 3

Expert Comment

by:luisr
ID: 2266400
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
 

Expert Comment

by:mozdik
ID: 2268121
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
 
LVL 3

Author Comment

by:Egore
ID: 2273665
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

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question