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

📄 cdialog.cpp

📁 用测试OLE DB提供者的一个程序。能够测试出OEL DB提供者到底实现了哪些接口?很灵的。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
								hWnd
								);
					return 0;
				}

				case IDMENU_BROWSE_FILE:
				{
					CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
					CHAR* pszTitle = NULL;
					WCHAR* pwszBuffer = NULL;
					
					switch(pThis->m_ePropSource)
					{
						case DBPROP_AUTH_INTEGRATED:
						{
							pszTitle = "DBPROP_AUTH_INTEGRATED";
							pwszBuffer = pThis->m_wszIntegrated;
							break;
						}

						default:
							ASSERT(!"Unhandled Source!");
							break;
					}

					//Display Common Dialog to obtain DataSource...
					//This is for providers that take a filename/path for this property
					if(SUCCEEDED(BrowseOpenFileName(pThis->m_hInst, hWnd, pszTitle, pwszBuffer, MAX_NAME_LEN)))
					{
						//Just update value
						CHAR szBuffer[MAX_NAME_LEN];
						ConvertToMBCS(pwszBuffer, szBuffer, MAX_NAME_LEN);
						ReplaceEditBoxSelection(pThis->m_hWndSource, szBuffer);
					}
					return 0;
				}

				case IDMENU_BROWSE_ENUM:
				{
					CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
					DialogBoxParam(pThis->m_hInst, MAKEINTRESOURCE(IDD_BROWSE_ENUM), hWnd, BrowseEnumeratorProc, (LPARAM)pThis);
					return 0;
				}
			}
		
			return FALSE;
		}

		case WM_NOTIFY:
		{	
			switch (((NMHDR*)lParam)->code) 
    		{
				case PSN_SETACTIVE: //Init
				{
					CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
					pThis->RefreshSecurity();
					return 0;
				}

				case PSN_KILLACTIVE://Switch
				{
					CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
					if(!pThis->UpdateSecurity())
					{
						SetWindowLong(hWnd, DWL_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
						return TRUE;
					}
					return 0;
				}

				case PSN_APPLY:		//OK
					return 0;

				case PSN_RESET:		//CANCEL
					return 0;
			}
    	}
	}

	return FALSE;   
}


////////////////////////////////////////////////////////////////
// CConnectDlg::OptionsProc
//
/////////////////////////////////////////////////////////////////
BOOL CALLBACK CConnectDlg::OptionsProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static PROPSHEETPAGE* ps = NULL;

	switch (message)
	{
		case WM_INITDIALOG:
		{	
			EXC_BEGIN
			
			// save off the PROPSHEETPAGE information
			ps = (PROPSHEETPAGE*)lParam;
			CConnectDlg* pThis = (CConnectDlg*)SetThis(hWnd, ps->lParam);
			pThis->InitOptions(hWnd);

			EXC_END_(hWnd, EndDialog(hWnd, FALSE));
			return TRUE;
		}

		case WM_COMMAND:
		{
			//Filter out any Control Notification codes
			if(GET_WM_COMMAND_CMD(wParam, lParam) > 1)
			{
				return UNHANDLED_MSG;
			}

			//Regular command messages
			switch(GET_WM_COMMAND_ID(wParam, lParam))
			{
				case IDB_REMOTE_SERVER:
					EnableWindow(GetDlgItem(hWnd, IDE_REMOTESERVER), IsDlgButtonChecked(hWnd, IDB_REMOTE_SERVER));
					return 0;
			}
		
			return FALSE;
		}

		case WM_NOTIFY:
    		switch (((NMHDR*)lParam)->code) 
    		{
				case PSN_SETACTIVE:
				{	
					CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
					pThis->RefreshOptions();
					return 0;
				}

				case PSN_KILLACTIVE:
				{	
					// initialize the controls
					CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
					if(!pThis->UpdateOptions())
					{
						SetWindowLong(hWnd, DWL_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
						return TRUE;
					}
				  	return 0;
				}

				case PSN_APPLY:
				  	return 0;

				case PSN_RESET:
				  	return 0;
    	}
	}

	return FALSE;   
}


////////////////////////////////////////////////////////////////
// CConnectDlg::TraceProc
//
/////////////////////////////////////////////////////////////////
BOOL CALLBACK CConnectDlg::TraceProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static PROPSHEETPAGE* ps = NULL;

	switch (message)
	{
		case WM_INITDIALOG:
		{	
			EXC_BEGIN 

			// save off the PROPSHEETPAGE information
			ps = (PROPSHEETPAGE*)lParam;
			CConnectDlg* pThis = (CConnectDlg*)SetThis(hWnd, ps->lParam);
			pThis->InitTrace(hWnd);

			EXC_END_(hWnd, EndDialog(hWnd, FALSE));
			return TRUE;
		}

		case WM_COMMAND:
		{
			//Filter out any Control Notification codes
			if(GET_WM_COMMAND_CMD(wParam, lParam) > 1)
			{
				return UNHANDLED_MSG;
			}

			//Regular command messages
			switch(GET_WM_COMMAND_ID(wParam, lParam))
			{
				case IDB_TEST:
				{
					CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
					
					//Obtain Provider from DropDown
					pThis->GetProviderName();
					pThis->CreateProviderInstance();
					return 0;
				}
			}
		
			return FALSE;
		}

		case WM_NOTIFY:
    		switch (((NMHDR*)lParam)->code) 
    		{
				case PSN_SETACTIVE:
				{	
					CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
					pThis->RefreshTrace();
					return 0;
				}

				case PSN_KILLACTIVE:
				{	
					//Must set the Window handle back
					CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
					if(!pThis->UpdateTrace())
					{
						SetWindowLong(hWnd, DWL_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
						return TRUE;
					}
				  	return 0;
				}

				case PSN_APPLY:
				  	return 0;

				case PSN_RESET:
				{	
					//Must set the Window handle back
					CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
					pThis->UpdateTrace();			
					return 0;
				}
    	}
	}

	return FALSE;   
}


////////////////////////////////////////////////////////////////
// CConnectDlg::BrowseEnumeratorProc
//
/////////////////////////////////////////////////////////////////
BOOL CALLBACK CConnectDlg::BrowseEnumeratorProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_INITDIALOG:
		{	
			EXC_BEGIN

			//save off the this pointer
			CConnectDlg* pThis = (CConnectDlg*)SetThis(hWnd, lParam);
			
			HWND hWndProv = GetDlgItem(hWnd, IDC_PROVIDER);
			HWND hWndListView = GetDlgItem(hWnd, IDL_LISTVIEW);
			LONG iIndex = 0;
			CEnum* pCEnum =  pThis->m_pCEnum;

			//We may need to connect to the RootEnumerator, if not done already
			if(!pCEnum->IsConnectedToRootEnum())
				pCEnum->ConnectToRootEnum();
			
			//We just need to fill in a combo box with the same values
			//from the Root Enumerator, but only displaying Enumerators...
			for(ULONG i=0; i<pCEnum->m_cEnumInfo; i++)
			{
				if(pCEnum->m_rgEnumInfo[i].wType == DBSOURCETYPE_ENUMERATOR)
				{
					//Add the name to the list
					//Since we have the CBS_SORT turned on, the order in the Combo Box does
					//not match our array, so we pass the array index (lParam) as the item data
					iIndex = wSendMessage(hWndProv, CB_ADDSTRING, 0, pCEnum->m_rgEnumInfo[i].wszName);
					SendMessage(hWndProv, CB_SETITEMDATA, (WPARAM)iIndex, (LPARAM)i);
				}
			}
		
			//Try to do a smart guess on which Enumerator.
			//Since the spec doesn't have a actual way of prgrammatically 
			//assoiciating providers with their enumerators, we will try and search
			//the enumerator name for the providers name...
			//So if using MSDASQL, it will find MSDASQL Enumerator
			iIndex = wSendMessage(hWndProv, CB_FINDSTRING, -1, pThis->m_EnumInfo.wszName);
			SendMessage(hWndProv, CB_SETCURSEL, iIndex!=CB_ERR ? iIndex : 0, 0);

			//Setup ListView
			SendMessage(hWndListView, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_TWOCLICKACTIVATE | LVS_EX_SUBITEMIMAGES, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_TWOCLICKACTIVATE | LVS_EX_SUBITEMIMAGES);
			LV_InsertColumn(hWndListView, 0, "SOURCES_NAME");
			HIMAGELIST hImageList = ImageList_Create(16, 16, ILC_MASK, 1, 0 );
			
			//IDI_ROW_NORMAL
			HICON hIcon = LoadIcon(pThis->m_hInst, MAKEINTRESOURCE(IDI_ROW_NORMAL));
			ImageList_AddIcon(hImageList, hIcon);
			//Set image list to the ListView
			ListView_SetImageList(hWndListView, hImageList, LVSIL_SMALL);

			//AutoSize Header
			SendMessage(hWndListView, LVM_SETCOLUMNWIDTH, 0, (LPARAM)LVSCW_AUTOSIZE_USEHEADER);

			//Send a selection change to the ComboBox so it updates everything
			SendMessage(hWnd, WM_COMMAND, GET_WM_COMMAND_MPS(IDC_PROVIDER, hWnd, LBN_SELCHANGE));
			CenterDialog(hWnd);

			EXC_END_(hWnd, EndDialog(hWnd, FALSE));
			return TRUE;
		}

		case WM_COMMAND:
		{
			//Filter out any Control Notification codes
			if(GET_WM_COMMAND_CMD(wParam, lParam) > 1)
			{
				return UNHANDLED_MSG;
			}

			//LBN_SELCHANGE ListBox Selection change
			switch(GET_WM_COMMAND_CMD(wParam, lParam))
			{
				//Selection change in a list box occurred
				case LBN_SELCHANGE:
				{	
					//Get the "this" pointer
					CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
					CEnum* pCEnum =  pThis->m_pCEnum;

					HWND hWndProv = GetDlgItem(hWnd, IDC_PROVIDER);
					HWND hWndListView = GetDlgItem(hWnd, IDL_LISTVIEW);
					
					//The Selection has changed...
					SendMessage(hWndListView, LVM_DELETEALLITEMS, 0, 0);
					EnableWindow(hWndListView, FALSE);
					
					//Update the Window Title - with the Description
					LONG iIndex = SendMessage(hWndProv, CB_GETCURSEL, 0, 0);
					LONG lParam = SendMessage(hWndProv, CB_GETITEMDATA, iIndex, 0);

					if(lParam!=CB_ERR && lParam <(LONG)pCEnum->m_cEnumInfo)
					{
						wSendMessage(hWnd, WM_SETTEXT, 0, pCEnum->m_rgEnumInfo[lParam].wszDescription);
					}
					return 0;
				}
			}
			
			switch (GET_WM_COMMAND_ID(wParam, lParam))
			{
				case IDB_CONNECT:
				{
					//Get the "this" pointer
					CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);

					//Fill in Enum Dialog
					pThis->DisplayBrowseEnumInfo(hWnd);
					return 0;
				}
								
				case IDOK:
				{
					//Get the "this" pointer
					CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
					CHAR szBuffer[MAX_NAME_LEN];
					szBuffer[0] = EOL;

					//Need to find the Selected Item...
					HWND hWndListView = GetDlgItem(hWnd, IDL_LISTVIEW);
					LONG iSelRow = SendMessage(hWndListView, LVM_GETNEXTITEM, (WPARAM)-1, (LPARAM)LVNI_SELECTED);
					
					//Need to obtain Enum selection from the ListView
					LV_GetItemText(hWndListView, iSelRow, 0, szBuffer, MAX_NAME_LEN);

					//Now need to copy value to the EditBox
					ReplaceEditBoxSelection(pThis->m_hWndSource, szBuffer);
					EndDialog(hWnd, TRUE);
					return 0;
				}

				case IDCANCEL:
				{
					EndDialog(hWnd, FALSE);
					return 0;
				}
			}
			break;
		}//WM_COMMAND

	
		case WM_NOTIFY:
		{
			LV_DISPINFO* pDispInfo = (LV_DISPINFO*)lParam;
			NM_LISTVIEW* pListView = (NM_LISTVIEW*)lParam;
			
			switch(pDispInfo->hdr.code)
			{
				//Since we have "TwoClickActive" on this will get sent
				//Whenever a row is clicked on twice!
				//This functionality used to be done with NM_DBCLK
				case LVN_ITEMACTIVATE:
				{
					//Send an OK message
					SendMessage(hWnd, WM_COMMAND, GET_WM_COMMAND_MPS(IDOK, hWnd, 0));
					return 0;
				}
			}
			break;
		}//WM_NOTIFY
	}

	return FALSE;   
}



////////////////////////////////////////////////////////////////
// CCon

⌨️ 快捷键说明

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