Я работаю над приложением c ++ (через сообщество Visual Studio) для Windows 10. Приложение отображает другое изображение на всех своих windows каждые 40 мс, чтобы сделать его похожим на видео. Для этого я использую DirectX9 с текстурой.
проблема: когда экран (дисплей, монитор) отключен, программа (приложение c ++) зависает в своем окне после повторного подключения экрана (дисплей, монитор).
В чем может быть проблема? У вас есть идея?
bool GenerateWindow(HINSTANCE hInstance, int nCmdShow, LPCWSTR className, LPCWSTR windowTitle, int x, int y, int widht, int height, HWND& hWnd);
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
Game* game;
const std::chrono::milliseconds intervalPeriodMillis{ 40 };
std::chrono::system_clock::time_point currentStartTime{ std::chrono::system_clock::now() };
std::chrono::system_clock::time_point nextStartTime{ currentStartTime };
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
bool fDone;
HWND hWnd;
if (GenerateWindow(hInstance, nCmdShow, L"Direct3D", L"Myprog", 9, 6, 1792, 128, hWnd))
{
MSG msg;
game = new Game();
if (game->Initialize(hWnd))
{
fDone = false;
while (!fDone)
{
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
{
fDone = true;
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
game->Run();
std::this_thread::sleep_until(nextStartTime);
currentStartTime = std::chrono::system_clock::now();
nextStartTime = (currentStartTime + intervalPeriodMillis);
}
delete game;
}
}
return 0;
}
bool GenerateWindow(HINSTANCE hInstance, int nCmdShow, LPCWSTR className, LPCWSTR windowTitle, int x, int y, int widht, int height, HWND& hWnd) {
WNDCLASSEX wcex;
ZeroMemory(&wcex, sizeof(WNDCLASSEX));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WindowProc;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)COLOR_WINDOW;
wcex.lpszClassName = className;
wcex.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
if (!RegisterClassEx(&wcex))
{
return false;
}
RECT rect = { 0,0,widht,height };
AdjustWindowRectEx(&rect, WS_OVERLAPPEDWINDOW, false, WS_EX_OVERLAPPEDWINDOW);
hWnd = CreateWindowEx(
WS_EX_OVERLAPPEDWINDOW,
className,
windowTitle,
WS_OVERLAPPEDWINDOW,
x, y,
rect.right - rect.left,
rect.bottom - rect.top,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd, nCmdShow);
return true;
}
//windowProc - Handles input sent to the window
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CLOSE:
DestroyWindow(hWnd);
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}