Examples: DirectX9/10/11: Renamed WndProc handler to use a generic Win32 name + returning 0 to all messages is more correct.

This commit is contained in:
omar 2017-10-23 09:57:59 +02:00
parent cb10da02f9
commit c14a66970b
6 changed files with 42 additions and 42 deletions

View File

@ -234,7 +234,7 @@ static bool IsAnyMouseButtonDown()
return false; return false;
} }
IMGUI_API LRESULT ImGui_ImplDX10_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
switch (msg) switch (msg)
@ -242,47 +242,47 @@ IMGUI_API LRESULT ImGui_ImplDX10_WndProcHandler(HWND hwnd, UINT msg, WPARAM wPar
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:
if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd);
io.MouseDown[0] = true; io.MouseDown[0] = true;
return true; return 0;
case WM_RBUTTONDOWN: case WM_RBUTTONDOWN:
if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd);
io.MouseDown[1] = true; io.MouseDown[1] = true;
return true; return 0;
case WM_MBUTTONDOWN: case WM_MBUTTONDOWN:
if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd);
io.MouseDown[2] = true; io.MouseDown[2] = true;
return true; return 0;
case WM_LBUTTONUP: case WM_LBUTTONUP:
io.MouseDown[0] = false; io.MouseDown[0] = false;
if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); if (!IsAnyMouseButtonDown()) ::ReleaseCapture();
return true; return 0;
case WM_RBUTTONUP: case WM_RBUTTONUP:
io.MouseDown[1] = false; io.MouseDown[1] = false;
if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); if (!IsAnyMouseButtonDown()) ::ReleaseCapture();
return true; return 0;
case WM_MBUTTONUP: case WM_MBUTTONUP:
io.MouseDown[2] = false; io.MouseDown[2] = false;
if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); if (!IsAnyMouseButtonDown()) ::ReleaseCapture();
return true; return 0;
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:
io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f; io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f;
return true; return 0;
case WM_MOUSEMOVE: case WM_MOUSEMOVE:
io.MousePos.x = (signed short)(lParam); io.MousePos.x = (signed short)(lParam);
io.MousePos.y = (signed short)(lParam >> 16); io.MousePos.y = (signed short)(lParam >> 16);
return true; return 0;
case WM_KEYDOWN: case WM_KEYDOWN:
if (wParam < 256) if (wParam < 256)
io.KeysDown[wParam] = 1; io.KeysDown[wParam] = 1;
return true; return 0;
case WM_KEYUP: case WM_KEYUP:
if (wParam < 256) if (wParam < 256)
io.KeysDown[wParam] = 0; io.KeysDown[wParam] = 0;
return true; return 0;
case WM_CHAR: case WM_CHAR:
// You can also use ToAscii()+GetKeyboardState() to retrieve characters. // You can also use ToAscii()+GetKeyboardState() to retrieve characters.
if (wParam > 0 && wParam < 0x10000) if (wParam > 0 && wParam < 0x10000)
io.AddInputCharacter((unsigned short)wParam); io.AddInputCharacter((unsigned short)wParam);
return true; return 0;
} }
return 0; return 0;
} }

View File

@ -74,10 +74,10 @@ void CleanupDeviceD3D()
if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; } if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; }
} }
extern LRESULT ImGui_ImplDX10_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
if (ImGui_ImplDX10_WndProcHandler(hWnd, msg, wParam, lParam)) if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam))
return true; return true;
switch (msg) switch (msg)

View File

@ -241,7 +241,7 @@ static bool IsAnyMouseButtonDown()
return false; return false;
} }
IMGUI_API LRESULT ImGui_ImplDX11_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
switch (msg) switch (msg)
@ -249,47 +249,47 @@ IMGUI_API LRESULT ImGui_ImplDX11_WndProcHandler(HWND hwnd, UINT msg, WPARAM wPar
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:
if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd);
io.MouseDown[0] = true; io.MouseDown[0] = true;
return true; return 0;
case WM_RBUTTONDOWN: case WM_RBUTTONDOWN:
if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd);
io.MouseDown[1] = true; io.MouseDown[1] = true;
return true; return 0;
case WM_MBUTTONDOWN: case WM_MBUTTONDOWN:
if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd);
io.MouseDown[2] = true; io.MouseDown[2] = true;
return true; return 0;
case WM_LBUTTONUP: case WM_LBUTTONUP:
io.MouseDown[0] = false; io.MouseDown[0] = false;
if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); if (!IsAnyMouseButtonDown()) ::ReleaseCapture();
return true; return 0;
case WM_RBUTTONUP: case WM_RBUTTONUP:
io.MouseDown[1] = false; io.MouseDown[1] = false;
if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); if (!IsAnyMouseButtonDown()) ::ReleaseCapture();
return true; return 0;
case WM_MBUTTONUP: case WM_MBUTTONUP:
io.MouseDown[2] = false; io.MouseDown[2] = false;
if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); if (!IsAnyMouseButtonDown()) ::ReleaseCapture();
return true; return 0;
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:
io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f; io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f;
return true; return 0;
case WM_MOUSEMOVE: case WM_MOUSEMOVE:
io.MousePos.x = (signed short)(lParam); io.MousePos.x = (signed short)(lParam);
io.MousePos.y = (signed short)(lParam >> 16); io.MousePos.y = (signed short)(lParam >> 16);
return true; return 0;
case WM_KEYDOWN: case WM_KEYDOWN:
if (wParam < 256) if (wParam < 256)
io.KeysDown[wParam] = 1; io.KeysDown[wParam] = 1;
return true; return 0;
case WM_KEYUP: case WM_KEYUP:
if (wParam < 256) if (wParam < 256)
io.KeysDown[wParam] = 0; io.KeysDown[wParam] = 0;
return true; return 0;
case WM_CHAR: case WM_CHAR:
// You can also use ToAscii()+GetKeyboardState() to retrieve characters. // You can also use ToAscii()+GetKeyboardState() to retrieve characters.
if (wParam > 0 && wParam < 0x10000) if (wParam > 0 && wParam < 0x10000)
io.AddInputCharacter((unsigned short)wParam); io.AddInputCharacter((unsigned short)wParam);
return true; return 0;
} }
return 0; return 0;
} }

View File

@ -77,10 +77,10 @@ void CleanupDeviceD3D()
if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; } if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; }
} }
extern LRESULT ImGui_ImplDX11_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
if (ImGui_ImplDX11_WndProcHandler(hWnd, msg, wParam, lParam)) if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam))
return true; return true;
switch (msg) switch (msg)

View File

@ -181,7 +181,7 @@ static bool IsAnyMouseButtonDown()
} }
// We use Win32 SetCapture/ReleaseCapture() API to enable reading the mouse outside our Windows bounds. // We use Win32 SetCapture/ReleaseCapture() API to enable reading the mouse outside our Windows bounds.
IMGUI_API LRESULT ImGui_ImplDX9_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) IMGUI_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
switch (msg) switch (msg)
@ -189,47 +189,47 @@ IMGUI_API LRESULT ImGui_ImplDX9_WndProcHandler(HWND hwnd, UINT msg, WPARAM wPara
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:
if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd);
io.MouseDown[0] = true; io.MouseDown[0] = true;
return true; return 0;
case WM_RBUTTONDOWN: case WM_RBUTTONDOWN:
if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd);
io.MouseDown[1] = true; io.MouseDown[1] = true;
return true; return 0;
case WM_MBUTTONDOWN: case WM_MBUTTONDOWN:
if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd); if (!IsAnyMouseButtonDown()) ::SetCapture(hwnd);
io.MouseDown[2] = true; io.MouseDown[2] = true;
return true; return 0;
case WM_LBUTTONUP: case WM_LBUTTONUP:
io.MouseDown[0] = false; io.MouseDown[0] = false;
if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); if (!IsAnyMouseButtonDown()) ::ReleaseCapture();
return true; return 0;
case WM_RBUTTONUP: case WM_RBUTTONUP:
io.MouseDown[1] = false; io.MouseDown[1] = false;
if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); if (!IsAnyMouseButtonDown()) ::ReleaseCapture();
return true; return 0;
case WM_MBUTTONUP: case WM_MBUTTONUP:
io.MouseDown[2] = false; io.MouseDown[2] = false;
if (!IsAnyMouseButtonDown()) ::ReleaseCapture(); if (!IsAnyMouseButtonDown()) ::ReleaseCapture();
return true; return 0;
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:
io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f; io.MouseWheel += GET_WHEEL_DELTA_WPARAM(wParam) > 0 ? +1.0f : -1.0f;
return true; return 0;
case WM_MOUSEMOVE: case WM_MOUSEMOVE:
io.MousePos.x = (signed short)(lParam); io.MousePos.x = (signed short)(lParam);
io.MousePos.y = (signed short)(lParam >> 16); io.MousePos.y = (signed short)(lParam >> 16);
return true; return 0;
case WM_KEYDOWN: case WM_KEYDOWN:
if (wParam < 256) if (wParam < 256)
io.KeysDown[wParam] = 1; io.KeysDown[wParam] = 1;
return true; return 0;
case WM_KEYUP: case WM_KEYUP:
if (wParam < 256) if (wParam < 256)
io.KeysDown[wParam] = 0; io.KeysDown[wParam] = 0;
return true; return 0;
case WM_CHAR: case WM_CHAR:
// You can also use ToAscii()+GetKeyboardState() to retrieve characters. // You can also use ToAscii()+GetKeyboardState() to retrieve characters.
if (wParam > 0 && wParam < 0x10000) if (wParam > 0 && wParam < 0x10000)
io.AddInputCharacter((unsigned short)wParam); io.AddInputCharacter((unsigned short)wParam);
return true; return 0;
} }
return 0; return 0;
} }

View File

@ -12,10 +12,10 @@
static LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; static LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
static D3DPRESENT_PARAMETERS g_d3dpp; static D3DPRESENT_PARAMETERS g_d3dpp;
extern LRESULT ImGui_ImplDX9_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
if (ImGui_ImplDX9_WndProcHandler(hWnd, msg, wParam, lParam)) if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam))
return true; return true;
switch (msg) switch (msg)