Create window form C++ function using MFC or Win32 API - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18

Thread: Create window form C++ function using MFC or Win32 API

  1. #16
    Join Date
    Jan 2013
    Location
    Lausanne, Switzerland
    Posts
    35

    Re: Create window form C++ function using MFC or Win32 API

    Quote Originally Posted by Paul McKenzie View Post
    There are thousands of these examples all over the Internet. Or get a good book, such as the ones written by Charles Petzold.
    Hello Paul. Thank you for response. If you show me just one, that correspond to my case I will be very grateful. FYI my case is:
    • creation of a GUI inside of a DLL
    • DLL is called by a particular CAD tool
    • the CAD interface for DLL call isn't on my control


    Regards

    Pavel

  2. #17
    Join Date
    Jan 2013
    Location
    Lausanne, Switzerland
    Posts
    35

    Re: Create window form C++ function using MFC or Win32 API

    Thanks Ovidiu,

    I programmed in C++ about 15 years ago, so some basic things are forgotten.
    Finally I've found workaround. Here is code that works (in sense simple window is displayed).
    Thanks to all participants !
    Best Regards.
    Pavel.

    Code:
    #include "stdafx.h"
    #include "vpi_MFC_regular.h"
    #include "vpi_user.h"
    
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #endif
    
    // Cvpi_MFC_regularApp
    
    BEGIN_MESSAGE_MAP(Cvpi_MFC_regularApp, CWinApp)
    END_MESSAGE_MAP()
    
    // Cvpi_MFC_regularApp construction
    
    Cvpi_MFC_regularApp::Cvpi_MFC_regularApp()
    {
    	vpi_printf("Inside of Application Constructor\n");
    }
    
    
    // The one and only Cvpi_MFC_regularApp object
    
    Cvpi_MFC_regularApp theApp;
    
    class CMyWindow : public CFrameWnd
    {
    	CStatic* cs;
    public:
    	CMyWindow();
    };
    
    CMyWindow::CMyWindow()
    {
    	Create(NULL, L"MyWindow", WS_VISIBLE, CRect(0,0,200,200));
    	cs = new CStatic();
    	cs->Create(L"AAAAAAAAAAAAAA", WS_CHILD|WS_VISIBLE|SS_CENTER, CRect(50, 80, 150, 150), this);
    	vpi_printf("Inside of Window Constructor\n");
    }
    
    // Cvpi_MFC_regularApp initialization
    BOOL Cvpi_MFC_regularApp::InitInstance()
    {
    	vpi_printf("Inside of Application InitInstance\n");
    	CWinApp::InitInstance();
    	m_pMainWnd = new CMyWindow();
    	m_pMainWnd->ShowWindow(SW_SHOW);
    	m_pMainWnd->UpdateWindow();
    	return TRUE;
    }
    
    PLI_INT32 vpi_CreateWindow(PLI_BYTE8 *user_data)
    {
    	vpi_printf("Inside of vpi_CreateWindow\n");
    	return 0;
    }

  3. #18
    Join Date
    Apr 1999
    Posts
    27,444

    Re: Create window form C++ function using MFC or Win32 API

    Quote Originally Posted by Pavel_47 View Post
    Hello Paul. Thank you for response. If you show me just one, that correspond to my case I will be very grateful. FYI my case is:
    • creation of a GUI inside of a DLL
    • DLL is called by a particular CAD tool
    • the CAD interface for DLL call isn't on my control
    Can you create a GUI, regardless of whether it is in a DLL or not? You are trying to run a marathon, but have not learned how to walk.

    Windows programming cannot be picked up by cobbling code together, and programming experience in whatever language doesn't automatically guarantee you can write a Windows program. You could be a C++ programmer for many years, if you haven't done event-driven programming, it is going to be brand new to you, and that takes time to learn. To learn Windows programming properly requires knowing and running working examples, regardless of what your final goal is.

    If you can't do the basics, how are you going to accomplish anything from there? You create the GUI and you display the window and wait for events to be processed by the window procedure. It is no different for an app than it is for a DLL. The only difference of note is that the resources to create the Window would normally reside in the DLL's resources and not the main app's resources.

    As for real-life examples, do you own a TWAIN device or scanner? Well, they work exactly the same way as you described. The user interface is implemented in a DLL provided by the manufacturer, and this GUI is initiated by the application (more exactly, the TWAIN manager).

    But to get to this stage, you need to be a solid Windows programmer, or at the very least, know the fundamentals enough to not have to make serioous errors such as writing incorrect message loops, never calling GetLastError() if there is an issue, etc. All of these mistakes are corrected by looking at working code and studying it properly.

    Regards,

    Paul McKenzie

Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center