
기존 Win32 애플리케이션 개발환경에서 WinUI3로 넘어갈 수 있을까 몇가지 기술들을 공부해보고 있다. 이번에는 가장 기본적인 창사이즈 조절이 가능하냐를 검증해본다. 기존 Win32개발 환경에서는 MoveWindow와 같은 함수로 창 사이즈 변경이 가능했다.
Winui3에서 창 사이즈 변경은 어떻게 할 수 있을까?
일단 기본 winui3 템플릿을 그대로 실행하면 창사이즈가 크게 실행된다.

MSDN에서 찾아본 바로는 AppWindow객체의 Resize함수를 통해 크기 조절이 가능하다고한다.
AppWindow.Resize(SizeInt32) 메서드 (Microsoft.UI.Windowing) - Windows App SDK
창의 크기를 지정된 크기로 조정합니다.
learn.microsoft.com
그러기 위해서는 AppWindow객체가 생성되는 곳을 찾아야한다.

일종의 App클래스인 App.xaml.cpp파일을 열어 보면 앱의 시작점인 OnLaunched 함수를 찾을 수 있다.

OnLaunched함수에서 MainWindow가 생성되는 것을 볼 수 있다. 이렇게 생성된 MainWindow 인스턴스에서 AppWindow를 찾을 수 있으며 Resize함수를 호출 할 수 있다.

void App::OnLaunched([[maybe_unused]] LaunchActivatedEventArgs const& e)
{
window = make<MainWindow>();
window.AppWindow().Resize({ 300, 500 });
window.Activate();
}
Resize함수에는winrt::Windows::Graphics::SizeInt32인자로 Width, Height 사이즈를 넣어주면된다. 빌드!.

그냥 순순히 될리가 없다. 우리가 만난 에러는 다음과 같다.
error C3779: 'winrt::impl::consume_Microsoft_UI_Windowing_IAppWindow<winrt::Microsoft::UI::Windowing::IAppWindow>::Resize': a function that returns 'auto' cannot be used before it is defined
정의되기 전에 쓸수 없데나.?
구글링을 해보면 레이몬드 첸 아저씨가 뭐라 써놓은 글이 있다.

https://devblogs.microsoft.com/oldnewthing/20190530-00/?p=102529
Why does my C++/WinRT project get errors of the form "consume_Something: function that returns 'auto' cannot be used before it i
Narrowing down the source of the missing header file.
devblogs.microsoft.com
For the impatient: The problem is that you are missing the header file for the interface you are using.
결론적으로 암튼 헤더파일이 누락되어서 내 벹는 에러라고 한다. 그러고보니 난 헤더를 추가한 적이 없다.
Resize함수의 네임스페이스는 Microsoft.UI.Windowing 이므로 winrtcpp 헤더를 추가해주자.
#include <winrt/Microsoft.UI.Windowing.h>
다시 빌드.

크기 조절이 잘 된 것을 볼 수 있다.
'개발 > Windows' 카테고리의 다른 글
[C++/WinRT] 윈도우C++프로젝트에서 json파싱하기 (0) | 2024.11.23 |
---|---|
[WTL] Visual studio 2022에서 WTL Wizard 설치하기 (1) | 2024.08.26 |
Openssl Windows용 빌드 하기(Openssl 3.0) + jom 병렬 빌드하기 (0) | 2024.07.20 |
[Winui3] Unpackaged 프로젝트로 설정하기 (0) | 2024.05.26 |
[WinUI3] WinUI3 써먹을 수 있을까? (0) | 2024.05.26 |
댓글