当前位置:网站首页>els 兼容性DC、传递图片到窗口
els 兼容性DC、传递图片到窗口
2022-07-27 03:41:00 【joker_0030】
1、函数定义(els.c)
#include"els_h.h"
void OnPaint(HDC hDc)
{
//创建兼容性DC。
HDC HMemDC = CreateCompatibleDC(hDc);//内存id为:HMemDc,窗口id hDc。
//创建兼容性位图。
HBITMAP hBitmapBack= CreateCompatibleBitmap(hDc, 500, 600);
//关联起来。
SelectObject(HMemDC, hBitmapBack);
Rectangle(HMemDC, 0, 0, 300, 600);//矩形框距离运行窗口的开始位置坐标和截至位置坐标。
Rectangle(HMemDC, 30, 30, 60, 60);//矩形框距离运行窗口的开始位置坐标和截至位置坐标。
//传递:
//返回值:失败返回0,成功返回非零。
//参数1:目标DC,窗口DC
//参数2,3:目标的起始位置,注意是基于我们的窗口。
//参数4,5:区域的大小。
//参数6:源DC,也就是我们的内存DC。
//参数7,8:内存图片的起始位置。
//参数9:传递方式。
//
BitBlt(hDc, 0, 0, 300, 600, HMemDC, 0, 0, SRCCOPY);
//释放DC
DeleteObject(hBitmapBack);
DeleteDC(HMemDC);
}
void Oncreate()
{
}
2.主函数(els_main.c)
#include<Windows.h>
#include"resource.h"
#include"els_h.h"
LRESULT CALLBACK PELouSi(HWND hWnd, UINT oMsg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPreInstance,LPSTR ipCmdLine,int nCmdShow)
{
//初始化窗口类。
WNDCLASSEX db;
HWND hWnd;
MSG msg;//结构体变量。
db.cbClsExtra = 0;
db.cbSize = sizeof(WNDCLASSEX);
db.cbWndExtra = 0;
db.hbrBackground = (HBRUSH)COLOR_BACKGROUND;//背景颜色。
//返回值:鼠标的句柄。
// 参数1:如果加载系统光标,NULL、如果加载自定义光标,填写实列句柄,hInstance;参数2:系统光标,直接填写定义好的宏、如果加载自定义光标,就用MAKEINTRESOURCE(240)加载相应的资源ID。
//db.hCursor = LoadCursor(NULL,IDC_HAND);//加载系统定义的光标。
db.hCursor = LoadCursor(hInstance,MAKEINTRESOURCE (IDC_NODROP));//自定义的光标。资源文件->添加->资源->Cursor->IDC_NODROP->新建。
//返回值:图标的句柄。
// 参数1:如果加载系统光标,NULL、如果加载自定义光标,填写实列句柄,hInstance;参数2:系统光标,直接填写定义好的宏、如果加载自定义光标,就用MAKEINTRESOURCE(240)加载相应的资源ID。
//db.hIcon = LoadIcon(NULL,IDI_ASTERISK);//加载系统定义的光标。
db.hIcon = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON1));//状态栏图标。
//db.hIconSm = NULL;//左上角图标为此定义。如果为空则默认为状态栏图标。
db.hIconSm = LoadIcon(NULL,IDI_HAND);
db.hInstance = hInstance;
db.lpfnWndProc = PELouSi;//回调函数名。
db.lpszClassName = "els";
db.lpszMenuName = NULL;
db.style = CS_HREDRAW | CS_VREDRAW;
if(0==RegisterClassEx(&db))
{
int a = GetLastError();
return 0;
}
//创建窗口。hWnd窗口句柄 失败返回NULL。
//窗口风格:参数4。
hWnd=CreateWindowEx(WS_EX_TOPMOST,"els","els方块",WS_OVERLAPPEDWINDOW,100,100,500,600,NULL,NULL,hInstance,NULL);
if (NULL == hWnd)//窗口句柄。 窗口的唯一标识。
{
return 0;
}
//显示窗口
ShowWindow(hWnd, nCmdShow);
//消息循环。队列。
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
//回调函数
//返回值:LRESULT,CALLBACK调用约定。
//参数1:窗口句柄;参数2:消息ID。
LRESULT CALLBACK PELouSi(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)// LRESULT:long类型;UINT:无符号整型,消息的ID。
{
PAINTSTRUCT pt;//定义结构体。
HDC hDc;
//关闭窗口消息
switch (nMsg)
{
case WM_CREATE://窗口信息处理程序接受的第一个消息,也是回调函数处理的第一个消息(为WM_CREATE)。此消息只产生一次,一般是用于初始化一些数据。
//GetLastError();//优化。
Oncreate();//游戏数据初始化。
break;
//是回调函数处理的第二个消息(为WM_PAINT)。
//当窗口显示区域的一部分显示内容或者全部变为(无效),以致于必须(更新画面)时,将由这个消息通知程序。
//窗口结构的最后的那个成员CS_HREDRAW|CS_VREDRAW,目的就是窗口大小发生变化的时候,产生WM_PAINT消息。
//窗口重叠时,重叠部分渐渐出现时。
case WM_PAINT:
//GetLastError();//优化。
hDc=BeginPaint(hWnd,&pt);//getDC,窗口可操作区域的标识。
//在此之间画窗口的内容。
//画方块。
OnPaint(hDc);//增加代码可读性。
EndPaint(hWnd, &pt);//结束。
break;
case WM_DESTROY:
PostQuitMessage(0);//调用PostQuitMessage(0)这个函数发出WM_QUIT消息。//点叉系统依次产生WM_CLOSE,WM_DESTROY,WM_QUIT。
break;
}//手动处理点叉关闭消息。
return DefWindowProc(hWnd, nMsg, wParam, lParam);
//LRESULT a=DefWindowProc(hWnd, oMsg, wParam, lParam);//功能
//return a;
}
3.头函数(els.h)
#ifndef N_d
#define N_d
#include<Windows.h>
void OnPaint(HDC hDc);
void Oncreate();
#endif
边栏推荐
- JMeter learning notes 004-csv file line number control cycle times
- 一张图看懂KingbaseES V9
- Elastic certification test: 30 day FastPass Study Guide
- Slope of binary tree
- [small sample segmentation] msanet: multi similarity and attention guidance for boosting few shot segmentation
- CloudCompare&PCL 匹配点距离抑制
- php+swoole
- 【机器学习网络】BP神经网络与深度学习-6 深度神经网络(deep neural Networks DNN)
- P1438 无聊的数列 线段树+差分
- What is the principle difference between lateinit and lazy in kotlin
猜你喜欢

452 pages, 130000 words, the overall solution of modern smart Township Xueliang project 2022 Edition

使用WebMvcConfigurer进行接口请求拦截进行中增强(附源码)

HEAD detached from origin/...导致push失败

BSN IPFS(星际文件系统)专网简介、功能、架构及特性、接入说明

C language learning notes - memory management

Eureka-服务注册中心

JMeter download and installation
![[competition reference] pytorch common code snippet and operation collection](/img/b3/0b91e381e2444dfd222537bf5b8ccf.jpg)
[competition reference] pytorch common code snippet and operation collection

Learning route from junior programmer to architect + complete version of supporting learning resources

佳明手表怎么设置用户定制显示
随机推荐
tcp协议知识详解
微服务化解决文库下载业务问题实践
The difference between ArrayList and LinkedList
Stm32cubemx learning notes (41) -- eth interface +lwip protocol stack use (DHCP)
Worship the 321 page PDF of the core technology of Internet entrepreneurship that Alibaba is pushing internally. It's really kneeling
面试题 16.05. 阶乘尾数
2022 retraining question bank and answers for main principals of hazardous chemical business units
SkyWalking分布式系统应用程序性能监控工具-中
2022 operation of simulated examination question bank and simulated examination platform for safety production management personnel of hazardous chemical production units
ISG index shows that the it and business service market in the Asia Pacific region fell sharply in the second quarter
C language learning notes - memory management
Convolution neural network -- convolution of gray image
技术分享 | 需要小心配置的 gtid_mode
Leetcode daily exercise: sort sentences
网工知识角|只需四个步骤,教会你使用SecureCRT连接到eNSP,常用工具操作指南必看
JS to realize page Jump and parameter acquisition and loading
playwright网络爬虫实战案例分享
Brightcove appoints Dan Freund as chief revenue Officer
ffmpeg合并视频功能
搜索旋转排序数组