none
Create window method of the class CWindowImpl causing crash in application RRS feed

  • Question

  • Hi Team,

    I am using Create window method of the class CWindowImpl in C++ application (Application is build using Visual studio 6.0 and running on Windows 10). Below is my calling format for the method.

    This call causes the application to crash,

    m_hmyWnd = Create(::GetDesktopWindow(), rect, NULL, WS_CHILD);

    GetDesktopWindow() when called independently is working well. Can you please help me to identify the issue?

    Thank you,

    Prasad


    Prasad B

    Monday, April 1, 2019 10:17 AM

All replies

  • Hello,

    GetDesktopWindow returns the full screen: https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getdesktopwindow

    You cannot create a child window of the Desktop window. You can only create child windows of your current app.

    What do you want to achieve with your Create-Call?

    Regards, Guido

    Monday, April 1, 2019 10:29 AM
  • Thank you for the response and suggestion.

    I am trying to create the hidden window by setting the rect to zero as below,

    rect.left = 0;
    rect.right = 0;
    rect.top = 0;
    rect.bottom = 0;

    Based on you suggestions, I tried to call the Create as below, and it worked.

    m_hmyWnd = Create(NULL, rect, NULL, NULL);


    Prasad B

    Tuesday, April 2, 2019 7:03 AM
  • Thank you for the response and suggestion.

    I am trying to create the hidden window by setting the rect to zero as below,

    rect.left = 0;
    rect.right = 0;
    rect.top = 0;
    rect.bottom = 0;

    Based on you suggestions, I tried to call the Create as below, and it worked.

    m_hmyWnd = Create(NULL, rect, NULL, NULL);


    Prasad B

    Depending on how you declared the ATL Window class derived from CWindowImpl your window may not be visible for more than one reason.  It may be a child window with 0 height and 0 width or it might not be a child window and received default dimensions but does not have the WS_VISIBLE style.

    The following examples assume that you have passed a window handle as the first parameter to the create function (necessary for child window). If you pass NULL as the window handle to the create function of CHiddenWinow the window will have default dimension but be hidden.

    For example, this creates a child window with 0 height and 0 width but has the WS_VISIBLE style -

    class CZeroWindow : public CWindowImpl<CZeroWindow, CWindow>
    {
    public:
    	DECLARE_WND_CLASS(L"ZeroWindow");
    	BEGIN_MSG_MAP(CZeroWindow)
    	END_MSG_MAP()
    };

    while this creates a top-level window that has default dimensions set by Windows but lacks the WS_VISIBLE style -

    class CHiddenWindow : public CWindowImpl<CHiddenWindow, CWindow, CFrameWinTraits>
    {
    public:
    	DECLARE_WND_CLASS(L"HiddenFrame");
    	BEGIN_MSG_MAP(CHiddenWindow)
    	END_MSG_MAP()
    };

    You can see the difference in how Spy++ shows the two windows - The frame window that is actually hidden is grayed out while the child window that has no dimension is not.

    And in the window tree notice that the hidden frame window is an owned window, not a child window  -



    Tuesday, April 2, 2019 10:57 AM
  • Thank you for this information.

    I tried creating the window using above two examples,

    1) I observed below example created a child window with 0 height and 0 width but has the WS_VISIBLE style.

    I used a call to, Create(::GetDesktopWindow(), rect, NULL, NULL); to get the window handle.

    class CZeroWindow : public CWindowImpl<CZeroWindow, CWindow>
    {
    public:
    	DECLARE_WND_CLASS(L"ZeroWindow");
    	BEGIN_MSG_MAP(CZeroWindow)
    	END_MSG_MAP()
    };

    2) Also I see below example created a top-level window that has default dimensions set by Windows but lacks the WS_VISIBLE style.

    I used a call to, Create(NULL, rect, NULL, NULL); to get the window handle.

    class CHiddenWindow : public CWindowImpl<CHiddenWindow, CWindow, CFrameWinTraits>
    {
    public:
    	DECLARE_WND_CLASS(L"HiddenFrame");
    	BEGIN_MSG_MAP(CHiddenWindow)
    	END_MSG_MAP()
    };

    I am interested in implementing second example.

    This implementation is part of one dll (COM DLL built in Visual studio 6.0) which is used by different applications. Current I have two applications one is build in VB6.0 and other is Office excel 2016 with macro having backend as VB6.0 code.

    Application built with VB6.0 --> The second implementation is successful.

    Office excel 2016 with macro having backend as VB6.0 code. --> The second implementation fails and excel crashes.

    Please provide guidance on this case.


    Prasad B

    Thursday, April 18, 2019 11:19 AM
  • I am interested in implementing second example.

    This implementation is part of one dll (COM DLL built in Visual studio 6.0) which is used by different applications. Current I have two applications one is build in VB6.0 and other is Office excel 2016 with macro having backend as VB6.0 code.

    Application built with VB6.0 --> The second implementation is successful.

    Office excel 2016 with macro having backend as VB6.0 code. --> The second implementation fails and excel crashes.

    Please provide guidance on this case.

    First, if your initial question has been answered then you should mark the answer to close this thread.

    From the above comments it is unclear whether you should pursue resolution of the "excel crash" in the Excel for Developers forum or at some other site that supports VB6.

    Thursday, April 18, 2019 1:52 PM
  • No my initial question is not completely answered. I want some guidance on why Create method is failing when it is called in below way,

    Office excel 2016 with macro having backend as VB6.0 code calls a function in my  C++ dll which uses create method. But it works when a different VB6.0 application calls a function in my C++ dll which uses same create method.


    Prasad B

    Sunday, April 21, 2019 6:39 AM
  • No my initial question is not completely answered. I want some guidance on why Create method is failing when it is called in below way,

    Office excel 2016 with macro having backend as VB6.0 code calls a function in my  C++ dll which uses create method. But it works when a different VB6.0 application calls a function in my C++ dll which uses same create method.


    Prasad B

    The initial question said nothing about Excel or VB6.  It referred to a C++ application.

    There is insufficient information to attempt to diagnose an Excel/vb6 problem and, in any event, this is not the appropriate forum in which the issue should be pursued.



    • Edited by RLWA32 Sunday, April 21, 2019 9:50 AM
    Sunday, April 21, 2019 9:43 AM