Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do CS_BYTEALIGNCLIENT and CS_BYTEALIGNWINDOW mean?

I have trouble understanding these two class styles. The docs say that they align the window on a byte boundary, but I don't understand what that means.

I have tried to use them and yes, the position of the window upon creation is different, but what do they do and why would I use them is unclear to me.

like image 692
NicknEma Avatar asked Sep 08 '26 13:09

NicknEma


1 Answers

From Why did Windows 95 keep window coordinates at multiples of 8? by Raymond Chen:

The screen itself is a giant bitmap, and this means that copying data to the screen goes much faster if x-coordinate of the destination resides on a full byte boundary. And the most common x-coordinate is the left edge of a window’s contents (known as its client area).

Applications can request that Windows position their windows so that their client area began at these advantageous coordinates by setting the CS_BYTE­ALIGN­CLIENT style in their window class. And pretty much all applications did this because of the performance benefit it produced.

So what happened after Windows 95 that made this optimization go away?

Oh, the optimization is still there. You can still set the CS_BYTE­ALIGN­CLIENT style today, and the system will honor it.

The thing that changed wasn’t Windows. The thing that changed was your video card.

In the Windows 95 era, predominant graphics cards were the VGA (Video Graphics Array) and EGA (Enhanced Graphics Adapter). Older graphics cards were also supported, such as the CGA (Color Graphics Adapter) and the monochrome HGC (Hercules Graphics Card).

All of these graphics cards had something in common: They used a pixel format where multiple pixels were represented within a single byte,¹ and therefore provided an environment where byte alignment causes certain x-coordinates to become ineligible positions.

Once you upgraded your graphics card and set the color resolution to “256 colors” or higher, every pixel occupies at least a full byte,² so the requirement that the x-coordinate be byte-aligned is vacuously satisfied. Every coordinate is eligible.

Nowadays, all graphics cards use 32-bit color formats, and the requirement that the coordinate be aligned to a byte offset is satisfied by all x-coordinates.³ The multiples of 8 are no longer special.

like image 128
Govind Parmar Avatar answered Sep 11 '26 04:09

Govind Parmar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!