728x90
1. 코드
stdafx.h 파일
//windows
#include <Windows.h>
#include <assert.h> //디버그 모드에서만 실행함, 프로그램이 실행 중에 중단 가능 (단원문)
stdafx.cpp 파일
#include "stdafx.h"
Window.h 파일
#pragma once
#include "stdafx.h"
namespace Window
{
static HINSTANCE global_instance;
static HWND global_handle;
//메시지 처리기 (CALLBACK : 컴퓨터 내부에서 알아서 셋팅함)
inline LRESULT CALLBACK WndProc
(
HWND handle,
UINT message,
WPARAM wParam,
LPARAM lParam
)
{
switch (message)
{
case WM_CLOSE:
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(handle, message, wParam, lParam);
}
return 0;
}
//윈도우 만들기
inline void Create(HINSTANCE hInstance, const UINT& width, const UINT& height)
{
WNDCLASSEX wnd_class;
wnd_class.cbClsExtra = 0;
wnd_class.cbWndExtra = 0;
wnd_class.hbrBackground = static_cast<HBRUSH>(GetStockObject(WHITE_BRUSH)); //배경
wnd_class.hCursor = LoadCursor(nullptr, IDC_ARROW); //커서 모양
wnd_class.hIcon = LoadIcon(nullptr, IDI_ERROR); // 아이콘 모양
wnd_class.hIconSm = LoadIcon(nullptr, IDI_ERROR); //작은 아이콘 모양
wnd_class.hInstance = hInstance;
wnd_class.lpfnWndProc = WndProc; //연결할 프로시저 (메시지 처리기)
wnd_class.lpszClassName = L"D2DGame"; //이름
wnd_class.lpszMenuName = nullptr; // 메뉴이름
wnd_class.style = CS_HREDRAW | CS_VREDRAW; // 크리는 방법
wnd_class.cbSize = sizeof(WNDCLASSEX); // 크기
//등록
auto check = RegisterClassEx(&wnd_class);
assert(check != 0); //검사
//만들기
global_handle = CreateWindowExW
(
WS_EX_APPWINDOW, // 어떤형태
L"D2DGame", // 윈도우 이름
L"D2DGame", // 이름
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
static_cast<int>(width), //가로
static_cast<int>(height), //세로
nullptr,
nullptr,
hInstance,
nullptr
);
assert(global_handle != nullptr);
}
//윈도우창 보이기
inline void Show()
{
// 정면, 포커스(카메라), 커서, 윈도우창(스타일), 업데이트
SetForegroundWindow(global_handle);
SetFocus(global_handle);
ShowCursor(TRUE);
ShowWindow(global_handle, SW_NORMAL);
UpdateWindow(global_handle);
}
//계속 윈도우창 띄우게 하기
inline const bool Update()
{
MSG msg;
ZeroMemory(&msg, sizeof(MSG));
if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE))
{
//핵심
TranslateMessage(&msg); // 문자에 관련
DispatchMessage(&msg); // 프로시저에 보냄
}
return msg.message != WM_QUIT;
}
//끝나면 할당 받은것들 삭제
inline void Destroy()
{
DestroyWindow(global_handle);
UnregisterClass(L"D2DGame", global_instance);
}
//위도우의 가로
inline const UINT GetWidth()
{
RECT rect;
GetClientRect(global_handle, &rect); // 윈도우창의 정보를 가져옴
return static_cast<UINT>(rect.right - rect.left);
}
inline const UINT GetHight()
{
RECT rect;
GetClientRect(global_handle, &rect);
return static_cast<UINT>(rect.bottom - rect.top); //윈도우창은 y값이 크면 아래로 가짐
}
}
main.cpp
#include "stdafx.h" //여러 함수
#include "Window.h" //윈도우 관련
//메인창
int APIENTRY WinMain
(
HINSTANCE hInstace,
HINSTANCE prevInstatce,
LPSTR lpszCmdParam,
int nCmdShow
)
{
Window::Create(hInstace, 500, 500);
Window::Show();
while (Window::Update())
{
}
Window::Destroy();
return 0;
}
2. 출력
3. 관계도
4. 요약
1. 미리 컴파일된 헤더 만들기 stdafx.cpp, stdafx.h 두개 작성후 stdafx.cpp 파일 속성에서 그림과 같이 설정
2. 프로젝트 만들땐 솔루션 디렉터리 체크 현재는 해제
window 데스크톱 마법사에서 콘솔 -> 응용(데스크톱) 으로 변경후 작성
3. calling convention : 함수 호출 규약 ( namespace , __call 이외 등등)
4. inline : 함수 호출 하는 과정을 없애서 속도 올리는 방법 단, 함수의 코드가 복제되므로 함수를 많이 사용하면 실행 파일의 크기가 커짐
dojang.io/mod/page/view.php?id=748
C 언어 코딩 도장: 85.14 인라인 함수 사용하기
인라인 함수는 함수를 선언할 때 inline 키워드를 붙입니다. inline 반환값자료형 함수이름(매개변수자료형 매개변수이름) { } 다음 내용을 소스 코드 편집 창에 입력한 뒤 실행해보세요. inline.c #incl
dojang.io
'DirectX > DirectX 2D_(구)' 카테고리의 다른 글
DX 공간 변환 (0) | 2020.11.05 |
---|---|
DX indexbuffer, 공간변환(이론) (0) | 2020.11.05 |
DX Render (0) | 2020.11.05 |
DX Window 창에 연동 (0) | 2020.11.04 |
DX 초기화, 설정, 삭제 (0) | 2020.11.04 |