跳至主要内容

13.窗口的本质

窗口的本质

  • win32k.sys模块实现图形界面、消息管理
  • ntoskrnl.exe模块实现进程、线程、内存管理等

GDI 图形设备接口

  1. 设备对象HWND:画在哪里?
  2. DC(设备上下文,Device Contexts)
  3. 图形对象
图形对象 作用
画笔(Pen) 影响线条,包括颜色、粗细、虚实、箭头形状等
画刷(Brushes) 影响对形状、区域等操作,如使用的颜色、是否有阴影等
字体(Fonts) 影响文字输出的字体
位图(Bitmaps) 影响位图创建、位图操作和保存等
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <handleapi.h>
#include <stdio.h>
#include <windef.h>
#include <windows.h>
#include <wingdi.h>

int main(int argc, char *argv[]) {
HWND hwnd;
HDC hdc;
HPEN hpen;
//设备对象
hwnd = (HWND)NULL;
//获取设备对象上下文
hdc = GetDC(hwnd);

//创建画笔,设置线条属性
hpen = CreatePen(PS_SOLID, 5, RGB(0xFF, 00, 00));

//关联
SelectObject(hdc, hpen);

//开始画
LineTo(hdc,400,400);
getchar();
ReleaseDC(hwnd, hdc);
DeleteObject(hpen);
return 0;
}

关于本文

由 GuQing 撰写,采用 CC BY-NC 4.0 许可协议。