用window api 不断地创建窗口显示窗口释放窗口,会存在内存泄露,查了很多资料都没有找到解决办法,有没有大牛帮一下忙?
void CTest1Dlg::initWnd(int screenWidth, int screenHeight, HWND parent)
{
WNDCLASSEX wc;
int posX = 0, posY = 0;
// Get an external pointer to this object.
//ApplicationHandle = this;
// Get the instance of this application.
m_hinstance = GetModuleHandle(NULL);
// Give the application a name.
m_applicationName = L"Ticker";
// Setup the windows class with default settings.
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = m_hinstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hIconSm = wc.hIcon;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = m_applicationName;
wc.cbSize = sizeof(WNDCLASSEX);
// Register the window class.
RegisterClassEx(&wc);
// Create the window with the screen settings and get the handle to it.
m_hwnd = CreateWindow(m_applicationName, m_applicationName,
WS_POPUP,
posX, posY, screenWidth, screenHeight, parent, NULL, m_hinstance, NULL);
//::SetProcessWorkingSetSize(m_hwnd,-1,-1);
::ShowWindow(m_hwnd, SW_HIDE);
}
void CTest1Dlg::ReleaseWnd()
{
::DestroyWindow(m_hwnd);
m_hwnd = NULL;
if (!UnregisterClass(m_applicationName, m_hinstance))
{
auto err = GetLastError();
}
if (m_hinstance != NULL)
{
FreeLibrary(m_hinstance);
m_hinstance = NULL;
}
}
void CTest1Dlg::OnBnClickedOk()
{
// TODO: 在此添加控件通知处理程序代码
//CDialogEx::OnOK();
HWND hWnd = this->GetSafeHwnd();
while (1)
{
initWnd(100, 100, hWnd);
::ShowWindow(m_hwnd, SW_SHOW);
ReleaseWnd();
//Sleep(100);
}
}