📄 cdialog.cpp
字号:
CB_GetSelectedText(hWndConfig, pThis->m_szConfigName, MAX_NAME_LEN);
//Now we need to update the FullConnect for this Config
pThis->LoadDefaults();
pThis->RefreshProvider();
return 0;
}
case IDC_PROVIDER:
{
//Obtain Provider From Drop Down
CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
pThis->GetProviderName();
//Reset this connection
SAFE_RELEASE(pThis->m_pIUnknown);
return 0;
}
}
break;
}
return FALSE;
}
//Regular command messages
switch(GET_WM_COMMAND_ID(wParam, lParam))
{
case IDB_DEFAULTS:
{
CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
pThis->ResetDefaults();
pThis->RefreshOptions();
return 0;
}
case IDB_CONFIG_SAVE:
{
CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
HWND hWndConfig = GetDlgItem(hWnd, IDC_CONFIG);
//Obtain the Selected Combo Text
LONG iSel = CB_GetSelectedText(hWndConfig, pThis->m_szConfigName, MAX_NAME_LEN);
iSel = CB_SelectText(hWndConfig, pThis->m_szConfigName, TRUE);
//Now update registry
pThis->UpdateProvider();
pThis->SaveDefaults();
//Update the Saved Configurations (now that successfuly connected)
pThis->AddRecentConfig();
return 0;
}
case IDB_CONFIG_REMOVE:
{
CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
HWND hWndConfig = GetDlgItem(hWnd, IDC_CONFIG);
//Obtain the Selected Combo Text
LONG iSel = CB_GetSelectedText(hWndConfig, pThis->m_szConfigName, MAX_NAME_LEN);
//Remove this item from the ComboBox
SendMessage(hWndConfig, CB_DELETESTRING, iSel, 0);
//Formulate the key
CHAR szKeyName[MAX_NAME_LEN];
sprintf(szKeyName, "%s\\%s", szCONFIG_KEY, pThis->m_szConfigName);
//Now Remove this Item from the registry
DelRegEntry(HKEY_ROWSETVIEWER, szKeyName);
//We need to make sure this is not the default Config
szKeyName[0] = EOL;
GetRegEntry(HKEY_ROWSETVIEWER, szCONFIG_KEY, "DefaultConfig", szKeyName, MAX_NAME_LEN);
if(strcmp(szKeyName, pThis->m_szConfigName)==0)
SetRegEntry(HKEY_ROWSETVIEWER, szCONFIG_KEY, "DefaultConfig", "(Default)");
//And Remove it from our Recent Config List
pThis->RemoveRecentConfig(pThis->m_szConfigName);
pThis->m_szConfigName[0] = EOL;
return 0;
}
case IDB_ENUM_REFRESH:
{
//Get the "this" pointer
CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
//Refresh Root Rnum (Reconnect = TRUE)
pThis->RefreshEnum(TRUE);
return 0;
}
case IDB_BROWSE_LOCATION:
{
CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
pThis->m_ePropSource = DBPROP_INIT_LOCATION;
pThis->m_hWndSource = GetDlgItem(pThis->m_hWndProvider, IDE_LOCATION);
RECT rect;
GetWindowRect(GetDlgItem(hWnd, IDB_BROWSE_LOCATION), &rect);
//Display the Context Menu
DisplayContextMenu( pThis->m_hInst,
hWnd,
IDMENU_BROWSE_OPTION,
rect.left,
rect.top,
hWnd
);
return 0;
}
case IDB_BROWSE_DATASOURCE:
{
CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
pThis->m_ePropSource = DBPROP_INIT_DATASOURCE;
pThis->m_hWndSource = GetDlgItem(pThis->m_hWndProvider, IDE_DATASOURCE);
RECT rect;
GetWindowRect(GetDlgItem(hWnd, IDB_BROWSE_DATASOURCE), &rect);
//Display the Context Menu
DisplayContextMenu( pThis->m_hInst,
hWnd,
IDMENU_BROWSE_OPTION,
rect.left,
rect.top,
hWnd
);
return 0;
}
case IDMENU_BROWSE_FILE:
{
CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
CHAR* pszTitle = NULL;
WCHAR* pwszBuffer = NULL;
switch(pThis->m_ePropSource)
{
case DBPROP_INIT_DATASOURCE:
{
pszTitle = "DBPROP_INIT_DATASOURCE";
pwszBuffer = pThis->m_wszDataSource;
break;
}
case DBPROP_INIT_LOCATION:
{
pszTitle = "DBPROP_INIT_LOCATION";
pwszBuffer = pThis->m_wszLocation;
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:
{
CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
pThis->m_hWndProvider = hWnd;
pThis->RefreshProvider();
return 0;
}
case PSN_KILLACTIVE://Switch
{
CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
if(!pThis->UpdateProvider())
{
SetWindowLong(hWnd, DWL_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
return TRUE;
}
return 0;
}
case PSN_APPLY:
{
Busy();
// Make a connection using the supplied values
CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
pThis->GetProviderName();
if(FAILED(pThis->FullConnect()))
{
SetWindowLong(hWnd, DWL_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
Busy(OFF);
return TRUE;
}
Busy(OFF);
return 0;
}
case PSN_RESET: //CANCEL
return 0;
}
}
}
return FALSE;
}
////////////////////////////////////////////////////////////////
// CConnectDlg::PropertiesProc
//
/////////////////////////////////////////////////////////////////
BOOL CALLBACK CConnectDlg::PropertiesProc(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->InitProperties(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 0;
}
//Regular command messages
switch(GET_WM_COMMAND_ID(wParam, lParam))
{
case IDB_MOREPROPERTIES:
{
CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
pThis->GetAdvProperties();
pThis->RefreshProperties();
return 0;
}
case IDB_BROWSE_PROVSTRING:
{
CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
pThis->m_ePropSource = DBPROP_INIT_PROVIDERSTRING;
pThis->m_hWndSource = GetDlgItem(pThis->m_hWndProperties, IDE_PROVSTRING);
RECT rect;
GetWindowRect(GetDlgItem(hWnd, IDB_BROWSE_PROVSTRING), &rect);
//Display the Context Menu
DisplayContextMenu( pThis->m_hInst,
hWnd,
IDMENU_BROWSE_OPTION,
rect.left,
rect.top,
hWnd
);
return 0;
}
case IDMENU_BROWSE_FILE:
{
CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
CHAR* pszTitle = NULL;
WCHAR* pwszBuffer = NULL;
switch(pThis->m_ePropSource)
{
case DBPROP_INIT_PROVIDERSTRING:
{
pszTitle = "DBPROP_INIT_PROVIDERSTRING";
pwszBuffer = pThis->m_wszProvString;
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->RefreshProperties();
return 0;
}
case PSN_KILLACTIVE://Switch
{
CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
if(!pThis->UpdateProperties())
{
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::SecurityProc
//
/////////////////////////////////////////////////////////////////
BOOL CALLBACK CConnectDlg::SecurityProc(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->InitSecurity(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_BROWSE_INTEGRATED:
{
CConnectDlg* pThis = (CConnectDlg*)GetThis(hWnd);
pThis->m_ePropSource = DBPROP_AUTH_INTEGRATED;
pThis->m_hWndSource = GetDlgItem(pThis->m_hWndSecurity, IDE_INTEGRATED);
RECT rect;
GetWindowRect(GetDlgItem(hWnd, IDB_BROWSE_INTEGRATED), &rect);
//Display the Context Menu
DisplayContextMenu( pThis->m_hInst,
hWnd,
IDMENU_BROWSE_OPTION,
rect.left,
rect.top,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -