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

📄 dlg_wingui.c

📁 postgresql-odbc,跨平台应用
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifdef	WIN32/*------- * Module:			dlg_wingui.c * * Description:		This module contains any specific code for handling *					dialog boxes such as driver/datasource options.  Both the *					ConfigDSN() and the SQLDriverConnect() functions use *					functions in this module.  If you were to add a new option *					to any dialog box, you would most likely only have to change *					things in here rather than in 2 separate places as before. * * Classes:			none * * API functions:	none * * Comments:		See "notice.txt" for copyright and license information. *------- *//* Multibyte support	Eiji Tokuya 2001-03-15 */#include "dlg_specific.h"#include "win_setup.h"#include "convert.h"#include "loadlib.h"#include "multibyte.h"#include "pgapifunc.h"extern GLOBAL_VALUES globals;extern HINSTANCE NEAR s_hModule;static int	driver_optionsDraw(HWND, const ConnInfo *, int src, BOOL enable);static int	driver_options_update(HWND hdlg, ConnInfo *ci, const char *);voidSetDlgStuff(HWND hdlg, const ConnInfo *ci){	char	buff[MEDIUM_REGISTRY_LEN + 1];	BOOL	libpq_exist = FALSE;	/*	 * If driver attribute NOT present, then set the datasource name and	 * description	 */	SetDlgItemText(hdlg, IDC_DSNAME, ci->dsn);	SetDlgItemText(hdlg, IDC_DESC, ci->desc);	SetDlgItemText(hdlg, IDC_DATABASE, ci->database);	SetDlgItemText(hdlg, IDC_SERVER, ci->server);	SetDlgItemText(hdlg, IDC_USER, ci->username);	SetDlgItemText(hdlg, IDC_PASSWORD, ci->password);	SetDlgItemText(hdlg, IDC_PORT, ci->port);	libpq_exist = LIBPQ_check();mylog("libpq_exist=%d\n", libpq_exist);	if (libpq_exist)		ShowWindow(GetDlgItem(hdlg, IDC_NOTICE_USER), SW_HIDE);	else	{mylog("SendMessage CTL_COLOR\n");		SendMessage(GetDlgItem(hdlg, IDC_NOTICE_USER), WM_CTLCOLOR, 0, 0);	}	LoadString(GetWindowInstance(hdlg), IDS_SSLREQUEST_DISABLE, buff, MEDIUM_REGISTRY_LEN);	SendDlgItemMessage(hdlg, IDC_SSLMODE, CB_ADDSTRING, 0, (WPARAM) buff);	if (libpq_exist || (ci->sslmode[0] && stricmp(ci->sslmode, "disable")))	{		LoadString(GetWindowInstance(hdlg), IDS_SSLREQUEST_PREFER, buff, MEDIUM_REGISTRY_LEN);		SendDlgItemMessage(hdlg, IDC_SSLMODE, CB_ADDSTRING, 0, (WPARAM) buff);		LoadString(GetWindowInstance(hdlg), IDS_SSLREQUEST_ALLOW, buff, MEDIUM_REGISTRY_LEN);		SendDlgItemMessage(hdlg, IDC_SSLMODE, CB_ADDSTRING, 0, (WPARAM) buff);		LoadString(GetWindowInstance(hdlg), IDS_SSLREQUEST_REQUIRE, buff, MEDIUM_REGISTRY_LEN);		SendDlgItemMessage(hdlg, IDC_SSLMODE, CB_ADDSTRING, 0, (WPARAM) buff);	}	if (!stricmp(ci->sslmode, "allow"))		LoadString(GetWindowInstance(hdlg), IDS_SSLREQUEST_ALLOW, buff, MEDIUM_REGISTRY_LEN);	else if (!stricmp(ci->sslmode, "require"))		LoadString(GetWindowInstance(hdlg), IDS_SSLREQUEST_REQUIRE, buff, MEDIUM_REGISTRY_LEN);	else if (!stricmp(ci->sslmode, "prefer"))		LoadString(GetWindowInstance(hdlg), IDS_SSLREQUEST_PREFER, buff, MEDIUM_REGISTRY_LEN);	else		LoadString(GetWindowInstance(hdlg), IDS_SSLREQUEST_DISABLE, buff, MEDIUM_REGISTRY_LEN);	SendDlgItemMessage(hdlg, IDC_SSLMODE, CB_SELECTSTRING, -1, (WPARAM) ((LPSTR) buff));}voidGetDlgStuff(HWND hdlg, ConnInfo *ci){	int	sslposition;	GetDlgItemText(hdlg, IDC_DESC, ci->desc, sizeof(ci->desc));	GetDlgItemText(hdlg, IDC_DATABASE, ci->database, sizeof(ci->database));	GetDlgItemText(hdlg, IDC_SERVER, ci->server, sizeof(ci->server));	GetDlgItemText(hdlg, IDC_USER, ci->username, sizeof(ci->username));	GetDlgItemText(hdlg, IDC_PASSWORD, ci->password, sizeof(ci->password));	GetDlgItemText(hdlg, IDC_PORT, ci->port, sizeof(ci->port));	sslposition = (int)(DWORD)SendMessage(GetDlgItem(hdlg, IDC_SSLMODE), CB_GETCURSEL, 0L, 0L);	switch (sslposition)	{		case 1:	strncpy(ci->sslmode, "prefer", sizeof(ci->sslmode));			break;		case 2:	strncpy(ci->sslmode, "allow", sizeof(ci->sslmode));			break;		case 3:	strncpy(ci->sslmode, "require", sizeof(ci->sslmode));			break;		default:strncpy(ci->sslmode, "disable", sizeof(ci->sslmode));			break;	}}static intdriver_optionsDraw(HWND hdlg, const ConnInfo *ci, int src, BOOL enable){	const GLOBAL_VALUES *comval;	static BOOL defset = FALSE;	static GLOBAL_VALUES defval;	switch (src)	{		case 0:			/* driver common */			comval = &globals;			break;		case 1:			/* dsn specific */			comval = &(ci->drivers);			break;		case 2:			/* default */			if (!defset)			{				defval.commlog = DEFAULT_COMMLOG;				defval.disable_optimizer = DEFAULT_OPTIMIZER;				defval.ksqo = DEFAULT_KSQO;				defval.unique_index = DEFAULT_UNIQUEINDEX;				defval.onlyread = DEFAULT_READONLY;				defval.use_declarefetch = DEFAULT_USEDECLAREFETCH;				defval.parse = DEFAULT_PARSE;				defval.cancel_as_freestmt = DEFAULT_CANCELASFREESTMT;				defval.debug = DEFAULT_DEBUG;				/* Unknown Sizes */				defval.unknown_sizes = DEFAULT_UNKNOWNSIZES;				defval.text_as_longvarchar = DEFAULT_TEXTASLONGVARCHAR;				defval.unknowns_as_longvarchar = DEFAULT_UNKNOWNSASLONGVARCHAR;				defval.bools_as_char = DEFAULT_BOOLSASCHAR;			}			defset = TRUE;			comval = &defval;			break;	}	ShowWindow(GetDlgItem(hdlg, DRV_MSG_LABEL2), enable ? SW_SHOW : SW_HIDE);	CheckDlgButton(hdlg, DRV_COMMLOG, comval->commlog);#ifndef Q_LOG	EnableWindow(GetDlgItem(hdlg, DRV_COMMLOG), FALSE);#endif /* Q_LOG */	CheckDlgButton(hdlg, DRV_OPTIMIZER, comval->disable_optimizer);	CheckDlgButton(hdlg, DRV_KSQO, comval->ksqo);	CheckDlgButton(hdlg, DRV_UNIQUEINDEX, comval->unique_index);	/* EnableWindow(GetDlgItem(hdlg, DRV_UNIQUEINDEX), enable); */	CheckDlgButton(hdlg, DRV_READONLY, comval->onlyread);	EnableWindow(GetDlgItem(hdlg, DRV_READONLY), enable);	CheckDlgButton(hdlg, DRV_USEDECLAREFETCH, comval->use_declarefetch);	/* Unknown Sizes clear */	CheckDlgButton(hdlg, DRV_UNKNOWN_DONTKNOW, 0);	CheckDlgButton(hdlg, DRV_UNKNOWN_LONGEST, 0);	CheckDlgButton(hdlg, DRV_UNKNOWN_MAX, 0);	/* Unknown (Default) Data Type sizes */	switch (comval->unknown_sizes)	{		case UNKNOWNS_AS_DONTKNOW:			CheckDlgButton(hdlg, DRV_UNKNOWN_DONTKNOW, 1);			break;		case UNKNOWNS_AS_LONGEST:			CheckDlgButton(hdlg, DRV_UNKNOWN_LONGEST, 1);			break;		case UNKNOWNS_AS_MAX:		default:			CheckDlgButton(hdlg, DRV_UNKNOWN_MAX, 1);			break;	}	CheckDlgButton(hdlg, DRV_TEXT_LONGVARCHAR, comval->text_as_longvarchar);	CheckDlgButton(hdlg, DRV_UNKNOWNS_LONGVARCHAR, comval->unknowns_as_longvarchar);	CheckDlgButton(hdlg, DRV_BOOLS_CHAR, comval->bools_as_char);	CheckDlgButton(hdlg, DRV_PARSE, comval->parse);	CheckDlgButton(hdlg, DRV_CANCELASFREESTMT, comval->cancel_as_freestmt);	CheckDlgButton(hdlg, DRV_DEBUG, comval->debug);#ifndef MY_LOG	EnableWindow(GetDlgItem(hdlg, DRV_DEBUG), FALSE);#endif /* MY_LOG */	SetDlgItemInt(hdlg, DRV_CACHE_SIZE, comval->fetch_max, FALSE);	SetDlgItemInt(hdlg, DRV_VARCHAR_SIZE, comval->max_varchar_size, FALSE);	SetDlgItemInt(hdlg, DRV_LONGVARCHAR_SIZE, comval->max_longvarchar_size, TRUE);	SetDlgItemText(hdlg, DRV_EXTRASYSTABLEPREFIXES, comval->extra_systable_prefixes);	/* Driver Connection Settings */	SetDlgItemText(hdlg, DRV_CONNSETTINGS, comval->conn_settings);	EnableWindow(GetDlgItem(hdlg, DRV_CONNSETTINGS), enable);	ShowWindow(GetDlgItem(hdlg, IDPREVPAGE), enable ? SW_HIDE : SW_SHOW);	ShowWindow(GetDlgItem(hdlg, IDNEXTPAGE), enable ? SW_HIDE : SW_SHOW);	return 0;}static intdriver_options_update(HWND hdlg, ConnInfo *ci, const char *updateDriver){	GLOBAL_VALUES *comval;	if (ci)		comval = &(ci->drivers);	else		comval = &globals;	comval->commlog = IsDlgButtonChecked(hdlg, DRV_COMMLOG);	comval->disable_optimizer = IsDlgButtonChecked(hdlg, DRV_OPTIMIZER);	comval->ksqo = IsDlgButtonChecked(hdlg, DRV_KSQO);	comval->unique_index = IsDlgButtonChecked(hdlg, DRV_UNIQUEINDEX);	if (!ci)	{		comval->onlyread = IsDlgButtonChecked(hdlg, DRV_READONLY);	}	comval->use_declarefetch = IsDlgButtonChecked(hdlg, DRV_USEDECLAREFETCH);	/* Unknown (Default) Data Type sizes */	if (IsDlgButtonChecked(hdlg, DRV_UNKNOWN_MAX))		comval->unknown_sizes = UNKNOWNS_AS_MAX;	else if (IsDlgButtonChecked(hdlg, DRV_UNKNOWN_DONTKNOW))		comval->unknown_sizes = UNKNOWNS_AS_DONTKNOW;	else if (IsDlgButtonChecked(hdlg, DRV_UNKNOWN_LONGEST))		comval->unknown_sizes = UNKNOWNS_AS_LONGEST;	else		comval->unknown_sizes = UNKNOWNS_AS_MAX;	comval->text_as_longvarchar = IsDlgButtonChecked(hdlg, DRV_TEXT_LONGVARCHAR);	comval->unknowns_as_longvarchar = IsDlgButtonChecked(hdlg, DRV_UNKNOWNS_LONGVARCHAR);	comval->bools_as_char = IsDlgButtonChecked(hdlg, DRV_BOOLS_CHAR);	comval->parse = IsDlgButtonChecked(hdlg, DRV_PARSE);	comval->cancel_as_freestmt = IsDlgButtonChecked(hdlg, DRV_CANCELASFREESTMT);	comval->debug = IsDlgButtonChecked(hdlg, DRV_DEBUG);	comval->fetch_max = GetDlgItemInt(hdlg, DRV_CACHE_SIZE, NULL, FALSE);	comval->max_varchar_size = GetDlgItemInt(hdlg, DRV_VARCHAR_SIZE, NULL, FALSE);	comval->max_longvarchar_size = GetDlgItemInt(hdlg, DRV_LONGVARCHAR_SIZE, NULL, TRUE);		/* allows for																								 * SQL_NO_TOTAL */	GetDlgItemText(hdlg, DRV_EXTRASYSTABLEPREFIXES, comval->extra_systable_prefixes, sizeof(comval->extra_systable_prefixes));	/* Driver Connection Settings */	if (!ci)		GetDlgItemText(hdlg, DRV_CONNSETTINGS, comval->conn_settings, sizeof(comval->conn_settings));	if (updateDriver)	{		if (writeDriverCommoninfo(ODBCINST_INI, updateDriver, comval) < 0)			MessageBox(hdlg, "impossible to update the values, sorry", "Update Error", MB_ICONEXCLAMATION | MB_OK);;	}	/* fall through */	return 0;}LRESULT		CALLBACKdriver_optionsProc(HWND hdlg,				   UINT wMsg,				   WPARAM wParam,				   LPARAM lParam){	ConnInfo   *ci;	char	strbuf[128];	switch (wMsg)	{		case WM_INITDIALOG:			SetWindowLongPtr(hdlg, DWLP_USER, lParam);		/* save for OK etc */			ci = (ConnInfo *) lParam;			LoadString(s_hModule, IDS_ADVANCE_OPTION_DEF, strbuf, sizeof(strbuf)); 			SetWindowText(hdlg, strbuf);			LoadString(s_hModule, IDS_ADVANCE_SAVE, strbuf, sizeof(strbuf)); 			SetWindowText(GetDlgItem(hdlg, IDOK), strbuf);			ShowWindow(GetDlgItem(hdlg, IDAPPLY), SW_HIDE);			driver_optionsDraw(hdlg, ci, 0, TRUE);			break;		case WM_COMMAND:			switch (GET_WM_COMMAND_ID(wParam, lParam))			{				case IDOK:					ci = (ConnInfo *) GetWindowLongPtr(hdlg, DWLP_USER);					driver_options_update(hdlg, NULL,						ci ? ci->drivername : NULL);				case IDCANCEL:					EndDialog(hdlg, GET_WM_COMMAND_ID(wParam, lParam) == IDOK);					return TRUE;				case IDDEFAULTS:					driver_optionsDraw(hdlg, NULL, 2, TRUE);					break;			}	}	return FALSE;}#ifdef _HANDLE_ENLIST_IN_DTC_staticHMODULE DtcProc(const char *procname, FARPROC *proc){	HMODULE	hmodule;	*proc = NULL;	if (hmodule = LoadLibrary(GetXaLibPath()), NULL != hmodule)	{mylog("GetProcAddres for %s\n", procname);		*proc = GetProcAddress(hmodule, procname);	}	return hmodule;}#endif /* _HANDLE_ENLIST_IN_DTC_ */LRESULT			CALLBACKglobal_optionsProc(HWND hdlg,				   UINT wMsg,				   WPARAM wParam,				   LPARAM lParam){#ifdef _HANDLE_ENLIST_IN_DTC_	HMODULE	hmodule;	FARPROC	proc;#endif /* _HANDLE_ENLIST_IN_DTC_ */	switch (wMsg)	{		case WM_INITDIALOG:			CheckDlgButton(hdlg, DRV_COMMLOG, globals.commlog);#ifndef Q_LOG			EnableWindow(GetDlgItem(hdlg, DRV_COMMLOG), FALSE);#endif /* Q_LOG */			CheckDlgButton(hdlg, DRV_DEBUG, globals.debug);#ifndef MY_LOG			EnableWindow(GetDlgItem(hdlg, DRV_DEBUG), FALSE);#endif /* MY_LOG */#ifdef _HANDLE_ENLIST_IN_DTC_			hmodule = DtcProc("GetMsdtclog", &proc);			if (proc)			{				INT_PTR res = (*proc)();				CheckDlgButton(hdlg, DRV_DTCLOG, 0 != res);			}			else				EnableWindow(GetDlgItem(hdlg, DRV_DTCLOG), FALSE);			if (hmodule)				FreeLibrary(hmodule);#else			ShowWindow(GetDlgItem(hdlg, DRV_DTCLOG), SW_HIDE);#endif /* _HANDLE_ENLIST_IN_DTC_ */			break;		case WM_COMMAND:			switch (GET_WM_COMMAND_ID(wParam, lParam))			{				case IDOK:					globals.commlog = IsDlgButtonChecked(hdlg, DRV_COMMLOG);					globals.debug = IsDlgButtonChecked(hdlg, DRV_DEBUG);					if (writeDriverCommoninfo(ODBCINST_INI, NULL, &globals) < 0)						MessageBox(hdlg, "Sorry, impossible to update the values\nWrite permission seems to be needed", "Update Error", MB_ICONEXCLAMATION | MB_OK);#ifdef _HANDLE_ENLIST_IN_DTC_					hmodule = DtcProc("SetMsdtclog", &proc);					if (proc)						(*proc)(IsDlgButtonChecked(hdlg, DRV_DTCLOG));					if (hmodule)						FreeLibrary(hmodule);#endif /* _HANDLE_ENLIST_IN_DTC_ */

⌨️ 快捷键说明

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