I have WinAPI application with menu. I click "Graphics" and choose open or draw. It doesn't matter what exactly. Then I close the child window. When I try to open it again, it doesn't work. Maybe I should put somewhere ShowWindow(hWnd, SW_HIDE). But I don't understand, where it should be. Maybe there is another solution
Here I'll put my code:
Callbacks, which I use
LRESULT CALLBACK DrawProcedure(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
switch (msg)
{
case WM_PAINT:
{
...
}
case WM_LBUTTONDOWN:
{
...
}
}
return DefWindowProc(hWnd, msg, wp, lp);
}
LRESULT CALLBACK GraphProcedure(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
switch (msg)
{
case WM_PAINT:
{
...
}
break;
case WM_CREATE:
...
case WM_SIZE:
...
}
return DefWindowProc(hWnd, msg, wp, lp);
}
LRESULT CALLBACK SoftwareMainProcedure(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
switch (msg)
{
case WM_COMMAND:
switch (wp)
{
case draw_plot:
GraphClass.style = CS_HREDRAW | CS_VREDRAW;
GraphClass.lpfnWndProc = DrawProcedure;
GraphClass.hInstance = hInst;
GraphClass.lpszMenuName = NULL;
GraphClass.lpszClassName = L"graphics";
if (!RegisterClassW(&GraphClass))
{
return -1;
}
gr_draw = CreateWindow(L"graphics", L"DRAW", WS_VISIBLE | WS_BORDER | WS_MAXIMIZE | WS_HSCROLL | WS_VSCROLL | WS_OVERLAPPEDWINDOW, 0, 0, 800, 700, NULL, NULL, hInst, NULL);
break;
case open_plot:
GraphClass.style = CS_HREDRAW | CS_VREDRAW;
GraphClass.lpfnWndProc = GraphProcedure;
GraphClass.hInstance = hInst;
GraphClass.lpszMenuName = NULL;
GraphClass.lpszClassName = L"graphics";
if (!RegisterClassW(&GraphClass))
{
return -1;
}
gr_open = CreateWindow(L"graphics", L"OPEN", WS_VISIBLE | WS_BORDER | WS_MAXIMIZE | WS_OVERLAPPEDWINDOW, 0, 0, 800, 700, NULL, NULL, hInst, NULL);
break;
case OnExitSoftware:
PostQuitMessage(0);
break;
default:
break;
}
break;
case WM_SIZE:
{
...
}
break;
case WM_CREATE:
MainWndAddMenus(hWnd);
MainWndAddWidgets(hWnd);
break;
case WM_DESTROY: // close mainwindow
ExitSoftware();
break;
default:
return DefWindowProc(hWnd, msg, wp, lp);
}
}