⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myheader.cpp

📁 caro program is written by VC++ and AI
💻 CPP
字号:
#include "myheader.h"
#include <math.h>
#include <commctrl.h>

#define TWOPI (2 * 3.14159)


////////////////////////////////////////////////////////////////////////////////
// Draw My Rectangle
// HDC, left , top, right, bottom, Color Pen, Color Brush
void MyRectangle(HDC hDC,int a,int b,int c,int d,COLORREF crPen,COLORREF crBrush) 
{
    HPEN hPen ;
    HBRUSH hBrush ;

    // Create a pen.
    hPen = CreatePen(PS_SOLID,0, crPen);
    // Create a brush
    hBrush = CreateSolidBrush(crBrush);

    // Select the new pen and brush, and then draw.
    SelectObject(hDC, hPen);
    SelectObject(hDC, hBrush);
    Rectangle(hDC, a, b, c, d);

    // Clean up.
    DeleteObject(hPen);
    DeleteObject(hBrush);
}

////////////////////////////////////////////////////////////////////////////////
// Draw My Rectangle Extended
// HDC, left , top, right, bottom, Pen Style, Pen Width, Color Pen, Color Brush
void MyRectangleEx(HDC hDC,int a,int b,int c,int d,int iPenStyle, int iPenWidth,COLORREF crPen,COLORREF crBrush) 
{
    HPEN hPen ;
    HBRUSH hBrush ;

    // Create a pen.
    hPen = CreatePen(iPenStyle,iPenWidth, crPen);
    // Create a brush.
    hBrush = CreateSolidBrush(crBrush);

    // Select the new pen and brush, and then draw.
    SelectObject(hDC, hPen);
    SelectObject(hDC, hBrush);
    Rectangle(hDC, a, b, c, d);

    // Clean up.
    DeleteObject(hPen);
    DeleteObject(hBrush);
}

////////////////////////////////////////////////////////////////////////////////
// Draw My Frame
// HDC, left , top, right, bottom, Color Pen
void MyFrame(HDC hDC,int a,int b,int c,int d,COLORREF crPen) 
{
    HPEN hPen ;
    HGDIOBJ hObject ;

    // Create a pen.
    hPen = CreatePen(PS_SOLID,0, crPen);
    // Create a brush
    hObject = GetStockObject(NULL_BRUSH);

    // Select the new pen and brush, and then draw.
    SelectObject(hDC, hPen);
    SelectObject(hDC, hObject);
    Rectangle(hDC, a, b, c, d);

    // Clean up.
    DeleteObject(hPen);
    DeleteObject(hObject);
}

////////////////////////////////////////////////////////////////////////////////
// Draw My Frame Extended
// HDC, left , top, right, bottom, Pen Style, Pen Width, Color Pen
void MyFrameEx(HDC hDC,int a,int b,int c,int d,int iPenStyle, int iPenWidth,COLORREF crPen) 
{
    HPEN hPen ;
    HGDIOBJ hObject ;

    // Create a pen.
    hPen = CreatePen(iPenStyle,iPenWidth, crPen);
    // Create a brush.
    hObject = GetStockObject(NULL_BRUSH);

    // Select the new pen and brush, and then draw.
    SelectObject(hDC, hPen);
    SelectObject(hDC, hObject);
    Rectangle(hDC, a, b, c, d);

    // Clean up.
    DeleteObject(hPen);
    DeleteObject(hObject);
}

////////////////////////////////////////////////////////////////////////////////
// Draw My Line
// HDC, left , top, right, bottom, Color Pen, Color Brush
void MyLine(HDC hDC,int a,int b,int c,int d,COLORREF crPen) 
{
    HPEN hPen ;

    // Create a pen.
    hPen = CreatePen(PS_SOLID,0, crPen);
    
    // Select the new pen and brush, and then draw.
    SelectObject(hDC, hPen);
    MoveToEx(hDC, a, b,NULL);
	LineTo(hDC,c, d);

    // Clean up.
    DeleteObject(hPen);
}

////////////////////////////////////////////////////////////////////////////////
// Draw My Line Extended
// HDC, left , top, right, bottom, Color Pen, Color Brush
void MyLineEx(HDC hDC,int a,int b,int c,int d,int iPenStyle, int iPenWidth, COLORREF crPen) 
{
	HGDIOBJ hPenOld;
    HPEN hPen ;

    // Create a pen.
    hPen = CreatePen(iPenStyle,iPenWidth, crPen);
    
    // Select the new pen and brush, and then draw.
    hPenOld = SelectObject(hDC, hPen);
    MoveToEx(hDC, a, b,NULL);
	LineTo(hDC,c, d);

    // Clean up.
    SelectObject(hDC, hPenOld);
    DeleteObject(hPen);
}

////////////////////////////////////////////////////////////////////////////////
// Draw My Ellipse
// HDC, left , top, right, bottom, Color Pen, Color Brush
void MyEllipse(HDC hDC,int a,int b,int c,int d,COLORREF crPen,COLORREF crBrush) 
{
    HPEN hPen ;
    HBRUSH hBrush ;

    // Create a pen.
    hPen = CreatePen(PS_SOLID,0, crPen);
    // Create a brush
    hBrush = CreateSolidBrush(crBrush);

    // Select the new pen and brush, and then draw.
    SelectObject(hDC, hPen);
    SelectObject(hDC, hBrush);
    Ellipse(hDC, a, b, c, d);

    // Clean up.
    DeleteObject(hPen);
    DeleteObject(hBrush);
}

////////////////////////////////////////////////////////////////////////////////
// Draw My Ellipse Extended
// HDC, left , top, right, bottom, Pen Style, Pen Width, Color Pen, Color Brush
void MyEllipseEx(HDC hDC,int a,int b,int c,int d,int iPenStyle, int iPenWidth,COLORREF crPen,COLORREF crBrush) 
{
    HPEN hPen ;
    HBRUSH hBrush ;

    // Create a pen.
    hPen = CreatePen(iPenStyle,iPenWidth, crPen);
    // Create a brush.
    hBrush = CreateSolidBrush(crBrush);

    // Select the new pen and brush, and then draw.
    SelectObject(hDC, hPen);
    SelectObject(hDC, hBrush);
    Ellipse(hDC, a, b, c, d);

    // Clean up.
    DeleteObject(hPen);
    DeleteObject(hBrush);
}

////////////////////////////////////////////////////////////////////////////////
// Draw Rectangle with Opacity
// HDC, left , top, right, bottom, Color Brush, Opacity
void RecOpac(HDC hDC,int a,int b,int c,int d,COLORREF crRec,int iOpac) 
{
	int x, y;
	COLORREF crBack;

	for(y=b;y<d;y++)
	for(x=a;x<c;x++)
	{
	crBack=GetPixel(hDC,x,y);
	SetPixel(hDC,x,y,RGB((GetRValue(crBack)*(100-iOpac)+GetRValue(crRec)*iOpac)/100,
		(GetGValue(crBack)*(100-iOpac)+GetGValue(crRec)*iOpac)/100,
		(GetBValue(crBack)*(100-iOpac)+GetBValue(crRec)*iOpac)/100));
	}
}

////////////////////////////////////////////////////////////////////////////////
// Save a region of screen to memory
// HDC, left, top, right, bottom ( of region,), pointer to a COLORREF
void ScreenToRam(HDC hDC,int a,int b,int c,int d,COLORREF *pCr)
{
	int x,y,i=0;

	
	for(y=b;y<d;y++)	
	for(x=a;x<c;x++)
		{
			*(pCr+i)=GetPixel(hDC,x,y);
			i++;
		}

}

////////////////////////////////////////////////////////////////////////////////
// Load picture from memory to screen
// HDC, left, top, right, bottom ( of region,), pointer to a COLORREF
void RamToScreen(HDC hDC,int a,int b,int c,int d,COLORREF *pCr)
{
	int x,y,i=0;

	for(y=b;y<d;y++)	
	for(x=a;x<c;x++)
		{
			SetPixel(hDC,x,y,*(pCr+i));
			i++;
		}
}

////////////////////////////////////////////////////////////////////////////////
// Load picture from memory to screen with Opacity
// HDC, left, top, right, bottom ( of region,), pointer to a COLORREF
void RamOpac(HDC hDC,int a,int b,int c,int d,COLORREF *pCr,int iOpac) 
{
	int x, y,i=0;
	COLORREF crBack;

	for(y=b;y<d;y++)
	for(x=a;x<c;x++)
	{
	crBack=GetPixel(hDC,x,y);
	SetPixel(hDC,x,y,RGB((GetRValue(crBack)*(100-iOpac)+GetRValue(*(pCr+i))*iOpac)/100,
		(GetGValue(crBack)*(100-iOpac)+GetGValue(*(pCr+i))*iOpac)/100,
		(GetBValue(crBack)*(100-iOpac)+GetBValue(*(pCr+i))*iOpac)/100));
	i++;
	}
}

////////////////////////////////////////////////////////////////////////////////
// Set Window Transparent
// hwnd : handle of window ; factor : transparent percent
// Note : Need #define WINVER 0x0500 before call #include <myheader.h>
void SetWindowTransparent(HWND hwnd,char factor)
{
HMODULE hDLL;
typedef DWORD (WINAPI *PSLWA)(HWND, DWORD, BYTE, DWORD);
PSLWA pSetLayeredWindowAttributes;

	// Load user32.dll	
	hDLL= LoadLibrary ("user32");
	// Get Function SetLayeredWindowAttributes
	pSetLayeredWindowAttributes = (PSLWA) GetProcAddress(hDLL, "SetLayeredWindowAttributes");
	// Set add-on to window
	SetWindowLong(hwnd, GWL_EXSTYLE , GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
	// Make Window Transparent
	pSetLayeredWindowAttributes (hwnd,NULL,(255*factor)/100,LWA_ALPHA);
}

////////////////////////////////////////////////////////////////////////////////
// Init Open Common Dialog 
BOOL OpenFileDlg (HWND hwnd, PTSTR pstrFilter, PTSTR pstrFileName)
{
OPENFILENAME ofn;

     ofn.lStructSize       = sizeof (OPENFILENAME) ;
     ofn.hwndOwner         = hwnd ;
     ofn.hInstance         = NULL ;
     ofn.lpstrFilter       = pstrFilter ;
     ofn.lpstrCustomFilter = NULL ;
     ofn.nMaxCustFilter    = 0 ;
     ofn.nFilterIndex      = 0 ;          
     ofn.nMaxFile          = MAX_PATH ;
     ofn.lpstrFileTitle    = NULL ;          
     ofn.nMaxFileTitle     = MAX_PATH ;
     ofn.lpstrInitialDir   = NULL ;
     ofn.lpstrTitle        = NULL ;
     ofn.Flags             = 0 ;             
     ofn.nFileOffset       = 0 ;
     ofn.nFileExtension    = 0 ;
     ofn.lpstrDefExt       = TEXT ("") ;
     ofn.lCustData         = 0L ;
     ofn.lpfnHook          = NULL ;
     ofn.lpTemplateName    = NULL ;

     ofn.lpstrFile         = pstrFileName ;
     ofn.Flags             = OFN_HIDEREADONLY ;
     
     return GetOpenFileName (&ofn) ;
}

////////////////////////////////////////////////////////////////////////////////
// Init Save Common Dialog 
BOOL SaveFileDlg (HWND hwnd, PTSTR pstrFilter, PTSTR pstrFileName)
{
OPENFILENAME ofn;

     ofn.lStructSize       = sizeof (OPENFILENAME) ;
     ofn.hwndOwner         = hwnd ;
     ofn.hInstance         = NULL ;
     ofn.lpstrFilter       = pstrFilter ;
     ofn.lpstrCustomFilter = NULL ;
     ofn.nMaxCustFilter    = 0 ;
     ofn.nFilterIndex      = 0 ;          
     ofn.nMaxFile          = MAX_PATH ;
     ofn.lpstrFileTitle    = NULL ;          
     ofn.nMaxFileTitle     = MAX_PATH ;
     ofn.lpstrInitialDir   = NULL ;
     ofn.lpstrTitle        = NULL ;
     ofn.Flags             = 0 ;             
     ofn.nFileOffset       = 0 ;
     ofn.nFileExtension    = 0 ;
     ofn.lpstrDefExt       = TEXT ("") ;
     ofn.lCustData         = 0L ;
     ofn.lpfnHook          = NULL ;
     ofn.lpTemplateName    = NULL ;

     ofn.lpstrFile         = pstrFileName ;
     ofn.Flags             = OFN_OVERWRITEPROMPT;
     
     return GetSaveFileName (&ofn) ;
}


CHOOSECOLOR ChooseColorDlg (HWND hwnd, COLORREF crResult)
{
CHOOSECOLOR ccolor;
COLORREF crCustom[16];

	ccolor.lStructSize = sizeof(CHOOSECOLOR);
	ccolor.hwndOwner = hwnd;
	ccolor.hInstance = NULL;
	ccolor.rgbResult = crResult;
	ccolor.lpCustColors = crCustom;
	ccolor.Flags = CC_RGBINIT | CC_FULLOPEN;
	ccolor.lCustData = 0;
	ccolor.lpfnHook = NULL;
	ccolor.lpTemplateName = NULL;

	return ccolor;
}

////////////////////////////////////////////////////////////////////////////////
// Track Mouse Timer Proc
VOID CALLBACK TrackMouseTimerProc(HWND hWnd,UINT uMsg,UINT idEvent,DWORD dwTime) 
{
RECT rect;
POINT pt;

      GetClientRect(hWnd,&rect);
      MapWindowPoints(hWnd,NULL,(LPPOINT)&rect,2);
      GetCursorPos(&pt);
      if (!PtInRect(&rect,pt) || (WindowFromPoint(pt) != hWnd)) 
	  {
         KillTimer(hWnd,idEvent);
         PostMessage(hWnd,WM_MOUSELEAVE,0,0);
      }
   }

/////////////////////////////////////////////////////////////////////////////////
// Track Mouse Event ( Need for WM_MOUSELEAVE -- This function send this message when mouse leave hWnd )
BOOL CheckMouseLeave(HWND hWnd) 
{
TRACKMOUSEEVENT tme;

	tme.cbSize = sizeof(TRACKMOUSEEVENT);
    tme.dwFlags = TME_LEAVE;
    tme.hwndTrack = hWnd;
	return SetTimer(tme.hwndTrack, tme.dwFlags,
                      50,(TIMERPROC)TrackMouseTimerProc);
}

////////////////////////////////////////////////////////////////////
// Rotate Point ( Center , Radius, Angle )
POINT RotatePoint(POINT pCenter, int iRadius, int iAngle)
{
POINT pTemp;
	
	pTemp.x = int ( iRadius * sin( TWOPI * iAngle / 360 ) ) + pCenter.x;
	pTemp.y = int ( iRadius * cos( TWOPI * iAngle / 360 ) ) + pCenter.y;

return pTemp;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -