hellow windows

main.cpp

#include <windows.h>
#include <stdlib.h>  
#include <string.h>  
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include "dispix.h"

#define FPS_SET 60	//帧率
#define WINDOW_HEIGHT 240
#define WINDOW_WIDTH  320

HWND hwnd_main;	//主窗口标识
CDisPix disp(WINDOW_HEIGHT, WINDOW_WIDTH);
int y = 20;
int x = 20;


BOOL InitWindowsClass(HINSTANCE hInstance, const char *name);									//注册窗口
BOOL InitWindows(HINSTANCE hInstance, int nCmdShow, const char *name, const char *name_show);	//创建窗口
VOID CALLBACK LocalTimerProc(HWND hwnd, UINT message, UINT iTimerID, DWORD dwTime);				//定时器中断,用来刷屏
long WINAPI WndProc(HWND hWnd, UINT iMessage, UINT wParam, LONG lParam);						//消息处理


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	MSG Message;
	if (!InitWindowsClass(hInstance, "hellow")) return FALSE;
	if (!InitWindows(hInstance, nCmdShow, "hellow", "hellow windows")) return FALSE;
	if (!SetTimer(NULL, 1, 1000 / FPS_SET, LocalTimerProc)) return FALSE;
	while (GetMessage(&Message, 0, 0, 0))//进入消息循环
	{
		TranslateMessage(&Message);
		DispatchMessage(&Message);
	}
	return Message.wParam;
}

//===================================消息处理===================================
long WINAPI WndProc(HWND hWnd, UINT iMessage, UINT wParam, LONG lParam)
{
	HDC hDC; 
	PAINTSTRUCT PtStr;
	switch (iMessage)
	{
	case WM_PAINT://重绘
		hDC = BeginPaint(hWnd, &PtStr);
		disp.SetHollowRect(y, x, 0, 0, 255, 20, 20);
		disp.UpdatePixel(hDC);
		EndPaint(hWnd, &PtStr);
		return 0;
	case WM_CHAR://按键信息
		disp.SetHollowRect(y, x, 255, 0, 0, 20, 20);
		switch (wParam)
		{
		case'w':
			y -= 1;
			break;
		case's':
			y += 1;
			break;
		case'a':
			x -= 1;
			break;
		case'd':
			x += 1;
			break;
		default:
			break;
		}
		return 0;
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	default:
		return(DefWindowProc(hWnd, iMessage, wParam, lParam));
	}
}
//==================================================================================

BOOL InitWindowsClass(HINSTANCE hInstance, const char *name)
{
	WNDCLASS WndClass;
	WndClass.cbClsExtra = 0;
	WndClass.cbWndExtra = 0;
	WndClass.hbrBackground = NULL;
	WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
	WndClass.hIcon = LoadIcon(NULL, "END");
	WndClass.hInstance = hInstance;
	WndClass.lpfnWndProc = WndProc;  //消息处理函数
	WndClass.lpszClassName = LPCSTR(name);
	WndClass.lpszMenuName = NULL;
	WndClass.style = CS_HREDRAW | CS_VREDRAW;
	return RegisterClass(&WndClass);
}
 
BOOL InitWindows(HINSTANCE hInstance, int nCmdShow, const char *name, const char *name_show)
{
	hwnd_main = CreateWindow(name, name_show, WS_OVERLAPPEDWINDOW &  ~WS_SIZEBOX & ~WS_MAXIMIZEBOX,
		GetSystemMetrics(SM_CXSCREEN) / 4, GetSystemMetrics(SM_CYSCREEN) / 4, WINDOW_WIDTH + 16, WINDOW_HEIGHT + 39, NULL, NULL, hInstance, NULL);
	if (!hwnd_main)	
		return FALSE;
	ShowWindow(hwnd_main, nCmdShow);
	UpdateWindow(hwnd_main);
	return TRUE;
}

VOID CALLBACK LocalTimerProc(HWND hwnd, UINT message, UINT iTimerID, DWORD dwTime)
{
	InvalidateRect(hwnd_main, NULL, true);
}

 

dispix.h

#ifndef _DISPIX_H
#define _DISPIX_H

#include <windows.h>

class CDisPix
{
public:
	unsigned char *framebuffer;	//32位色的存储空间,大小为Height*Width*4字节
	CDisPix(int height,int width);
	~CDisPix();
	void UpdatePixel(HDC hDC);//更新绘图
	void SetRect(int y, int x, unsigned char b, unsigned char g, unsigned char r, int Halfheight, int Hlfwidth);
	void SetHollowRect(int y, int x, unsigned char b, unsigned char g, unsigned char r, int Halfheight, int Hlfwidth);//中空矩阵
	void SetPixel(int y, int x, unsigned char b, unsigned char g,unsigned char r);
	void Fill(unsigned char b, unsigned char g, unsigned char r);
	int GetHeight();
	int GetWidth();
private:
	int height;
	int width;
};

#endif

 

dispix.cpp

 

#include "dispix.h"
#include <windows.h>

CDisPix::CDisPix(int height, int width)
{
	int i, j;
	this->height = height;
	this->width = width;
	framebuffer = (unsigned char*)malloc(height*width * 4);
	Fill(255, 0, 0);
}

CDisPix::~CDisPix()
{
	free(framebuffer);
}

void CDisPix::UpdatePixel(HDC hDC)
{
	HDC memDC = CreateCompatibleDC(hDC);
	HBITMAP bmp = CreateCompatibleBitmap(hDC, width, height);
	SelectObject(memDC, bmp);
	BITMAPINFO bmpInfo;
	bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 
	bmpInfo.bmiHeader.biWidth = width;			//图像宽度
	bmpInfo.bmiHeader.biHeight = -height;		//图像高度
	bmpInfo.bmiHeader.biPlanes = 1;	
	bmpInfo.bmiHeader.biBitCount = 32;			//32位色,b,g,r,保留,由于计算机存储是4字节对齐
	bmpInfo.bmiHeader.biCompression = BI_RGB;	//无压缩
	bmpInfo.bmiHeader.biSizeImage = 0;
	bmpInfo.bmiHeader.biXPelsPerMeter = 3000;	//X方向每米的像素数,实际上没有作用
	bmpInfo.bmiHeader.biYPelsPerMeter = 3000;	//X方向每米的像素数,实际上没有作用
	bmpInfo.bmiHeader.biClrUsed = 0;			//0
	bmpInfo.bmiHeader.biClrImportant = 0;		//0
	SetDIBits(hDC, bmp, 0, height, framebuffer, &bmpInfo, DIB_RGB_COLORS);		//在内存中打图
	BitBlt(hDC, 0, 0, width, height, memDC, 0, 0, SRCCOPY);
	//StretchBlt(hDC,0, 0, 320, 240, memDC, 0, 0, 320, 240, SRCCOPY);//拉伸显示
}

void CDisPix::SetRect(int y, int x, unsigned char b, unsigned char g, unsigned char r, int Halfheight, int Hlfwidth)
{
	int i, j, ct;
	if (y + Halfheight >= height || y - Halfheight < 0) return;
	if (x + Hlfwidth >= width || x - Hlfwidth < 0) return;
	for (i = y - Halfheight; i <= y + Halfheight; i++)
	{
		for (j = x - Hlfwidth; j <= x + Hlfwidth; j++)
		{
			ct = (i * width * 4 + j * 4);
			framebuffer[ct + 0] = b;
			framebuffer[ct + 1] = g;
			framebuffer[ct + 2] = r;
		}
	}
}

void CDisPix::SetHollowRect(int y, int x, unsigned char b, unsigned char g, unsigned char r, int Halfheight, int Hlfwidth)
{
	int i, j, ct;
	if (y + Halfheight >= height || y - Halfheight < 0) return;
	if (x + Hlfwidth >= width || x - Hlfwidth < 0) return;
	for (i = y - Halfheight; i <= y + Halfheight; i++)
	{
		ct = (i * width * 4 + (x - Hlfwidth) * 4);
		framebuffer[ct + 0] = b;
		framebuffer[ct + 1] = g;
		framebuffer[ct + 2] = r;
		ct = (i * width * 4 + (x + Hlfwidth) * 4);
		framebuffer[ct + 0] = b;
		framebuffer[ct + 1] = g;
		framebuffer[ct + 2] = r;
	}
	for (j = x - Hlfwidth; j <= x + Hlfwidth; j++)
	{
		ct = ((y - Halfheight) * width * 4 + j * 4);
		framebuffer[ct + 0] = b;
		framebuffer[ct + 1] = g;
		framebuffer[ct + 2] = r;
		ct = ((y + Halfheight) * width * 4 + j * 4);
		framebuffer[ct + 0] = b;
		framebuffer[ct + 1] = g;
		framebuffer[ct + 2] = r;
	}
}

void CDisPix::SetPixel(int y, int x, unsigned char b, unsigned char g,unsigned char r)
{
	if (y >= height || y < 0) return;
	if (x >= width || x < 0) return;
	int ct = (y * width * 4 + x * 4);
	framebuffer[ct + 0] = b;
	framebuffer[ct + 1] = g;
	framebuffer[ct + 2] = r;
}

void CDisPix::Fill(unsigned char b, unsigned char g, unsigned char r)
{
	int i, j, ct;
	for (i = 0; i < height; i++)
	{
		for (j = 0; j < width; j++)
		{
			ct = (i * width * 4 + j * 4);
			framebuffer[ct + 0] = b;
			framebuffer[ct + 1] = g;
			framebuffer[ct + 2] = r;
		}
	}
}

int CDisPix::GetHeight()
{
	return height;
}

int CDisPix::GetWidth()
{
	return width;
}

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Hello WindowsWindows 10操作系统中的一项功能,它允许用户使用面部识别、指纹识别或PIN码等生物识别方式来解锁设备和登录应用程序。 如果在使用Windows Hello设置时出现问题,常见原因可能是账户、网络或Windows Hello系统配置文件受损。解决此问题的方法如下: 1. 首先,确保你的设备已连接到互联网,并且你的Windows操作系统已更新到最新版本。这可以通过打开Windows设置,选择“更新和安全”然后点击“检查更新”来完成。 2. 如果你使用的是微软账户登录系统并遇到问题,你可以尝试使用本地账户进行登录并设置Windows Hello。如果你能够成功录入指纹并设置Windows Hello,那么问题可能是由于你当前使用的微软账户下的系统配置文件受损导致的。对于这种情况,你可以尝试创建一个新的本地账户并使用它来设置Windows Hello。 请注意,系统内置的administrators账户可能无法使用Windows Hello的指纹录入功能,这是因为系统本身没有为该账户提供该功能。 如果以上方法仍然无法解决问题,你可以尝试重新安装Windows Hello驱动程序或重置Windows Hello的设置,具体步骤可以参考Windows官方文档或联系技术支持获取帮助。 总的来说,解决Hello Windows设置问题的方法主要包括确保设备联网和操作系统更新、尝试使用本地账户、重新安装驱动程序或重置设置等。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [windows hello出现问题怎么办?](https://blog.csdn.net/zym0218/article/details/126607590)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [Windows Hello制作日记](https://blog.csdn.net/qq_51578152/article/details/129133694)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值