Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs] Add a basic example #3

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions ExampleBasic/ExampleBasic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* WGC-Capture-with-OpenCV
*
* Copyright 2023-2024 Tyler Parret True
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @Authors
* Tyler Parret True <mysteryworldgod@outlook.com><https://github.com/OwlHowlinMornSky>
*/

// You can use Spy++ to get the info about target window.
constexpr wchar_t TargetWindowName[] = L"ExampleName";
constexpr wchar_t TargetWindowClass[] = L"ExampleClassName";

#include <ohms/WGC.h>
#include <opencv2/opencv.hpp>
#include <Windows.h>

int main() {
// Initialization.
ohms::wgc::ICapture::setup(false);
auto r_capture = ohms::wgc::ICapture::getInstance();
// Find Window.
HWND hwnd = FindWindowW(TargetWindowClass, TargetWindowName);
if (hwnd == NULL) {
return 1;
}
if (!IsWindow(hwnd) || IsIconic(hwnd)) { // Requirements for capture.
return 2;
}
if (!r_capture->startCapture(hwnd)) {
return 3;
}
r_capture->setClipToClientArea(true);
// Run
r_capture->askForRefresh(); // Ask for the first.
MSG msg{ 0 };
size_t testCnt = 3300; // About 100 seconds.
while (testCnt > 0) {
if (PeekMessageW(&msg, NULL, NULL, NULL, PM_REMOVE)) { // Neccessary for get frames.
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
else {
if (r_capture->isRefreshed()) {
cv::Mat mat;
if (r_capture->copyMatTo(mat, false)) {
cv::imshow("show", mat);
}
r_capture->askForRefresh(); // Ask for next one.
}
Sleep(30);
--testCnt;
}
}
// Clear.
ohms::wgc::ICapture::drop();
return 0;
}

90 changes: 90 additions & 0 deletions ExampleBasic/ExampleBasic.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{df2c7211-c422-40fb-9fa3-0f085ce2e93b}</ProjectGuid>
<RootNamespace>ExampleBasic</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<AdditionalIncludeDirectories>$(SolutionDir)WGC-Capture-with-OpenCV\include;$(OHMS_LIB_DIR)\opencv\4.8.0\build\include;</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(OHMS_LIB_DIR)\opencv\4.8.0\build\x64\vc16\lib;</AdditionalLibraryDirectories>
<AdditionalDependencies>dwmapi.lib;$(OutDir)wgc-capture-d.lib;opencv_world480d.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<AdditionalIncludeDirectories>$(SolutionDir)WGC-Capture-with-OpenCV\include;$(OHMS_LIB_DIR)\opencv\4.8.0\build\include;</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>$(OHMS_LIB_DIR)\opencv\4.8.0\build\x64\vc16\lib;</AdditionalLibraryDirectories>
<AdditionalDependencies>dwmapi.lib;$(OutDir)wgc-capture.lib;opencv_world480.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="ExampleBasic.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
22 changes: 22 additions & 0 deletions ExampleBasic/ExampleBasic.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ExampleBasic.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion ExampleWin32/ExampleWin32.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<Filter>MainWindow\Header</Filter>
</ClInclude>
<ClInclude Include="Resource.h">
<Filter>Header Files</Filter>
<Filter>Resource Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
Expand Down
22 changes: 21 additions & 1 deletion ExampleWin32/Window/Macro.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
#pragma once
/*
* WGC-Capture-with-OpenCV
*
* Copyright 2023-2024 Tyler Parret True
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @Authors
* Tyler Parret True <mysteryworldgod@outlook.com><https://github.com/OwlHowlinMornSky>
*/
#pragma once

#define WM_OHMS_REFRESH_COMBOX (WM_USER + 1)
#define WM_OHMS_STOP_CAPTURE (WM_USER + 2)
22 changes: 21 additions & 1 deletion ExampleWin32/Window/MainWindow.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
#include "MainWindow.h"
/*
* WGC-Capture-with-OpenCV
*
* Copyright 2023-2024 Tyler Parret True
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @Authors
* Tyler Parret True <mysteryworldgod@outlook.com><https://github.com/OwlHowlinMornSky>
*/
#include "MainWindow.h"

#include <opencv2/opencv.hpp>

Expand Down
22 changes: 21 additions & 1 deletion ExampleWin32/Window/MainWindow.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
#pragma once
/*
* WGC-Capture-with-OpenCV
*
* Copyright 2023-2024 Tyler Parret True
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @Authors
* Tyler Parret True <mysteryworldgod@outlook.com><https://github.com/OwlHowlinMornSky>
*/
#pragma once

#include "Window.h"
#include "WndEnumeration.h"
Expand Down
22 changes: 21 additions & 1 deletion ExampleWin32/Window/Window.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
#include "Window.h"
/*
* WGC-Capture-with-OpenCV
*
* Copyright 2023-2024 Tyler Parret True
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @Authors
* Tyler Parret True <mysteryworldgod@outlook.com><https://github.com/OwlHowlinMornSky>
*/
#include "Window.h"

namespace {

Expand Down
22 changes: 21 additions & 1 deletion ExampleWin32/Window/Window.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
#pragma once
/*
* WGC-Capture-with-OpenCV
*
* Copyright 2023-2024 Tyler Parret True
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @Authors
* Tyler Parret True <mysteryworldgod@outlook.com><https://github.com/OwlHowlinMornSky>
*/
#pragma once

#include "../framework.h"

Expand Down
22 changes: 21 additions & 1 deletion ExampleWin32/Window/WindowFactory.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
#include "Window.h"
/*
* WGC-Capture-with-OpenCV
*
* Copyright 2023-2024 Tyler Parret True
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @Authors
* Tyler Parret True <mysteryworldgod@outlook.com><https://github.com/OwlHowlinMornSky>
*/
#include "Window.h"
#include "MainWindow.h"

namespace ohms {
Expand Down
22 changes: 21 additions & 1 deletion ExampleWin32/Window/WndEnumeration.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
#include "WndEnumeration.h"
/*
* WGC-Capture-with-OpenCV
*
* Copyright 2023-2024 Tyler Parret True
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @Authors
* Tyler Parret True <mysteryworldgod@outlook.com><https://github.com/OwlHowlinMornSky>
*/
#include "WndEnumeration.h"

namespace {

Expand Down
Loading