Is good to write in C++ this type of code?
-
Are any better way write it to understand it?
-
Me write these codes with CodeBlocks and Notepad C++.
-
Need to much time to search for all these functions.
Is this best way? No better way to write it?
Link of this code: http://alivat.com/IMAGE_HBITMAP_GET_PIXEL_COLOR.txt
// ============================== BEGIN
// IMAGE_HBITMAP_GET_PIXEL_COLOR
// ============================== PUBLIC
// ============================== ABOUT
// Set pixel color for HBITMAP object.
// ============================== MINIMUM SUPPORT
// Windows_XP
// Windows_Server_2003
// ============================== REQUIRE DLL (1)
// Gdi32.dll
// ============================== REQUIRE LIBRARIES (1)
// Gdi32.lib
// ============================== REQUIRE INCLUDES (2)
#include <Windows.h>
#include <WinDef.h>
// ============================== USING FUNCTIONS (4)
// =============== SYSTEM
// CreateCompatibleDC() - wingdi.h (Windows.h) | Gdi32.lib | Gdi32.dll | Windows_2000_Professional, Windows_2000_Server
// SelectObject() - wingdi.h (Windows.h) | Gdi32.lib | Gdi32.dll | Windows_2000_Professional, Windows_2000_Server
// SetPixel() - wingdi.h (Windows.h) | Gdi32.lib | Gdi32.dll | Windows_2000_Professional, Windows_2000_Server
// DeleteDC() - wingdi.h (Windows.h) | Gdi32.lib | Gdi32.dll | Windows_2000_Professional, Windows_2000_Server
// ============================== USING DATA_TYPES (3)
// HBITMAP - WinDef.h
// COLORREF - Windef.h (Windows.h) | Windows_2000_Professional, Windows_2000_Server
// HDC - BaseTsd.h, WinDef.h, WinNT.h (windows.h) | Windows_XP, Windows_Server_2003
// ============================== USING CONSTANTS (0)
// ============================== USING VARIABLES (0)
// ============================== CODE
COLORREF image_hbitmap_get_pixel_color(HBITMAP image_hbitmap, int image_x, int image_y)
{
COLORREF pixel_color;
// ===== CREATE_HDC - BEGIN
// CreateCompatibleDC() - The CreateCompatibleDC function creates a memory device context (DC) compatible with the specified device.
HDC image_hdc = CreateCompatibleDC(
NULL // hdc (HDC) - A handle to an existing DC. If this handle is NULL, the function creates a memory DC compatible with the application's current screen.
);
if (image_hdc == NULL)
{
// ERROR
}
// ===== CREATE_HDC - END
// ===== HBITMAP_TO_HDC - BEGIN
// SelectObject() - The SelectObject function selects an object into the specified device context (DC). The new object replaces the previous object of the same type.
if (SelectObject(
image_hdc, // hdc (HDC) - A handle to the DC.
// h (HGDIOBJ) - A handle to the object to be selected.
// The specified object must have been created by using one of the following functions.
// * Bitmap - CreateBitmap, CreateBitmapIndirect, CreateCompatibleBitmap, CreateDIBitmap, CreateDIBSection.
// Bitmaps can only be selected into memory DC's. A single bitmap cannot be selected into more than one DC at the same time.
// * Brush - CreateBrushIndirect, CreateDIBPatternBrush, CreateDIBPatternBrushPt, CreateHatchBrush, CreatePatternBrush, CreateSolidBrush.
// * Font - CreateFont, CreateFontIndirect.
// * Pen - CreatePen, CreatePenIndirect.
// * Region - CombineRgn, CreateEllipticRgn, CreateEllipticRgnIndirect, CreatePolygonRgn, CreateRectRgn, CreateRectRgnIndirect.
image_hbitmap
) == NULL)
{
// ERROR
}
// ===== HBITMAP_TO_HDC - END
// ===== HDC_GET_PIXEL - BEGIN
// The GetPixel function retrieves the red, green, blue (RGB) color value of the pixel at the specified coordinates.
pixel_color = GetPixel(
image_hdc, // hdc (HDC) - A handle to the device context.
image_x, // x (int) - The x-coordinate, in logical units, of the pixel to be examined.
image_y // y (int) - The y-coordinate, in logical units, of the pixel to be examined.
);
if (pixel_color == 0xFFFFFFFF) // CLR_INVALID (0xFFFFFFFF)
{
// ERROR
}
// ===== HDC_GET_PIXEL - END
// The DeleteDC function deletes the specified device context (DC).
if (DeleteDC(
image_hdc // hdc (HDC) - A handle to the device context.
) == 0)
{
// ERROR
}
return pixel_color;
}
// ============================== END
// IMAGE_HBITMAP_GET_PIXEL_COLOR
// ==============================
Aucun commentaire:
Enregistrer un commentaire