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

📄 winfract.c

📁 frasr200的win 版本源码(18.21),使用make文件,使用的vc版本较低,在我的环境下编译有问题! 很不错的分形程序代码!
💻 C
📖 第 1 页 / 共 5 页
字号:

    SizeWindow(hwnd);
    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    /* let's ensure that we have at lease 40K of free memory */
    {
    HANDLE temphandle;
    if (!(temphandle = GlobalAlloc(GMEM_FIXED,40000L)) ||
        !(htemp_array = GlobalAlloc(GMEM_FIXED, 5L * sizeof(double) * MAXPIXELS))) {
        MessageBox (
            GetFocus(),
            winfract_msg97,
            winfract_msg01,
            MB_ICONSTOP | MB_OK);
        return(FALSE);
        }
        GlobalLock(temphandle);
        GlobalUnlock(temphandle);
        GlobalFree(temphandle);
        temp_array = (double far *)GlobalLock(htemp_array);
    }

   MakeHelpPathName(szHelpFileName);

    /* so, what kind of a display are we using, anyway? */
    hDC = GetDC(NULL);
    iPalSize    = GetDeviceCaps (hDC, SIZEPALETTE);
    iRasterCaps = GetDeviceCaps (hDC, RASTERCAPS);
    iRasterCaps = (iRasterCaps & RC_PALETTE) ? TRUE : FALSE;
    if (iRasterCaps)
       iNumColors = GetDeviceCaps(hDC, SIZEPALETTE);
    else
       iNumColors = GetDeviceCaps(hDC, NUMCOLORS);
    ReleaseDC(NULL,hDC);

    /* fudges for oddball stuff (is there any?) */
    /* also, note that "true color" devices return -1 for NUMCOLORS */
    colors = iNumColors;
    if (colors < 2 || colors > 16) colors = 256;
    if (colors > 2 && colors < 16) colors = 16;
    /* adjust for Windows' 20 reserved palettes in 256-color mode */
    max_colors = 256;
    if (colors == 256  && iNumColors >= 0) max_colors = 236;

     /* Allocate enough memory for a logical palette with
      * PALETTESIZE entries and set the size and version fields
      * of the logical palette structure.
      */
     if (!(hLogPal = GlobalAlloc (GMEM_FIXED,
        (sizeof (LOGPALETTE) +
        (sizeof (PALETTEENTRY) * (PALETTESIZE)))))) {
        MessageBox (
            GetFocus(),
            winfract_msg97,
            winfract_msg01,
            MB_ICONSTOP | MB_OK);
        return(FALSE);
          }
    pLogPal = (LPLOGPALETTE)GlobalLock(hLogPal); 
    pLogPal->palVersion    = 0x300;
    pLogPal->palNumEntries = PALETTESIZE;
    /* fill in intensities for all palette entry colors */
    for (iLoop = 0; iLoop < PALETTESIZE; iLoop++) {
        pLogPal->palPalEntry[iLoop].peRed   = iLoop;
        pLogPal->palPalEntry[iLoop].peGreen = 0;
        pLogPal->palPalEntry[iLoop].peBlue  = 0;
        pLogPal->palPalEntry[iLoop].peFlags = PC_EXPLICIT;
        }
    /* flip the ugly red color #1 with the pretty blue color #4 */
/*
    if (iNumColors < 0 || iNumColors > 4) {
        pLogPal->palPalEntry[1].peRed = 4;
        pLogPal->palPalEntry[4].peRed = 1;
        }
*/
    /*  create a logical color palette according the information
        in the LOGPALETTE structure. */
    hDC = GetDC(GetFocus());
    SetMapMode(hDC,MM_TEXT);
    hPal = CreatePalette ((LPLOGPALETTE) pLogPal) ;
    ReleaseDC(GetFocus(),hDC);

    /* allocate a device-independent bitmap header */
    if (!(hDibInfo = GlobalAlloc(GMEM_FIXED,
        sizeof(BITMAPINFOHEADER)+256*sizeof(PALETTEENTRY)))) {
        MessageBox (
            GetFocus(),
            winfract_msg97,
            winfract_msg01,
            MB_ICONSTOP | MB_OK);
        return(FALSE);
        }
    pDibInfo = (LPBITMAPINFO)GlobalLock(hDibInfo);
    /* fill in the header */
    pDibInfo->bmiHeader.biSize  = (long)sizeof(BITMAPINFOHEADER);
    pDibInfo->bmiHeader.biWidth  = win_xdots;
    pDibInfo->bmiHeader.biHeight = win_ydots;
    pDibInfo->bmiHeader.biSizeImage = (DWORD)win_xdots * win_ydots;
    pDibInfo->bmiHeader.biPlanes = 1;
    pDibInfo->bmiHeader.biBitCount = 8;
    pDibInfo->bmiHeader.biCompression = BI_RGB;
    pDibInfo->bmiHeader.biXPelsPerMeter = 0L;
    pDibInfo->bmiHeader.biYPelsPerMeter = 0L;
    pDibInfo->bmiHeader.biClrUsed = 0L;
    pDibInfo->bmiHeader.biClrImportant = 0L;
    default_dib_palette();

    IconWidth = GetSystemMetrics(SM_CXICON);
    IconHeight = GetSystemMetrics(SM_CYICON);
    IconSize = (IconWidth * IconHeight) >> pixelshift_per_byte;
    hIconBitmap = GlobalAlloc(GMEM_MOVEABLE, IconSize);

    /* initialize our delay counter */
    CalibrateDelay();
    win_cycledelay = 15;

    /* obtain an hourglass cursor */
    hHourGlass  = LoadCursor(NULL, IDC_WAIT);
    hSaveCursor = LoadCursor(NULL, IDC_ARROW);

    /* allocate and lock a pixel array for the initial bitmap */
    hpixels = (HANDLE) 0;
    pixels = (char huge *) NULL;
    if (hIconBitmap && clear_screen(0))
        return(TRUE);

    MessageBox (
        GetFocus(),
        winfract_msg97,
        winfract_msg01,
         MB_ICONSTOP | MB_OK);

    return (FALSE);

}

void lmemcpy(char huge *to, char huge *from, long len)
{
long i;

for (i = 0; i < len; i++)
  to[i] = from[i];
}

HWND SecondaryhWnd;
unsigned Secondarymessage;
WORD SecondarywParam;
LONG SecondarylParam;


long FAR PASCAL MainWndProc(hWnd, message, wParam, lParam)
HWND hWnd;				/* handle to main window */
unsigned message;
WORD wParam;
LONG lParam;
{

    RECT tempRect;
    HMENU hMenu;

    int Return;
    int i, fchoice;
    extern char FractintMenusStr[];
    extern char FractintPixelsStr[];

    switch (message) {

        case WM_INITMENU:
           if (!iRasterCaps || iNumColors < 16) {
               EnableMenuItem(GetMenu(hWnd), IDM_CYCLE, MF_DISABLED | MF_GRAYED);
               }
           hMenu = GetMenu(hWnd);
           if (winfract_menustyle) {
               CheckMenuItem(hMenu, IDF_FRACTINTSTYLE, MF_CHECKED);
               CheckMenuItem(hMenu, IDF_WINFRACTSTYLE, MF_UNCHECKED);
               }
           else {
               CheckMenuItem(hMenu, IDF_FRACTINTSTYLE, MF_UNCHECKED);
               CheckMenuItem(hMenu, IDF_WINFRACTSTYLE, MF_CHECKED);
               }
           if (win_fastupdate)
               CheckMenuItem(hMenu, IDM_PIXELS, MF_CHECKED);
           else
               CheckMenuItem(hMenu, IDM_PIXELS, MF_UNCHECKED);
           hWndCopy = hWnd;
           return (TRUE);
 
        case WM_LBUTTONDBLCLK:
            if(Zooming) {
               win_savedac();
               ExecuteZoom();
               }
            if (bMove) {
               DragPoint = MAKEPOINT(lParam);
        ExecZoom:
               /* End the selection */
               EndSelection(DragPoint, &Rect);
               ClearSelection(hWnd, &Rect, Shape);
	       win_title_text(-1);

               if(PtInRect(&Rect, DragPoint)) {
                  if (abs(Rect.bottom - Rect.top ) > 5 &&
                      abs(Rect.right  - Rect.left) > 5) {
                        double xd, yd, z;
                        extern POINT Center, ZoomDim;
                        extern double delxx, delyy;
		
			z = (double)(ZoomDim.x << 1) / xdots;
			if(ZoomMode == IDM_ZOOMOUT) {
			    z = 1.0 / z;
			    xd = (xxmin + xxmax) / 2 - (delxx * z * (Center.x + win_xoffset - (xdots/2)));
			    yd = (yymin + yymax) / 2 + (delxx * z * (Center.y + win_yoffset - (ydots/2)));
			    }
			else {
			    xd = xxmin + (delxx * (Center.x + win_xoffset));  /* BDT 11/6/91 */
			    yd = yymax - (delyy * (Center.y + win_yoffset));  /* BDT 11/6/91 */
			    }
			xxmin = xd - (delxx * z * (xdots / 2));
			xxmax = xd + (delxx * z * (xdots / 2));
			yymin = yd - (delyy * z * (ydots / 2));
			yymax = yd + (delyy * z * (ydots / 2));
			}

                      zoomflag = TRUE;
                      win_savedac();
                      time_to_restart = 1;
                      time_to_cycle = 0;
                      calc_status = 0;
                  }

                  bMove = FALSE;
                  bMoving = FALSE;
                  bTrack = FALSE;
               }

            break;

        case WM_LBUTTONDOWN:           /* message: left mouse button pressed */

            /* Start selection of region */

            if(bMove)
            {
               DragPoint = MAKEPOINT(lParam);
               bMoving   = PtInRect(&Rect, DragPoint);
               if(bMoving)
                  SetCapture(hWnd);
            }
            else if(Zooming)
               StartZoomTracking(lParam);
            else if(ZoomMode == IDM_ZOOMIN || ZoomMode == IDM_ZOOMOUT)
            {
	       win_title_text(3);
               bTrack = TRUE;
               bMoving = FALSE;
               bMove = FALSE;
               SetRectEmpty(&Rect);
               StartSelection(hWnd, MAKEPOINT(lParam), &Rect,
                   (wParam & MK_SHIFT) ? (SL_EXTEND | Shape) : Shape);
            }
            break;

        case WM_MOUSEMOVE:                        /* message: mouse movement */

            /* Update the selection region */

            if (bTrack || bMoving)
                UpdateSelection(hWnd, MAKEPOINT(lParam), &Rect, Shape);
            if(CoordBoxOpen)
                UpdateCoordBox(lParam);
            if(TrackingZoom)
               TrackZoom(lParam);
            break;

        case WM_LBUTTONUP:            /* message: left mouse button released */

            if(bTrack)
            {
               bTrack = FALSE;
               bMove = TRUE;
               ReleaseCapture();
               if (abs(Rect.bottom - Rect.top ) <= 5 ||
                   abs(Rect.right  - Rect.left) <= 5) {
                   /* Zoom Box is too small - kill it off */
                   ClearSelection(hWnd, &Rect, Shape);
	           win_title_text(-1);
                   bMove = bMoving = bTrack = FALSE;
                   }
            }
            else if(bMoving)
            {
               bMoving = FALSE;
               ReleaseCapture();
            }
            else if(TrackingZoom)
               EndZoom(lParam);
            break;

        case WM_RBUTTONUP:
            {
            int xx, yy;
            win_kill_all_zooming();
            xx = LOWORD(lParam);
            yy = HIWORD(lParam);
            xx += win_xoffset;
            yy += win_yoffset;
            if (xx >= xdots || yy >= ydots) 
                break;
            if (fractalspecific[fractype].tojulia != NOFRACTAL
                && param[0] == 0.0 && param[1] == 0.0) {
                /* switch to corresponding Julia set */
                fractype = fractalspecific[fractype].tojulia;
                curfractalspecific = &fractalspecific[fractype];
                param[0] = xxmin + (xxmax - xxmin) * xx / xdots;
                param[1] = yymax - (yymax - yymin) * yy / ydots;
                jxxmin = xxmin; jxxmax = xxmax;
                jyymax = yymax; jyymin = yymin;
                jxx3rd = xx3rd; jyy3rd = yy3rd;
                frommandel = 1;
                xxmin = fractalspecific[fractype].xmin;
                xxmax = fractalspecific[fractype].xmax;
                yymin = fractalspecific[fractype].ymin;
                yymax = fractalspecific[fractype].ymax;
                xx3rd = xxmin;
                yy3rd = yymin;
                if(biomorph != -1 && bitshift != 29) {
                   xxmin *= 3.0;
                   xxmax *= 3.0;
                   yymin *= 3.0;
                   yymax *= 3.0;
                   xx3rd *= 3.0;
                   yy3rd *= 3.0;
                   }
                calc_status = 0;
                }
            else if (fractalspecific[fractype].tomandel != NOFRACTAL) {
                /* switch to corresponding Mandel set */
                fractype = fractalspecific[fractype].tomandel;
                curfractalspecific = &fractalspecific[fractype];
                if (frommandel) {
                    xxmin = jxxmin;  xxmax = jxxmax;

⌨️ 快捷键说明

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