Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/150.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 按钮创建使Direct2Factory指针无效Windows C++;_C++_Pointers_Button_Graphics2d_Createwindowex - Fatal编程技术网

C++ 按钮创建使Direct2Factory指针无效Windows C++;

C++ 按钮创建使Direct2Factory指针无效Windows C++;,c++,pointers,button,graphics2d,createwindowex,C++,Pointers,Button,Graphics2d,Createwindowex,我正在MS Visual Studio 2017中编写一个windows应用程序,在使用Direct 2D Factory对象和按钮时遇到了一些问题。 如果我先创建direct 2D Factory对象,也就是说。 运行: 使用存储在“m_pDirect2dFactory”中的指针正确创建factory对象。 此对象指针在主窗口的创建过程中保持不变: m_hwnd = CreateWindowEx(0, ... 并通过创建子窗口: m_hwndRenderView = CreateWind

我正在MS Visual Studio 2017中编写一个windows应用程序,在使用Direct 2D Factory对象和按钮时遇到了一些问题。 如果我先创建direct 2D Factory对象,也就是说。 运行:

使用存储在“m_pDirect2dFactory”中的指针正确创建factory对象。 此对象指针在主窗口的创建过程中保持不变:

m_hwnd = CreateWindowEx(0, ...  
并通过创建子窗口:

m_hwndRenderView = CreateWindowEx(0, 
                                   L"AppChildWindow", 
                                   L"ChildWinName", WS_CHILD | WS_BORDER | WS_VISIBLE, 
                                   ...   
但是,当代码创建按钮时:

m_hwndButton = CreateWindow(L"BUTTON", 
                            TEXT("button name"),
                            WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
                            m_buttonStart_pixX,
                            cur_button_pixY,
                            button_pix_width,
                            button_pix_height,
                            m_hwnd,
                            (HMENU)(int)(CORE_BUTTON_IDSTART+1),
                            (HINSTANCE)GetWindowLong(m_hwnd, GWL_HINSTANCE),
                            NULL);
指针“m_pDirect2dFactory”的值更改为明显无效的值,这会在 m_pDirect2dFactory->Release() 被称为。 或者,换句话说,按钮的创建会篡改D2D1CreateFactory创建的factory对象


这是一个众所周知的问题吗

我们需要一个,可能您传递给
CreateWindow
的变量之一不正确,但由于我们不知道这些变量是什么,所以很难帮助。很抱歉回来这么晚。我自己发现了问题。首先,我简化了这个例子。在实际代码中,m_hwndButton=CreateWindow(…)实际上是一个循环m_hwndButton[i]=CreateWindow(…)。为m_hwndButton阵列保留的内存只有5个左右。然而,我试图创建10个m_Hwnd按钮窗口。发生这种情况时,我重写了对象中的下一个变量,它是带有hwnd窗口句柄的m_pDirect2dFactory指针,因此破坏了指针。
m_hwndButton = CreateWindow(L"BUTTON", 
                            TEXT("button name"),
                            WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
                            m_buttonStart_pixX,
                            cur_button_pixY,
                            button_pix_width,
                            button_pix_height,
                            m_hwnd,
                            (HMENU)(int)(CORE_BUTTON_IDSTART+1),
                            (HINSTANCE)GetWindowLong(m_hwnd, GWL_HINSTANCE),
                            NULL);