mirror of
https://github.com/reactos/reactos.git
synced 2024-08-12 06:06:27 +00:00
some code cleanup
svn path=/trunk/; revision=41435
This commit is contained in:
parent
84833730d0
commit
3d402751d4
|
@ -14,92 +14,101 @@
|
||||||
|
|
||||||
HBITMAP CreateDIBWithProperties(int width, int height)
|
HBITMAP CreateDIBWithProperties(int width, int height)
|
||||||
{
|
{
|
||||||
BITMAPINFO bitmapinfo;
|
BITMAPINFO bmi;
|
||||||
bitmapinfo.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
|
ZeroMemory(&bmi, sizeof(BITMAPINFO));
|
||||||
bitmapinfo.bmiHeader.biWidth = width;
|
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||||
bitmapinfo.bmiHeader.biHeight = height;
|
bmi.bmiHeader.biWidth = width;
|
||||||
bitmapinfo.bmiHeader.biPlanes = 1;
|
bmi.bmiHeader.biHeight = height;
|
||||||
bitmapinfo.bmiHeader.biBitCount = 24;
|
bmi.bmiHeader.biPlanes = 1;
|
||||||
bitmapinfo.bmiHeader.biCompression = BI_RGB;
|
bmi.bmiHeader.biBitCount = 24;
|
||||||
bitmapinfo.bmiHeader.biSizeImage = 0;
|
bmi.bmiHeader.biCompression = BI_RGB;
|
||||||
bitmapinfo.bmiHeader.biXPelsPerMeter = 0;
|
return CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, NULL, NULL, 0);
|
||||||
bitmapinfo.bmiHeader.biYPelsPerMeter = 0;
|
|
||||||
bitmapinfo.bmiHeader.biClrUsed = 0;
|
|
||||||
bitmapinfo.bmiHeader.biClrImportant = 0;
|
|
||||||
return CreateDIBSection(NULL, &bitmapinfo, DIB_RGB_COLORS, NULL, NULL, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetDIBWidth(HBITMAP hbm)
|
int GetDIBWidth(HBITMAP hBitmap)
|
||||||
{
|
{
|
||||||
BITMAP bm;
|
BITMAP bm;
|
||||||
GetObject(hbm, sizeof(BITMAP), &bm);
|
GetObject(hBitmap, sizeof(BITMAP), &bm);
|
||||||
return bm.bmWidth;
|
return bm.bmWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetDIBHeight(HBITMAP hbm)
|
int GetDIBHeight(HBITMAP hBitmap)
|
||||||
{
|
{
|
||||||
BITMAP bm;
|
BITMAP bm;
|
||||||
GetObject(hbm, sizeof(BITMAP), &bm);
|
GetObject(hBitmap, sizeof(BITMAP), &bm);
|
||||||
return bm.bmHeight;
|
return bm.bmHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveDIBToFile(HBITMAP hbm, LPTSTR name, HDC hdc)
|
void SaveDIBToFile(HBITMAP hBitmap, LPTSTR FileName, HDC hDC)
|
||||||
{
|
{
|
||||||
BITMAP bm;
|
BITMAP bm;
|
||||||
HANDLE hFile;
|
HANDLE hFile;
|
||||||
BITMAPFILEHEADER bf;
|
BITMAPFILEHEADER bf;
|
||||||
BITMAPINFOHEADER bi;
|
BITMAPINFOHEADER bi;
|
||||||
int imgDataSize;
|
int imgDataSize;
|
||||||
int bytesWritten;
|
DWORD dwBytesWritten;
|
||||||
|
char* buffer;
|
||||||
|
|
||||||
GetObject(hbm, sizeof(BITMAP), &bm);
|
GetObject(hBitmap, sizeof(BITMAP), &bm);
|
||||||
|
|
||||||
imgDataSize = bm.bmWidthBytes*bm.bmHeight;
|
ZeroMemory(&bf, sizeof(BITMAPFILEHEADER));
|
||||||
bf.bfType = 0x4d42;
|
ZeroMemory(&bi, sizeof(BITMAPINFOHEADER));
|
||||||
bf.bfSize = imgDataSize+52;
|
|
||||||
bf.bfReserved1 = 0;
|
imgDataSize = bm.bmWidthBytes * bm.bmHeight;
|
||||||
bf.bfReserved2 = 0;
|
bf.bfType = 0x4d42; /* BM */
|
||||||
|
bf.bfSize = imgDataSize + 52;
|
||||||
bf.bfOffBits = 54;
|
bf.bfOffBits = 54;
|
||||||
bi.biSize = 40;
|
bi.biSize = sizeof(BITMAPINFOHEADER);
|
||||||
bi.biWidth = bm.bmWidth;
|
bi.biWidth = bm.bmWidth;
|
||||||
bi.biHeight = bm.bmHeight;
|
bi.biHeight = bm.bmHeight;
|
||||||
bi.biPlanes = bm.bmPlanes;
|
bi.biPlanes = bm.bmPlanes;
|
||||||
bi.biBitCount = bm.bmBitsPixel;
|
bi.biBitCount = bm.bmBitsPixel;
|
||||||
bi.biCompression = BI_RGB;
|
bi.biCompression = BI_RGB;
|
||||||
bi.biSizeImage = 0;
|
|
||||||
bi.biXPelsPerMeter = 0;
|
buffer = HeapAlloc(GetProcessHeap(), 0, imgDataSize);
|
||||||
bi.biYPelsPerMeter = 0;
|
GetDIBits(hDC, hBitmap, 0, bm.bmHeight, buffer, (LPBITMAPINFO)&bi, DIB_RGB_COLORS);
|
||||||
bi.biClrUsed = 0;
|
|
||||||
bi.biClrImportant = 0;
|
hFile = CreateFile(FileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
||||||
int *buffer = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, imgDataSize);
|
if (hFile == INVALID_HANDLE_VALUE)
|
||||||
GetDIBits(hdc, hbm, 0, bm.bmHeight, buffer, (LPBITMAPINFO)&bi, DIB_RGB_COLORS);
|
return;
|
||||||
hFile = CreateFile(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
|
||||||
WriteFile(hFile, &bf, 14, (LPDWORD)&bytesWritten, NULL);
|
WriteFile(hFile, &bf, sizeof(BITMAPFILEHEADER), &dwBytesWritten, NULL);
|
||||||
WriteFile(hFile, &bi, 40, (LPDWORD)&bytesWritten, NULL);
|
WriteFile(hFile, &bi, sizeof(BITMAPINFOHEADER), &dwBytesWritten, NULL);
|
||||||
WriteFile(hFile, buffer, imgDataSize, (LPDWORD)&bytesWritten, NULL);
|
WriteFile(hFile, buffer, imgDataSize, &dwBytesWritten, NULL);
|
||||||
|
|
||||||
CloseHandle(hFile);
|
CloseHandle(hFile);
|
||||||
HeapFree(GetProcessHeap(), 0, buffer);
|
HeapFree(GetProcessHeap(), 0, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
HBITMAP LoadDIBFromFile(LPTSTR name)
|
HBITMAP LoadDIBFromFile(LPTSTR name)
|
||||||
{
|
{
|
||||||
HBITMAP bm;
|
HBITMAP hBitmap;
|
||||||
BITMAPFILEHEADER bfh;
|
BITMAPFILEHEADER bfh;
|
||||||
BITMAPINFO *bi;
|
BITMAPINFO *bi;
|
||||||
VOID *data;
|
PVOID pvBits;
|
||||||
int bytesRead;
|
DWORD dwBytesRead;
|
||||||
HANDLE f = CreateFile(name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
HANDLE hFile;
|
||||||
ReadFile(f, &bfh, 14, (LPDWORD)&bytesRead, NULL);
|
|
||||||
if (bfh.bfType!=0x4d42)
|
hFile = CreateFile(name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
|
||||||
|
if (hFile == INVALID_HANDLE_VALUE)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
/* read header and check for 'BM' magic */
|
||||||
|
ReadFile(hFile, &bfh, sizeof(BITMAPFILEHEADER), &dwBytesRead, NULL);
|
||||||
|
if (bfh.bfType != 0x4d42)
|
||||||
{
|
{
|
||||||
CloseHandle(f);
|
CloseHandle(hFile);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
bi = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, bfh.bfOffBits-14);
|
|
||||||
ReadFile(f, bi, bfh.bfOffBits-14, (LPDWORD)&bytesRead, NULL);
|
bi = HeapAlloc(GetProcessHeap(), 0, bfh.bfOffBits - sizeof(BITMAPFILEHEADER));
|
||||||
bm = CreateDIBSection(NULL, bi, DIB_RGB_COLORS, &data, NULL, 0);
|
if (!bi)
|
||||||
ReadFile(f, data, bfh.bfSize-bfh.bfOffBits, (LPDWORD)&bytesRead, NULL);
|
return NULL;
|
||||||
CloseHandle(f);
|
|
||||||
|
ReadFile(hFile, bi, bfh.bfOffBits - sizeof(BITMAPFILEHEADER), &dwBytesRead, NULL);
|
||||||
|
hBitmap = CreateDIBSection(NULL, bi, DIB_RGB_COLORS, &pvBits, NULL, 0);
|
||||||
|
ReadFile(hFile, pvBits, bfh.bfSize - bfh.bfOffBits, &dwBytesRead, NULL);
|
||||||
|
CloseHandle(hFile);
|
||||||
HeapFree(GetProcessHeap(), 0, bi);
|
HeapFree(GetProcessHeap(), 0, bi);
|
||||||
return bm;
|
return hBitmap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,10 +251,17 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR l
|
||||||
SendMessage(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
|
SendMessage(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
|
||||||
for (i=0; i<16; i++)
|
for (i=0; i<16; i++)
|
||||||
{
|
{
|
||||||
|
TBBUTTON tbbutton;
|
||||||
int wrapnow = 0;
|
int wrapnow = 0;
|
||||||
|
|
||||||
if (i % 2 == 1) wrapnow = TBSTATE_WRAP;
|
if (i % 2 == 1) wrapnow = TBSTATE_WRAP;
|
||||||
LoadString(hThisInstance, IDS_TOOLTIP1 + i, tooltips[i], 30);
|
LoadString(hThisInstance, IDS_TOOLTIP1 + i, tooltips[i], 30);
|
||||||
TBBUTTON tbbutton = { i, ID_FREESEL + i, TBSTATE_ENABLED | wrapnow, TBSTYLE_CHECKGROUP, {0}, 0, (INT_PTR)tooltips[i] };
|
ZeroMemory(&tbbutton, sizeof(TBBUTTON));
|
||||||
|
tbbutton.iString = (INT_PTR)tooltips[i];
|
||||||
|
tbbutton.fsStyle = TBSTYLE_CHECKGROUP;
|
||||||
|
tbbutton.fsState = TBSTATE_ENABLED | wrapnow;
|
||||||
|
tbbutton.idCommand = ID_FREESEL + i;
|
||||||
|
tbbutton.iBitmap = i;
|
||||||
SendMessage(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&tbbutton);
|
SendMessage(hToolbar, TB_ADDBUTTONS, 1, (LPARAM)&tbbutton);
|
||||||
}
|
}
|
||||||
/* SendMessage(hToolbar, TB_SETROWS, MAKEWPARAM(8, FALSE), (LPARAM)NULL); */
|
/* SendMessage(hToolbar, TB_SETROWS, MAKEWPARAM(8, FALSE), (LPARAM)NULL); */
|
||||||
|
@ -264,9 +271,6 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR l
|
||||||
SendMessage(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(25, 25));
|
SendMessage(hToolbar, TB_SETBUTTONSIZE, 0, MAKELONG(25, 25));
|
||||||
/* SendMessage(hToolbar, TB_AUTOSIZE, 0, 0); */
|
/* SendMessage(hToolbar, TB_AUTOSIZE, 0, 0); */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* creating the tool settings child window */
|
/* creating the tool settings child window */
|
||||||
hToolSettings = CreateWindowEx(0, _T("ToolSettings"), _T(""), WS_CHILD | WS_VISIBLE, 7, 210, 42, 140, hwnd, NULL, hThisInstance, NULL);
|
hToolSettings = CreateWindowEx(0, _T("ToolSettings"), _T(""), WS_CHILD | WS_VISIBLE, 7, 210, 42, 140, hwnd, NULL, hThisInstance, NULL);
|
||||||
|
|
||||||
|
|
|
@ -19,54 +19,49 @@ LRESULT CALLBACK PalWinProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lPar
|
||||||
{
|
{
|
||||||
case WM_PAINT:
|
case WM_PAINT:
|
||||||
{
|
{
|
||||||
int i;
|
RECT rc = {0, 0, 31, 32};
|
||||||
long rectang[4] = {0, 0, 31, 32};
|
HDC hDC = GetDC(hwnd);
|
||||||
int a;
|
|
||||||
int b;
|
|
||||||
HDC hdc = GetDC(hwnd);
|
|
||||||
HPEN oldPen;
|
HPEN oldPen;
|
||||||
HBRUSH oldBrush;
|
HBRUSH oldBrush;
|
||||||
|
int i, a, b;
|
||||||
|
|
||||||
DefWindowProc (hwnd, message, wParam, lParam);
|
DefWindowProc (hwnd, message, wParam, lParam);
|
||||||
|
|
||||||
for (b=2; b<30; b++) for (a=2; a<29; a++) if ((a+b)%2==1) SetPixel(hdc, a, b, GetSysColor(COLOR_BTNHILIGHT));
|
for (b = 2; b < 30; b++)
|
||||||
DrawEdge(hdc, (LPRECT)&rectang, EDGE_RAISED, BF_TOPLEFT);
|
for (a = 2; a < 29; a++)
|
||||||
DrawEdge(hdc, (LPRECT)&rectang, BDR_SUNKENOUTER, BF_TOPLEFT|BF_BOTTOMRIGHT);
|
if ((a + b) % 2 == 1)
|
||||||
rectang[0] = 11;
|
SetPixel(hDC, a, b, GetSysColor(COLOR_BTNHILIGHT));
|
||||||
rectang[1] = 12;
|
|
||||||
rectang[2] = 26;
|
DrawEdge(hDC, &rc, EDGE_RAISED, BF_TOPLEFT);
|
||||||
rectang[3] = 27;
|
DrawEdge(hDC, &rc, BDR_SUNKENOUTER, BF_TOPLEFT|BF_BOTTOMRIGHT);
|
||||||
DrawEdge(hdc, (LPRECT)&rectang, BDR_RAISEDINNER, BF_RECT|BF_MIDDLE);
|
SetRect(&rc, 11, 12, 26, 27);
|
||||||
oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
|
DrawEdge(hDC, &rc, BDR_RAISEDINNER, BF_RECT|BF_MIDDLE);
|
||||||
oldBrush = SelectObject(hdc, CreateSolidBrush(bgColor));
|
oldPen = SelectObject(hDC, CreatePen(PS_NULL, 0, 0));
|
||||||
Rectangle( hdc, rectang[0]+2,rectang[1]+2,rectang[2]-1,rectang[3]-1);
|
oldBrush = SelectObject(hDC, CreateSolidBrush(bgColor));
|
||||||
DeleteObject(SelectObject(hdc, oldBrush));
|
Rectangle(hDC, rc.left, rc.top + 2, rc.right -1, rc.bottom - 1);
|
||||||
DeleteObject(SelectObject(hdc, oldPen));
|
DeleteObject(SelectObject(hDC, oldBrush));
|
||||||
rectang[0] = 4;
|
SetRect(&rc, 4, 5, 19, 20);
|
||||||
rectang[1] = 5;
|
DrawEdge(hDC, &rc, BDR_RAISEDINNER, BF_RECT|BF_MIDDLE);
|
||||||
rectang[2] = 19;
|
oldBrush = SelectObject(hDC, CreateSolidBrush(fgColor));
|
||||||
rectang[3] = 20;
|
Rectangle( hDC, rc.left + 2,rc.top + 2, rc.right - 1, rc.bottom - 1);
|
||||||
DrawEdge(hdc, (LPRECT)&rectang, BDR_RAISEDINNER, BF_RECT|BF_MIDDLE);
|
DeleteObject(SelectObject(hDC, oldBrush));
|
||||||
oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
|
DeleteObject(SelectObject(hDC, oldPen));
|
||||||
oldBrush = SelectObject(hdc, CreateSolidBrush(fgColor));
|
|
||||||
Rectangle( hdc, rectang[0]+2,rectang[1]+2,rectang[2]-1,rectang[3]-1);
|
|
||||||
DeleteObject(SelectObject(hdc, oldBrush));
|
|
||||||
DeleteObject(SelectObject(hdc, oldPen));
|
|
||||||
for (i=0; i<28; i++)
|
for (i=0; i<28; i++)
|
||||||
{
|
{
|
||||||
rectang[0] = 31+(i%14)*16;
|
SetRect(&rc, 31 + (i % 14) * 16,
|
||||||
rectang[1] = 0+(i/14)*16;
|
0 + (i / 14) * 16,
|
||||||
rectang[2] = 16+rectang[0];
|
16 + 31 + (i % 14) * 16,
|
||||||
rectang[3] = 16+rectang[1];
|
16 + 0 + (i / 14) * 16);
|
||||||
DrawEdge(hdc, (LPRECT)&rectang, EDGE_RAISED, BF_TOPLEFT);
|
DrawEdge(hDC, &rc, EDGE_RAISED, BF_TOPLEFT);
|
||||||
DrawEdge(hdc, (LPRECT)&rectang, BDR_SUNKENOUTER, BF_RECT);
|
DrawEdge(hDC, &rc, BDR_SUNKENOUTER, BF_RECT);
|
||||||
oldPen = SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
|
oldPen = SelectObject(hDC, CreatePen(PS_NULL, 0, 0));
|
||||||
oldBrush = SelectObject(hdc, CreateSolidBrush(palColors[i]));
|
oldBrush = SelectObject(hDC, CreateSolidBrush(palColors[i]));
|
||||||
Rectangle( hdc, rectang[0]+2,rectang[1]+2,rectang[2]-1,rectang[3]-1);
|
Rectangle(hDC, rc.left + 2,rc.top + 2,rc.right + 1, rc.bottom - 1);
|
||||||
DeleteObject(SelectObject(hdc, oldBrush));
|
DeleteObject(SelectObject(hDC, oldBrush));
|
||||||
DeleteObject(SelectObject(hdc, oldPen));
|
DeleteObject(SelectObject(hDC, oldPen));
|
||||||
}
|
}
|
||||||
ReleaseDC(hwnd, hdc);
|
ReleaseDC(hwnd, hDC);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WM_LBUTTONDOWN:
|
case WM_LBUTTONDOWN:
|
||||||
|
|
|
@ -28,10 +28,10 @@ LRESULT CALLBACK SelectionWinProc (HWND hwnd, UINT message, WPARAM wParam, LPARA
|
||||||
{
|
{
|
||||||
if (!moving)
|
if (!moving)
|
||||||
{
|
{
|
||||||
HDC hdc=GetDC(hwnd);
|
HDC hDC = GetDC(hwnd);
|
||||||
DefWindowProc (hwnd, message, wParam, lParam);
|
DefWindowProc (hwnd, message, wParam, lParam);
|
||||||
SelectionFrame(hdc, 1, 1, rectSel_dest[2]*zoom/1000+5, rectSel_dest[3]*zoom/1000+5);
|
SelectionFrame(hDC, 1, 1, rectSel_dest[2]*zoom/1000+5, rectSel_dest[3]*zoom/1000+5);
|
||||||
ReleaseDC(hwnd, hdc);
|
ReleaseDC(hwnd, hDC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue