Имеется следующий код —
#include "stdafx.h"
#include "MaskWindow.h"
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
HBITMAP maskBitmap;
HWND hWnd;
bool dragging=false;
POINT MousePnt;
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_MASKWINDOW, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_MASKWINDOW);
//----------------------------------------------------------------------------------------------------------------------------------------
//Следующий код добавляется
int Style;
Style = GetWindowLong(hWnd, GWL_STYLE);
Style=Style || WS_CAPTION;
Style=Style || WS_SYSMENU;
SetWindowLong(hWnd, GWL_STYLE, Style);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
maskBitmap = (HBITMAP)LoadImage(NULL, "mask.bmp",
IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
if (!maskBitmap) return NULL;
BITMAP bi;
BYTE bpp;
DWORD TransPixel;
DWORD pixel;
int startx;
INT i, j;
HRGN Rgn, ResRgn = CreateRectRgn(0, 0, 0, 0);
GetObject(maskBitmap, sizeof( BITMAP ), &bi);
bpp = bi.bmBitsPixel >> 3;
BYTE *pBits = new BYTE[ bi.bmWidth * bi.bmHeight * bpp ];
int p = GetBitmapBits( maskBitmap, bi.bmWidth * bi.bmHeight * bpp,
pBits );
TransPixel = *(DWORD*)pBits;
TransPixel <<= 32 - bi.bmBitsPixel;
for (i = 0; i < bi.bmHeight; i++)
{
startx=-1;
for (j = 0; j < bi.bmWidth; j++)
{
pixel = *(DWORD*)(pBits + (i * bi.bmWidth +
j) * bpp) << (32 - bi.bmBitsPixel);
if (pixel != TransPixel)
{
if (startx<0)
{
startx = j;
} else if (j == (bi.bmWidth - 1))
{
Rgn = CreateRectRgn( startx, i, j, i + 1 );
CombineRgn( ResRgn, ResRgn, Rgn, RGN_OR);
startx=-1;
}
} else if (startx>=0)
{
Rgn = CreateRectRgn(startx, i, j, i + 1);
CombineRgn(ResRgn, ResRgn, Rgn, RGN_OR);
startx=-1;
}
}
}
delete pBits;
SetWindowRgn(hWnd, ResRgn, TRUE);
InvalidateRect(hWnd, 0, false);
//Конец добавляемого кода
//-----------------------------------------------------------------------------------------------------------------------------------------------
// Main message loop:
while (GetMessage(&msg, NULL, 0, false))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
и так далее по созданному шаблону в win32 project на VC++ 7.0
Алгоритм программульки следующий — она ищет в битмапе изображение на любого цвета фоне, дальше делает фон прозрачным а изображение выводи на экран...
!!!!! Требуется найти координаты вершин 4хугольника (находящегося естесственно в битмапе)... Волновой алгоритм — слишком сложен для меня... Нет ничего попроще
24.11.04 09:12: Перенесено модератором из 'C/C++' — Павел Кузнецов