Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Initialise ActiveX Control without specifying pParentWnd...

Posted on 2003-12-11
14
Medium Priority
?
327 Views
Last Modified: 2013-11-20
Hi,

I have an application that utilises an array of MSComm controls.
These are defined in the main application code as...
   CMSComm myCommArray[5];

When I initialise the application I wish to 'Initialise' the control to check that it is registered and prepare it for use...
I use the command
   myCommArray[x].Create(NULL, WS_VISIBLE, CRect(0,0,0,0), m_pMainWnd, IDC_COM1+x);

This works fine when it is part of the InitInstance() function, after the window has been created and displayed.

I wish to move this code to the InitApplication() function so that it is called BEFORE any window is displayed...

I'm sure this is a fairly simple thing to achieve, but I am not sure how?

Any help would be appreciated...

Best regards,

James
0
Comment
Question by:James Atkin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 7
14 Comments
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 9919109
from an SDI app - InitInstance function of the App

      CSingleDocTemplate* pDocTemplate;
      pDocTemplate = new CSingleDocTemplate(
            IDR_MAINFRAME,
            RUNTIME_CLASS(CXxxDoc),
            RUNTIME_CLASS(CMainFrame),       // main SDI frame window
            RUNTIME_CLASS(CXxxView));
      AddDocTemplate(pDocTemplate);

      // Parse command line for standard shell commands, DDE, file open
      CCommandLineInfo cmdInfo;
      ParseCommandLine(cmdInfo);

      // Dispatch commands specified on the command line
      if (!ProcessShellCommand(cmdInfo))
            return FALSE;

//********************************************
PUT YOUR INITIALISATION HERE - window is created but not yet shown


      // The one and only window has been initialized, so show and update it.
      m_pMainWnd->ShowWindow(SW_SHOW);
      m_pMainWnd->UpdateWindow();
0
 
LVL 4

Author Comment

by:James Atkin
ID: 9919252
That's not how the Wizard created my SDI app...  I have ...

   CSingleDocTemplate* pDocTemplate;                         <- ***Window is automatically shown at this point***
   pDocTemplate = new CSingleDocTemplate(
      IDR_MAINFRAME,
      RUNTIME_CLASS(CxxxDoc),
      RUNTIME_CLASS(CMainFrame),
      RUNTIME_CLASS(CxxxView));
   AddDocTemplate(pDocTemplate);

   EnableShellOpen();
   RegisterShellFileTypes(TRUE);

   CCommandLineInfo cmdInfo;
   ParseCommandLine(cmdInfo);

   if (!ProcessShellCommand(cmdInfo))
      return FALSE;

   // The one and only window has been initialized, so update it.
   m_pMainWnd->UpdateWindow();      

Any ideas?
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 9919811
Hmm.
Does it have to be in the InitInstance of the app?
A view has a function OnInitialUpdate that is called once (I think before the window is shown).  That could be a place to put the code.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 4

Author Comment

by:James Atkin
ID: 9920139
It doesn't matter where it it - providing the Window is not visible at the time...

OnInitialUpdate does not appear to be part of CWinApp though - would this be in the CFrameWnd?
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 9920167
Its a view function
0
 
LVL 45

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 9920174
Select your view - add a virtual function - OnInitialUpdate should be one of the choices available
0
 
LVL 4

Author Comment

by:James Atkin
ID: 9920194
Cool, got it - it DOES execute before the Main window is displayed so I'll try moving the required code to there...  Let you know the result shortly...
0
 
LVL 4

Author Comment

by:James Atkin
ID: 9920365
Ok,

That works nicely!  

Is there a way (being a little fussy now) to stop the Main Window flashing up as the termination is proceeding?  I currently set a flag in the main App to say the initialisation has failed, and after returning from the ProcessShellCommand function, this flag is set and I return FALSE from InitInstance().

I guess that if it was possible to return FALSE to the ProcessShellCommand function, it might do it, but I have no idea how to do this !!!

I am accepting your above comment as the answer though as it works quite nicely - the 'Non-Flash' is one of those "Wonder if you can do that" sort of questions  ;-)

Thanks for the help...

James
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 9920419
Would it not be nicer for the user that the app appears, a messagebox giving some sort of error message appears (In the InitInstance) and then you return false to kill the app.  The user knows it attempted to start rather than a blank screen and the user thinks why didn't it start and tries again.
0
 
LVL 4

Author Comment

by:James Atkin
ID: 9920446
Part of the Initialisation is a Login procedure.  If this is cancelled or fails, the Login Class will display the appropriate message to the user - displaying a message in InitInstance will duplicate the information already given to the user during Login.
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 9920563
OK.
There ought to be a way but I can't think of it at present.  

Just a guess
In the OnCreate  of the MainFrame you get a parameter of type
CREATESTRUCT Structure
The CREATESTRUCT structure has the following form:

typedef struct tagCREATESTRUCT {
   LPVOID    lpCreateParams;
   HANDLE    hInstance;
   HMENU     hMenu;
   HWND      hwndParent;
   int       cy;
   int       cx;
   int       y;
   int       x;
   LONG      style;
   LPCSTR    lpszName;
   LPCSTR    lpszClass;
   DWORD     dwExStyle;
} CREATESTRUCT;


Try modifying the style member so it is a hidden window, if your creation of the controls in the view succeeds then add
m_pmainWnd->ShowWindow(SW_SHOW) before the UpdateWindow() call in InitInstance.
0
 
LVL 4

Author Comment

by:James Atkin
ID: 9920877
What's the style for 'Hidden Window' ?  Do you just exclude WS_VISIBLE?
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 9920894
yes - it might work, not tried it here
0
 
LVL 4

Author Comment

by:James Atkin
ID: 9928580
I've tried the following in MainFrame...

   int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
   {
      long tmpStyle = lpCreateStruct->style;
      tmpStyle = tmpStyle & ~WS_VISIBLE;
      lpCreateStruct->style = tmpStyle;

      if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1;

      return 0;
   }

But the window still appears briefly...

As I said, not urgent (you've earned your points) but if you have any ideas, please let me know...

James
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Suggested Courses

636 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