windows程序设计 调色板问题

ewfc12ewrew 2011-11-07 11:36:06
case WM_CREATE:
// Set up a LOGPALETTE structure and create a palette

plp = malloc (sizeof (LOGPALETTE) + 64 * sizeof (PALETTEENTRY)) ;

plp->palVersion = 0x0300 ;
plp->palNumEntries = 65 ;

for (i = 0 ; i < 65 ; i++)
{
plp->palPalEntry[i].peRed = (BYTE) min (255, 4 * i) ;
plp->palPalEntry[i].peGreen = (BYTE) min (255, 4 * i) ;
plp->palPalEntry[i].peBlue = (BYTE) min (255, 4 * i) ;
plp->palPalEntry[i].peFlags = 0 ;
}
hPalette = CreatePalette (plp) ;
free (plp) ;//为什么现在就释放plp所指向的内存,如果释放了hPalette岂不是空的
return 0 ;
...全文
38 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2011-11-07
  • 打赏
  • 举报
回复
《Windows核心编程》
赵4老师 2011-11-07
  • 打赏
  • 举报
回复
CreatePalette
The CreatePalette function creates a logical color palette.

HPALETTE CreatePalette(
CONST LOGPALETTE *lplgpl // pointer to logical color palette
);

Parameters
lplgpl
Pointer to a LOGPALETTE structure that contains information about the colors in the logical palette.
Return Values
If the function succeeds, the return value is a handle that identifies a logical palette.

If the function fails, the return value is NULL.

Windows NT: To get extended error information, callGetLastError.

Remarks
An application can determine whether a device supports palette operations by calling the GetDeviceCaps function and specifying the RASTERCAPS constant.

Once an application creates a logical palette, it can select that palette into a device context by calling the SelectPalette function. A palette selected into a device context can be realized by calling the RealizePalette function.

When you no longer need the palette, call the DeleteObject function to delete it.

Windows CE: Since Windows CE does not arbitrate between the palettes of the foreground and background applications, palettes are not automatically padded with Windows systems colors. Therefore, the number of color entries in the palette created by this function is always the same as the palNumEntries member of the LOGPALETTE structure.

QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Requires version 2.0 or later.
Header: Declared in wingdi.h.
Import Library: Use gdi32.lib.

See Also
Colors Overview, Color Functions, DeleteObject, GetDeviceCaps, LOGPALETTE, RealizePalette, SelectPalette


69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧