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

📄 g2_win32.c

📁 ViennaRNA-1.6.1
💻 C
📖 第 1 页 / 共 2 页
字号:
/*******************************************************************************  Copyright (C) 1998-2001  Ljubomir Milanovic & Horst Wagner**  This file is part of the g2 library****  This library is free software; you can redistribute it and/or**  modify it under the terms of the GNU Lesser General Public**  License as published by the Free Software Foundation; either**  version 2.1 of the License, or (at your option) any later version.****  This library is distributed in the hope that it will be useful,**  but WITHOUT ANY WARRANTY; without even the implied warranty of**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU**  Lesser General Public License for more details.****  You should have received a copy of the GNU Lesser General Public**  License along with this library; if not, write to the Free Software**  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA******************************************************************************/#include <stdio.h>#include <stdlib.h>#include <math.h>#include "g2.h"#include "g2_device.h"#include "g2_util.h"#include "g2_config.h"#include "g2_win32.h"#include "g2_win32_P.h"#include "g2_win32_funix.h"#include "resource.h"/* Global Definitions */int g2_win32_registered = FALSE;HINSTANCE g2res_DLL;	/* Instance of the resource DLL */#define PDP ((struct g2_win32_STRUCT *)pdp)#ifndef PI#define PI 3.14159265358979323846#endif /* PI */#define sgn(x) (x>0?1:x?-1:0)/* someday their might be a DLL version of g2 */#ifdef G2DLLBOOL WINAPI DllMain( HANDLE hModule, DWORD fdwreason,  LPVOID lpReserved ){    switch(fdwreason) {    case DLL_PROCESS_ATTACH:    // The DLL is being mapped into process's address space    //  Do any required initialization on a per application basis, return FALSE if failed    MessageBox(NULL, "DLL Process Attach", "DLL Message 1", MB_OK);    	break;    case DLL_THREAD_ATTACH:    // A thread is created. Do any required initialization on a per thread basis    MessageBox(NULL, "DLL Thread Attach", "DLL Message 1", MB_OK);        break;    case DLL_THREAD_DETACH:    // Thread exits with  cleanup    MessageBox(NULL, "DLL Thread Detach", "DLL Message 1", MB_OK);        break;    case DLL_PROCESS_DETACH:    // The DLL unmapped from process's address space. Do necessary cleanup    MessageBox(NULL, "DLL Process Detach", "DLL Message 1", MB_OK);        break;	default:	MessageBox(NULL, "DLL default", "DLL Message 1", MB_OK);        }    return TRUE;}#endifg2_win32_SetPen(int pid, void *pdp)	{	HGDIOBJ oldpen;    LOGBRUSH    logBrush ;	logBrush.lbStyle = PS_SOLID;	logBrush.lbColor = PDP->Inks[PDP->Pen];    logBrush.lbHatch = 0 ;	oldpen = PDP->hPen;	PDP->hPen = ExtCreatePen (logBrush.lbStyle | PS_GEOMETRIC |                          PS_ENDCAP_FLAT | PS_JOIN_BEVEL | (PDP->PenStyle > 0)*PS_USERSTYLE,                         PDP->PenWidth, &logBrush,                         PDP->PenStyle , PDP->PenDash) ;	if (PDP->hPen != NULL) 		{		SelectObject(PDP->hMemDC,PDP->hPen);/*		if (PDP->type == g2_win32)*/		DeleteObject(oldpen);		}	else		{		errhandler("Pen",NULL);		PDP->hPen = oldpen;		}	oldpen = PDP->hNullPen;	PDP->hNullPen = CreatePen(PS_SOLID,1,PDP->Inks[PDP->Pen]);	if (PDP->hNullPen != NULL) 		{/*		if (PDP->type == g2_win32)*/		DeleteObject(oldpen);		}	else		{		errhandler("Pen",NULL);		PDP->hNullPen = oldpen;		}	return 0;	}int g2_win32_Cleanup(int pid, void *pdp)	{	struct g2_win32_STRUCT *thispdp;	thispdp = pdp;	g2_win32_ClearPalette(pid,pdp);	if (PDP->hBrush != NULL) DeleteObject(PDP->hBrush);	if (PDP->hPen != NULL) DeleteObject(PDP->hPen);	if (PDP->hNullPen != NULL) DeleteObject(PDP->hPen);	if (PDP->hFont != NULL) DeleteObject(PDP->hFont);	if (PDP->hBitmap != NULL) DeleteObject(PDP->hBitmap);	if (PDP->hMemDC != NULL) DeleteDC(PDP->hMemDC);	if (PDP->PenDash != NULL) free(PDP->PenDash);	free(thispdp);	return 0;	}int g2_win32_Delete(int pid, void *pdp)	{	switch(PDP->type)		{		case g2_win32:			SendMessage(PDP->hwndThreadWindow,WM_CLOSE,(WPARAM)NULL,(LPARAM)NULL);			break;		case g2_wmf32:			{			CloseEnhMetaFile(PDP->hMemDC);			g2_win32_Cleanup(pid,pdp);			break;			}		}	return 0;    }int g2_win32_Clear(int pid, void *pdp)	{	int OldPen;	OldPen = PDP->Pen;	g2_win32_Pen(pid,pdp,PDP->BkColor);	g2_win32_FilledRectangle(pid,pdp,0,0,PDP->nWidth,PDP->nHeight);	g2_win32_Pen(pid,pdp,OldPen);	return 0;    }int g2_win32_Flush(int pid, void *pdp)	{	InvalidateRect(PDP->hwndThreadWindow, (RECT *)NULL, TRUE); 	return 0;    }int g2_win32_Pen(int pid, void *pdp, int color)	{	struct tagLOGBRUSH logbrush;	HGDIOBJ oldbrush;		if(color>=PDP->NoOfInks || color<0)		{		fprintf(stderr,"g2_WIN32: Ink %d not defined\n",color);		return -1;		}	PDP->Pen = color;	PDP->PenColor = PDP->Inks[color];	g2_win32_SetPen(pid,pdp);	logbrush.lbStyle = BS_SOLID;	logbrush.lbColor = PDP->PenColor;	oldbrush = PDP->hBrush;	PDP->hBrush = CreateBrushIndirect(&logbrush);	if (PDP->hBrush == NULL) 		{		errhandler("Pen (CreateBrush)",NULL);		PDP->hBrush = oldbrush;		}	else/*		if (PDP->type == g2_win32)*/		DeleteObject(oldbrush);	return 0;    }int g2_win32_Ink(int pid, void *pdp, double red, double green, double blue)	{	BYTE rc,gc,bc;	rc = (BYTE)((int)(red*255));	gc = (BYTE)((int)(green*255));	bc = (BYTE)((int)(blue*255));	PDP->NoOfInks++;	if(PDP->Inks==NULL)		PDP->Inks=(COLORREF *)malloc(PDP->NoOfInks*sizeof(COLORREF));	else		PDP->Inks=(COLORREF *)realloc((void *)PDP->Inks,PDP->NoOfInks*sizeof(COLORREF));	if(PDP->Inks==NULL) 		{		fputs("g2: not enough memory\n",stderr);		return -1;		}	PDP->Inks[PDP->NoOfInks-1]=RGB(rc,gc,bc);	return PDP->NoOfInks-1;	}	int g2_win32_ClearPalette(int pid, void *pdp)	{	if (PDP->Inks != NULL)		free(PDP->Inks);	PDP->Inks = NULL;	PDP->NoOfInks = 0;	return 0;    }int g2_win32_SetBackground(int pid, void *pdp, int color)	{	PDP->BkColor = color;	SetBkColor(PDP->hMemDC,PDP->BkColor);	return 0;    }int g2_win32_SetLineWidth(int pid, void *pdp, int w)	{	PDP->PenWidth = w;	g2_win32_SetPen(pid,pdp);	return 0;    }int g2_win32_SetDash(int pid, void *pdp, int n, int *data)	{	if (PDP->PenDash != NULL)		free(PDP->PenDash);	PDP->PenDash = NULL;	PDP->PenStyle = n;	if (n > 0) 		{		int i;		PDP->PenDash = (DWORD *)malloc(n*sizeof(DWORD));		for (i=0;i<n;i++)			PDP->PenDash[i] = data[i];		}	g2_win32_SetPen(pid,pdp);	return 0;	}int g2_win32_SetFontSize(int pid, void *pdp, int size)	{	//static LOGFONT lf = {10,0,0,0,0,0,0,0,0,0,0,0,0,"Arial\0"};    HGDIOBJ oldfont;   	oldfont = PDP->hFont;	//lf.lfHeight = size;	//PDP->hFont = CreateFontIndirect(&lf);	PDP->hFont = CreateFont(-size, 0, 0, 0, FW_NORMAL, 0, 0, 0, 0, OUT_TT_ONLY_PRECIS , 0, PROOF_QUALITY,0, "Times New Roman\0");	if (PDP->hFont == NULL) 		{		errhandler("Font (CreateFont)",NULL);		PDP->hFont = oldfont;		}	else		{		SelectObject(PDP->hMemDC,PDP->hFont);		if (oldfont != NULL)// && PDP->type == g2_win32)			DeleteObject(oldfont);		}	return 0;    }int g2_win32_Plot(int pid, void *pdp, int x, int y)	{	return SetPixel(PDP->hMemDC,x,y,PDP->PenColor);    }int g2_win32_Line(int pid, void *pdp, int x1, int y1, int x2, int y2)	{	MoveToEx(PDP->hMemDC,x1,y1,NULL);	LineTo(PDP->hMemDC,x2,y2);	SetPixel(PDP->hMemDC,x1,y1,PDP->PenColor);	SetPixel(PDP->hMemDC,x2,y2,PDP->PenColor);	// specifically draw end points since windows does not include one endpoint	return 0;    }int g2_win32_PolyLine(int pid, void *pdp, int N, int *points)	{	POINT *PointList;	int i;	PointList = (POINT *)malloc(N*sizeof(POINT));	if (PointList == NULL)		{		fprintf(stderr,"g2_win32: not enough memory !\n");		return -1;		}	for (i=0;i<N;i++)		{		PointList[i].x = points[2*i];		PointList[i].y = points[2*i+1];		}	Polyline(PDP->hMemDC,PointList,N);	free(PointList);	return 0;    }int g2_win32_Rectangle(int pid, void *pdp, int x, int y, int x2, int y2)	{	SelectObject(PDP->hMemDC,GetStockObject(NULL_BRUSH));	Rectangle(PDP->hMemDC,x,y,x2+1,y2+1); // add one since windows excludes lower right point

⌨️ 快捷键说明

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