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

📄 pgpoptionsdialog.cpp

📁 vc环境下的pgp源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*____________________________________________________________________________
	Copyright (C) 1997 Network Associates Inc. and affiliated companies.
	All rights reserved.
	
	$Id: PGPOptionsDialog.cpp,v 1.3 1999/03/10 02:53:58 heller Exp $
____________________________________________________________________________*/

// Public includes:

#include "pgpDialogs.h"

#define CHECKWIDTH 19
#define INDENT 19
#define LINESPERCONTROL 1.60
#define COMBOSPACER 5
#define COMBOYADJ 3

int NumLines (char *pText, int Width)
{
	int  iBreakCount ;
	char * pBegin = 0, * pEnd = 0 ;
	int numrows;

	(void) Width;

	numrows = 0;
	do                               // for each text line
	{
		iBreakCount = 0 ;
	
		pBegin = pText ;

//		do                           // until the line is known
	//	{
	//		pEnd = pText ;
//
//			while (*pText != '\0' && *pText++ != ' ') ;
//			if (*pText == '\0')
//				break ;
//                                     // for each space, calculate extents
//			iBreakCount++ ;
//			SetTextJustification (hdc, 0, 0) ;
//			GetTextExtentPoint32 (hdc, pBegin, pText - pBegin - 1, &size) ;
//		}
//		while ((int) size.cx < Width) ;

		iBreakCount-- ;
		while (*(pEnd - 1) == ' ')   // eliminate trailing blanks
		{
			pEnd-- ;
			iBreakCount-- ;
		}

		if (*pText == '\0' || iBreakCount <= 0)
			pEnd = pText;

//		SetTextJustification (hdc, 0, 0) ;
//		GetTextExtentPoint32 (hdc, pBegin, pEnd - pBegin, &size) ;

		numrows++;
		pText = pEnd ;
	} while (*pText);

	return numrows;
}

#if 0
int GetClientWidth(HWND hwnd)
{
	RECT rc;

	GetClientRect(hwnd,&rc);
	return(rc.right-rc.left-GetSystemMetrics(SM_CXVSCROLL));
}

HWND MakeDescription(HWND hwndParent,
				 HDC hdc,
				 HFONT hFont,
				 int ID,
				 const char *String,
				 int *y,
				 int MaxWidth)
{
	int NumberOfLines;
	HWND hwndDesc;
	SIZE size;

	if(*String==0)
		return NULL;

	GetTextExtentPoint32(hdc,String,strlen(String),&size);

	NumberOfLines=NumLines(hdc,(char *)String,MaxWidth-INDENT);

	hwndDesc = CreateWindow ("static", String,
                              WS_CHILDWINDOW | WS_VISIBLE | SS_LEFT,
                              size.cy+INDENT,*y,
                              MaxWidth-INDENT,size.cy*NumberOfLines,
                              hwndParent, (HMENU) ID,
                              g_hInst, NULL) ;

	*y=(int)((double)(*y)+
		((double)LINESPERCONTROL + (double)NumberOfLines - (double)1) *
			(double)size.cy);

	SendMessage(hwndDesc, WM_SETFONT,(WPARAM)hFont, MAKELPARAM(TRUE, 0));

	return hwndDesc;
}

HWND MakeCheckBox(HWND hwndParent,
				 HDC hdc,
				 HFONT hFont,
				 PGPOUICheckboxDesc *Descriptor,
				 int *y,
				 int MaxWidth)
{
	HWND hwndCheckBox;
	SIZE size;

	GetTextExtentPoint32(hdc,Descriptor->title,strlen(Descriptor->title),&size);

	hwndCheckBox = CreateWindow ("button", Descriptor->title,
		WS_CHILD | WS_VISIBLE | BS_CHECKBOX | WS_TABSTOP,
        size.cy,*y,
        size.cx+CHECKWIDTH,size.cy,
        hwndParent, (HMENU) Descriptor->itemID,
        g_hInst, NULL) ;

	*y=(int)((double)*y + (double)size.cy * (double)LINESPERCONTROL);

	SendMessage(hwndCheckBox, WM_SETFONT,
		(WPARAM)hFont, MAKELPARAM(TRUE, 0));

	Button_SetCheck (hwndCheckBox,*(Descriptor->valuePtr));

	if(Descriptor->description!=NULL)
		MakeDescription(hwndParent,hdc,hFont,
			5000+Descriptor->itemID,Descriptor->description,y,MaxWidth);

	SetWindowLong(hwndCheckBox, GWL_USERDATA, (DWORD)Descriptor->valuePtr);    

	return hwndCheckBox;
}

int MeasureComboBox(HDC hdc,PGPOUIPopupListDesc *Descriptor)
{
	SIZE size;
	unsigned int itemIndex;
	int ComboWidth;

	ComboWidth=0;

	// Find the longest text element
	for(itemIndex = 0; itemIndex < Descriptor->numListItems; itemIndex++)
	{
		if( IsntNull( Descriptor->listItems[itemIndex] ) )
		{
			GetTextExtentPoint32(hdc,Descriptor->listItems[itemIndex],
				strlen(Descriptor->listItems[itemIndex]),&size);
			if(size.cx>ComboWidth)ComboWidth=size.cx;
		}
	}

	ComboWidth=ComboWidth+2*GetSystemMetrics(SM_CXVSCROLL);

	return ComboWidth;
}

HWND MakeComboBox(HWND hwndParent,
				 HDC hdc,
				 HFONT hFont,
				 PGPOUIPopupListDesc *Descriptor,
				 int *y,
				 int MaxWidth)
{
	HWND hwndText,hwndComboBox;
	SIZE size;
	unsigned int itemIndex;

	GetTextExtentPoint32(hdc,Descriptor->title,strlen(Descriptor->title),&size);

	hwndText = CreateWindow ("static", Descriptor->title,
		WS_CHILDWINDOW | WS_VISIBLE | SS_LEFT ,
		size.cy,*y,
		size.cx,size.cy,
		hwndParent, (HMENU) (1000+Descriptor->itemID),
		g_hInst, NULL) ;

	SendMessage(hwndText, WM_SETFONT,
		(WPARAM)hFont, MAKELPARAM(TRUE, 0));

	hwndComboBox = CreateWindow ("combobox",NULL,
		WS_CHILD | WS_VISIBLE | CBS_DROPDOWN | WS_TABSTOP,
		size.cy+size.cx+COMBOSPACER,*y-COMBOYADJ,
		MeasureComboBox(hdc,Descriptor),size.cy*6,
        hwndParent, (HMENU)Descriptor->itemID,
		g_hInst, NULL) ;

		*y=(int)((double)*y + (double)size.cy * (double)(LINESPERCONTROL));

	for(itemIndex = 0; itemIndex < Descriptor->numListItems; itemIndex++)
	{
		if( IsntNull( Descriptor->listItems[itemIndex] ) )
		{
			SendMessage (hwndComboBox, CB_ADDSTRING, 0, 
				(LPARAM)Descriptor->listItems[itemIndex]);
		}
	}

	SendMessage(hwndComboBox,CB_SETCURSEL,
		(WPARAM)(*Descriptor->valuePtr-1),0);

	SendMessage(hwndComboBox, WM_SETFONT,
		(WPARAM)hFont, MAKELPARAM(TRUE, 0));

	if(Descriptor->description!=NULL)
		MakeDescription(hwndParent,hdc,hFont,
			5000+Descriptor->itemID,Descriptor->description,y,MaxWidth);

	SetWindowLong(hwndComboBox, GWL_USERDATA, (DWORD)Descriptor->valuePtr);    

	return hwndComboBox;
}

int MeasureOptionsControls(HDC hdc,PGPOptionListRef options)
{
	PGPUInt32	optionIndex	= 0;
	PGPOption	optionData;
	int MaxWidth;
	SIZE size;

	if(options==NULL)
		return(0);

	MaxWidth=0;

	/* Build list of checkboxes and/or popups */
	
	while( IsntPGPError( pgpGetIndexedOption( options,
					optionIndex, FALSE, &optionData ) ) )
	{
		if( optionData.type == kPGPOptionType_Checkbox )
		{
			PGPOUICheckboxDesc		*descriptor;
			
			descriptor = (PGPOUICheckboxDesc *) optionData.value.asPtr;

			GetTextExtentPoint32(hdc,descriptor->title,
					strlen(descriptor->title),&size);

			if(size.cx>MaxWidth)MaxWidth=size.cx;
		}
		else if( optionData.type == kPGPOptionType_PopupList )
		{
			PGPOUIPopupListDesc		*descriptor;
			
			descriptor = (PGPOUIPopupListDesc *) optionData.value.asPtr;

			GetTextExtentPoint32(hdc,descriptor->title,
					strlen(descriptor->title),&size);
			size.cx=size.cx+COMBOSPACER;
			size.cx=size.cx+MeasureComboBox(hdc,descriptor);

			if(size.cx>MaxWidth)MaxWidth=size.cx;
		}		
		++optionIndex;
	}

	return MaxWidth;
}

	PGPError
CreateOptionsControls(HWND hwndOptionsControl,
					  HDC hdc,HFONT hFont,
					  int *ypos,int MaxWidth,
					  PGPOptionListRef options)
{
	PGPError	err 		= kPGPError_NoErr;
	PGPUInt32	optionIndex	= 0;
	PGPOption	optionData;
	
	if(options==NULL)
		return( err);

	/* Build list of checkboxes and/or popups */
	
	while( IsntPGPError( pgpGetIndexedOption( options,
					optionIndex, FALSE, &optionData ) ) )
	{
		if( optionData.type == kPGPOptionType_Checkbox )
		{
			PGPOUICheckboxDesc		*descriptor;
			HWND checkboxView;
			
			descriptor = (PGPOUICheckboxDesc *) optionData.value.asPtr;

			checkboxView = MakeCheckBox(
				hwndOptionsControl,
				hdc,hFont,
				descriptor,
				ypos,MaxWidth);
		}
		else if( optionData.type == kPGPOptionType_PopupList )
		{
			PGPOUIPopupListDesc		*descriptor;
			HWND popupView;
			
			descriptor = (PGPOUIPopupListDesc *) optionData.value.asPtr;

			popupView = MakeComboBox(
				hwndOptionsControl,
				hdc,hFont,
				descriptor,
				ypos,MaxWidth);
		}		
		++optionIndex;
	}

	return( err );
}

LRESULT CALLBACK CustomOptionsWndProc (HWND hwnd, UINT iMsg, WPARAM wParam,
					LPARAM lParam)
	{
	static int  cxChar, cxCaps, cyChar,MaxWidth,NUMLINES,cxClient,cyClient,
		iVscrollPos, iVscrollMax, iHscrollPos, iHscrollMax,
		iVscrollInc,iHscrollInc;

	switch (iMsg)
	{
		case WM_CREATE :
		{
			PGPOptionListRef options;
			LPCREATESTRUCT lpcs;
			HFONT hFont;
			LOGFONT lf;
			int ypos;
			HDC hdc;
			TEXTMETRIC tm;
			int HeaderWidths;
			
			lpcs=(LPCREATESTRUCT)lParam;
			options=(PGPOptionListRef)lpcs->lpCreateParams;
			SetWindowLong(hwnd, GWL_USERDATA, (DWORD)options);    

			SystemParametersInfo (SPI_GETICONTITLELOGFONT, 
				sizeof(LOGFONT), &lf, 0);

			hFont=CreateFontIndirect (&lf);
				   
			hdc=GetDC(hwnd);
			SelectObject(hdc,hFont);

			GetTextMetrics (hdc, &tm) ;
			cxChar = tm.tmAveCharWidth ;

⌨️ 快捷键说明

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