theOranger 2017-06-22 03:39 采纳率: 0%
浏览 1044
已结题

[window api] showwindow() 存在内存泄露

用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);
}

}

  • 写回答

1条回答 默认 最新

  • oyljerry 2017-06-22 09:39
    关注

    窗口资源可能没有完全回收,但是你不应该反复的创建销毁窗口啊。如果只是显示隐藏,可以对同一个窗口进行显示隐藏就可以了

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?