Add Windows support.

This commit is contained in:
david 2020-07-04 19:43:08 +01:00
parent ee51f3ee09
commit 683ba5447f
37 changed files with 477 additions and 113 deletions

View file

@ -5,7 +5,15 @@ target_include_directories(sample_gui PUBLIC
"${PROJECT_SOURCE_DIR}/src/client"
)
target_link_libraries(sample_gui PUBLIC client windows console core
network database geometry audio graphics web)
network database geometry audio web)
add_executable(sample_gui_win WIN32 gui-main-win.cpp)
target_include_directories(sample_gui PUBLIC
"${PROJECT_SOURCE_DIR}/src/console"
"${PROJECT_SOURCE_DIR}/src/client"
)
target_link_libraries(sample_gui_win PUBLIC client windows console core
network database geometry audio web)
# Sample Console
add_executable(sample_console console-main.cpp)
@ -21,4 +29,9 @@ target_include_directories(xml_practice PUBLIC
"${PROJECT_SOURCE_DIR}/src/core"
"${PROJECT_SOURCE_DIR}/src/web/xml"
)
target_link_libraries(xml_practice PUBLIC core web)
target_link_libraries(xml_practice PUBLIC core web)
set_property(TARGET sample_console PROPERTY FOLDER apps)
set_property(TARGET sample_gui PROPERTY FOLDER apps)
set_property(TARGET sample_gui_win PROPERTY FOLDER apps)
set_property(TARGET xml_practice PROPERTY FOLDER apps)

82
apps/audio-win.cpp Normal file
View file

@ -0,0 +1,82 @@
// LowLevelAudio.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include "Mmdeviceapi.h"
#include "Functiondiscoverykeys_devpkey.h"
#include <iostream>
const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
int main()
{
CoInitialize(nullptr);
IMMDeviceEnumerator* pEnumerator = nullptr;
IMMDeviceCollection* pDeviceCollection = nullptr;
HRESULT hr = S_OK;
hr = CoCreateInstance(CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL,
IID_IMMDeviceEnumerator, (void**)& pEnumerator);
if (!pEnumerator)
{
std::cout << "Failed to populate enumerator" << std::endl;
return 0;
}
hr = pEnumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &pDeviceCollection);
UINT count;
hr = pDeviceCollection->GetCount(&count);
if (count == 0)
{
std::cout << "No devices found\n";
}
// Each loop prints the name of an endpoint device.
IMMDevice* pEndpoint = nullptr;
IPropertyStore* pProps = nullptr;
LPWSTR pwszID = nullptr;
for (ULONG i = 0; i < count; i++)
{
// Get pointer to endpoint number i.
hr = pDeviceCollection->Item(i, &pEndpoint);
// Get the endpoint ID string.
hr = pEndpoint->GetId(&pwszID);
hr = pEndpoint->OpenPropertyStore(STGM_READ, &pProps);
PROPVARIANT varName;
// Initialize container for property value.
PropVariantInit(&varName);
// Get the endpoint's friendly-name property.
hr = pProps->GetValue(PKEY_Device_FriendlyName, &varName);
// Print endpoint friendly name and endpoint ID.
std::cout << "Endpoint: " << i << " " << varName.pwszVal << " " << pwszID << std::endl;
CoTaskMemFree(pwszID);
pwszID = nullptr;
PropVariantClear(&varName);
if (pProps)
{
pProps->Release();
pProps = nullptr;
}
if (pEndpoint)
{
pEndpoint->Release();
pEndpoint = nullptr;
}
}
if (pEnumerator)
{
pEnumerator->Release();
pEnumerator = nullptr;
}
if (pDeviceCollection)
{
pDeviceCollection->Release();
pDeviceCollection = nullptr;
}
return 0;
}

73
apps/gui-main-win.cpp Normal file
View file

@ -0,0 +1,73 @@
#ifndef UNICODE
#define UNICODE
#endif
#include "windows.h"
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
// Register the window class.
const wchar_t CLASS_NAME[] = L"Sample Window Class";
WNDCLASS wc = { };
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
HWND hwnd = CreateWindowEx(
0, // Optional window styles.
CLASS_NAME, // Window class
L"Learn to Program Windows", // Window text
WS_OVERLAPPEDWINDOW, // Window style
// Size and position
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, // Parent window
NULL, // Menu
hInstance, // Instance handle
NULL // Additional application data
);
if (hwnd == NULL)
{
return 0;
}
ShowWindow(hwnd, nCmdShow);
// Run the message loop.
MSG msg = { };
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 1));
EndPaint(hwnd, &ps);
}
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}