Files
XCEngine/MVS/Music fluctuations/source/window/Window.h

67 lines
1.6 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#pragma once
#include "../global/Base.h"
#include"../myinput/Input.h"
#include<Windows.h>
#include <chrono>
#include <thread>
class Window {
public:
Window(Input& p_input);
~Window();
//注册窗体类,创建一个窗体,显示
bool initWindow(HINSTANCE hInstance, const uint32_t& width = 800, const uint32_t& height = 600);
//托管了wndProc捕获的消息并且进行处理
void handleMessage(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
//每一帧/每一次循环,都会调用,捕获以及分发窗体消息
void peekMessage();
void swapBuffer();
uint32_t getWidth() const { return mWidth; }
uint32_t getHeight() const { return mHeight; }
void* getCanvas() const { return mCanvasBuffer; }
bool shouldClose() { return !mAlive; }
void Test(int p_time){
swapBuffer();
std::this_thread::sleep_for(std::chrono::microseconds(p_time));
}
void Update() {
POINT cursorPos;
if (GetCursorPos(&cursorPos)) {
m_input.HandelMouseInput(cursorPos.x, cursorPos.y);
}
}
private:
BOOL createWindow(HINSTANCE hInstance);
ATOM registerWindowClass(HINSTANCE hInstance);
public:
static Window* currentWindow; //当前的窗口实例
private:
//为true表示当前窗体仍然在继续显示程序一直在跑
//为false表示窗体已经被命令关闭程序需要退出
bool mAlive{ true };
HINSTANCE mWindowInst;
WCHAR mWindowClassName[100] = L"AppWindow";
HWND mHwnd;
int mWidth = 800;
int mHeight = 600;
HDC mhDC; //当前窗口主dc
HDC mCanvasDC; //创建的于mhDC相兼容的绘图用的dc
HBITMAP mhBmp; //mCanvasDC内部生成的bitmap
void* mCanvasBuffer{ nullptr }; //mhBmp对应的内存起始位置指针
Input& m_input;
};