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