📄 main.cpp
字号:
{
//This window has already been removed, From the WM_DESTROY...
m_hWnd = NULL;
m_hWndListView = NULL;
m_hWndEditBox = NULL;
m_hWndScrollBar = NULL;
m_pCListBox->m_hWnd = NULL;
SAFE_DELETE(m_pCRowset);
SAFE_DELETE(m_pCPropDlg);
SAFE_DELETE(m_pCSchemaDlg);
SAFE_DELETE(m_pCError);
//This must happen last, since all object will
//use the list box when loggin releases...
SAFE_DELETE(m_pCListBox);
//Properties
FreeProperties(&m_cPropSets, &m_rgPropSets);
DeleteObject(m_hBitmapReadOnly);
}
////////////////////////////////////////////////////////////////
// CMDIChild::GetOptionsObj
//
/////////////////////////////////////////////////////////////////
COptionsDlg* CMDIChild::GetOptionsObj()
{
ASSERT(m_pCMainWindow);
ASSERT(m_pCMainWindow->m_pCOptionsDlg);
return m_pCMainWindow->m_pCOptionsDlg;
}
////////////////////////////////////////////////////////////////
// CMDIChild::GetConnectObj
//
/////////////////////////////////////////////////////////////////
CConnectDlg* CMDIChild::GetConnectObj()
{
ASSERT(m_pCMainWindow);
ASSERT(m_pCMainWindow->m_pCConnectDlg);
return m_pCMainWindow->m_pCConnectDlg;
}
////////////////////////////////////////////////////////////////
// CMDIChild::pCSchemaDlg
//
/////////////////////////////////////////////////////////////////
CSchemaDlg* const CMDIChild::pCSchemaDlg()
{
if(!m_pCSchemaDlg)
m_pCSchemaDlg = new CSchemaDlg(m_pCMainWindow->m_hWnd, m_hInst, this);
return m_pCSchemaDlg;
}
////////////////////////////////////////////////////////////////
// CMDIChild::Display
//
/////////////////////////////////////////////////////////////////
ULONG CMDIChild::Display()
{
//Need to first obtain Window TitleBar...
CDataSource* pCDataSource = m_pCRowset->m_pCDataSource;
//Create MDI Child Window, (passing the "this" pointer)
MDICREATESTRUCT mcs;
mcs.szClass = OLEDBMDICLASS;
mcs.szTitle = NULL;
mcs.hOwner = m_hInst;
mcs.style = 0;
mcs.x = CW_USEDEFAULT;
mcs.cx = CW_USEDEFAULT;
mcs.y = CW_USEDEFAULT;
mcs.cy = 450;
mcs.lParam = (LPARAM)this;
m_hWnd = (HWND)SendMessage(m_pCMainWindow->m_hWndMDIClient, WM_MDICREATE, 0, (LPARAM)&mcs);
// check if it was created, if it wasn't free up resource and flag warning
if(!m_hWnd)
{
wMessageBox(NULL, MB_OK|MB_ICONERROR|MB_SYSTEMMODAL, wsz_ERROR, L"Unable to create a MDIChild!");
goto CLEANUP;
}
//Increment total ChildWindow count
m_ulWindow = ++CMainWindow::m_ulChildWindows;
//Update Window Title
UpdateWndTitle();
CLEANUP:
return m_hWnd ? TRUE : FALSE;
}
/////////////////////////////////////////////////////////////////
// CMDIChild::UpdateWndTitle
//
/////////////////////////////////////////////////////////////////
HRESULT CMDIChild::UpdateWndTitle()
{
//Create Title for ChildWindow
CHAR* pszName = NULL;
ASSERT(m_pCRowset);
CDataSource* pCDataSource = m_pCRowset->m_pCDataSource;
//Format text and output to window
EXC_TEST(SendMessageFmt(m_hWnd, WM_SETTEXT, 0, "%S - %d %S %S %S",
pCDataSource->GetEnumInfo()->wszName[0] ? pCDataSource->GetEnumInfo()->wszName : pCDataSource->m_pwszProviderName ? pCDataSource->m_pwszProviderName : L"",
m_ulWindow,
pCDataSource->m_pwszDataSource!=NULL ? pCDataSource->m_pwszDataSource : pCDataSource->m_EnumInfo.wszName,
pCDataSource->m_pwszDBMS!=NULL ? pCDataSource->m_pwszDBMS : L"",
pCDataSource->m_pwszDBMSVer!=NULL ? pCDataSource->m_pwszDBMSVer : L""));
return S_OK;
}
////////////////////////////////////////////////////////////////
// CMDIChild::CreateNewSessionWindow
//
/////////////////////////////////////////////////////////////////
HRESULT CMDIChild::CreateNewSessionWindow()
{
//Bascially we want to diplay a new window, but use the existing connection,
//So we will obtain all interfaces from the existing IDBInitialize
HRESULT hr = E_FAIL;
//Create a MDIChild and DataSource
CMDIChild* pCMDIChild = new CMDIChild(NULL, m_hInst, m_pCMainWindow);
//Connect using the Same DataSource...
TESTC(hr = pCMDIChild->m_pCRowset->CreateConnection(m_pCRowset));
//Display
pCMDIChild->Display();
CLEANUP:
if(FAILED(hr))
SAFE_DELETE(pCMDIChild);
return hr;
}
////////////////////////////////////////////////////////////////
// CMDIChild::CreateNewCommandWindow
//
/////////////////////////////////////////////////////////////////
HRESULT CMDIChild::CreateNewCommandWindow()
{
//Bascially we want to diplay a new window, but use the existing connection,
//So we will obtain all interfaces from the existing IDBInitialize
HRESULT hr = E_FAIL;
//Create a MDIChild and DataSource
CMDIChild* pCMDIChild = new CMDIChild(NULL, m_hInst, m_pCMainWindow);
//Connect using the Same DataSource, (FALSE == Same Session as well)
TESTC(hr = pCMDIChild->m_pCRowset->CreateConnection(m_pCRowset, FALSE));
//Display
pCMDIChild->Display();
CLEANUP:
if(FAILED(hr))
SAFE_DELETE(pCMDIChild);
return hr;
}
////////////////////////////////////////////////////////////////
// CMDIChild::InitControls
//
/////////////////////////////////////////////////////////////////
BOOL CMDIChild::InitControls(HWND hWnd)
{
m_hWnd = hWnd;
HRESULT hr = S_OK;
// create child windows
// 1. ListView for rowset data
// 2. EditBox for entering SQL Text
// 3. ListBox for notifcations
// 4. ScrollBar for scrolling through the rowset
//CreateListView
m_hWndListView = CreateWindowEx(
WS_EX_CLIENTEDGE, // ex style
WC_LISTVIEW, // class name - defined in commctrl.h
NULL, // window text
WS_TABSTOP | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL | /*LVS_SINGLESEL |*/ LVS_AUTOARRANGE | LVS_REPORT | LVS_EDITLABELS | LVS_SHOWSELALWAYS,
0, // x position
0, // y position
100, // width
100, // height
m_hWnd, // parent
(HMENU)IDC_LISTVIEW, // ID
m_hInst, // instance
this); // no extra data
//Obtain the Approxiamate height to diaply MAX_LISTVIEWROWS items
DWORD dwValue = GetSystemMetrics(SM_CYHSCROLL) + SendMessage(m_hWndListView, LVM_APPROXIMATEVIEWRECT, MAX_LISTVIEWROWS, MAKELPARAM(100, 275));
MoveWindow(m_hWndListView, 0, 0, 100, HIWORD(dwValue), TRUE);
//SubClass the ListView
SetThis(m_hWndListView, (LPARAM)this);
m_pSavedListViewProc = (WNDPROC)GetWindowLong(m_hWndListView, GWL_WNDPROC);
SetWindowLong(m_hWndListView, GWL_WNDPROC, (LONG)SubClassListViewProc);
//CreateEditBox
m_hWndEditBox = CreateWindowEx(
WS_EX_CLIENTEDGE, // ex style
m_pCMainWindow->m_hLibRichEdit ? "RICHEDIT" : "EDIT", // class name - defined in commctrl.h
NULL, // window text
WS_TABSTOP | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_HSCROLL | WS_VSCROLL | ES_LEFT | ES_AUTOVSCROLL | /*ES_AUTOHSCROLL |*/ ES_MULTILINE | ES_WANTRETURN | ES_NOHIDESEL,
0, // x position
0, // y position
65, // width
65, // height
m_hWnd, // parent
(HMENU)IDC_EDITBOX, // ID
m_hInst, // instance
this); // no extra data
//Set Focus to SQL Edit Box
SendMessage(m_hWndEditBox, EM_FMTLINES, FALSE, 0);
SendMessage(m_hWndEditBox, EM_SETTEXTMODE | TM_MULTILEVELUNDO, TM_PLAINTEXT, 0);
SetFocus(m_hWndEditBox);
//SubClass the EditBox
SetThis(m_hWndEditBox, (LPARAM)this);
m_pSavedEditBoxProc = (WNDPROC)GetWindowLong(m_hWndEditBox, GWL_WNDPROC);
SetWindowLong(m_hWndEditBox, GWL_WNDPROC, (LONG)SubClassEditBoxProc);
//CreateListBox
SetParent(m_pCListBox->m_hWnd, m_hWnd);
SetThis(m_pCListBox->m_hWnd, (LPARAM)this);
ShowWindow(m_pCListBox->m_hWnd, SW_SHOW);
//SubClass the ListBox
m_pSavedListBoxProc = (WNDPROC)GetWindowLong(m_pCListBox->m_hWnd, GWL_WNDPROC);
SetWindowLong(m_pCListBox->m_hWnd, GWL_WNDPROC, (LONG)SubClassListBoxProc);
//CreateScrollBar
m_hWndScrollBar = CreateWindowEx(
NULL, // ex style
"SCROLLBAR", // class name - defined in commctrl.h
NULL, // window text
WS_CHILD | WS_VISIBLE | SBS_VERT,
0, // x position
0, // y position
GetSystemMetrics(SM_CXVSCROLL), // width
dwValue, // height
m_hWnd, // parent
(HMENU)IDC_SCROLLBAR, // ID
m_hInst, // instance
this); // no extra data
//Clear ListView
ClearListView("No Rowset");
//Disable Windows
EnableWindow(m_hWndListView, FALSE);
EnableWindow(m_hWndScrollBar, FALSE);
//Get ListView font
HFONT hFont = (HFONT)SendMessage(m_hWndListView, WM_GETFONT, 0, 0);
SendMessage(m_hWndEditBox, WM_SETFONT, (WPARAM)hFont, 0);
SendMessage(m_pCListBox->m_hWnd, WM_SETFONT, (WPARAM)hFont, 0);
//Use Extended ListView Styles!
SendMessage(GetDlgItem(hWnd, IDC_LISTVIEW), 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);
//Create the Row ImageList
HIMAGELIST hRowImageList = ImageList_Create(16, 16, ILC_MASK, 8, 8 );
//IDI_ROW_NORMAL - normal row icon
HICON hIcon = LoadIcon(m_hInst, MAKEINTRESOURCE(IDI_ROW_NORMAL));
ImageList_AddIcon(hRowImageList, hIcon);
hIcon = LoadIcon(m_hInst, MAKEINTRESOURCE(IDI_READONLY));
ImageList_AddIcon(hRowImageList, hIcon);
hIcon = LoadIcon(m_hInst, MAKEINTRESOURCE(IDI_COL_INFO));
ImageList_AddIcon(hRowImageList, hIcon);
hIcon = LoadIcon(m_hInst, MAKEINTRESOURCE(IDI_COL_ERROR));
ImageList_AddIcon(hRowImageList, hIcon);
hIcon = LoadIcon(m_hInst, MAKEINTRESOURCE(IDI_NFP_BEFORE));
ImageList_AddIcon(hRowImageList, hIcon);
hIcon = LoadIcon(m_hInst, MAKEINTRESOURCE(IDI_NFP_AFTER));
ImageList_AddIcon(hRowImageList, hIcon);
hIcon = LoadIcon(m_hInst, MAKEINTRESOURCE(IDI_ROW_DELETE));
ImageList_AddIcon(hRowImageList, hIcon);
hIcon = LoadIcon(m_hInst, MAKEINTRESOURCE(IDI_ROW_CHANGE));
ImageList_AddIcon(hRowImageList, hIcon);
//Set image list to the ListView
ListView_SetImageList(m_hWndListView, hRowImageList, LVSIL_SMALL);
// ImageList_Destroy(hRowImageList);
//Initally setup up some rowset properties that are very useful functionality
//These are mainly to have the most common operations on the rowset and to
//be able to obtain blob columns...
CDataSource* pCDataSource = m_pCRowset->m_pCDataSource;
CCommand* pCCommand = m_pCRowset->m_pCCommand;
//Only set these "Default" properties, if requested by the user
if(GetOptionsObj()->m_dwRowsetOpts & ROWSET_SETDEFAULTPROPS)
{
DBPROPOPTIONS dwPropOptions = DBPROPOPTIONS_OPTIONAL;
//Kagera has a problem with OPTIONAL properties, still treating
//them as SETIFCHEAP and lets you know the NOTSET ones...
//Instead of always getting DB_S_ERRORSOCCURRED just special case until fixed
if(pCDataSource->m_pwszProviderName && wcscmp(pCDataSource->m_pwszProviderName, L"MSDASQL.DLL")==0)
dwPropOptions = DBPROPOPTIONS_REQUIRED;
//DBPROP_CANHOLDROWS is required by the OLEDB Spec - Level-0 Conformance
//Since it is also legal to set a ReadOnly property, just blindy set it...
if(IsSettableProperty(pCDataSource->m_pIUnknown, DBPROP_CANHOLDROWS, DBPROPSET_ROWSET) || pCDataSource->m_pISourcesRowset)
SetProperty(DBPROP_CANHOLDROWS, DBPROPSET_ROWSET, &m_cPropSets, &m_rgPropSets, DBTYPE_BOOL, VARIANT_TRUE, dwPropOptions);
//We want to provide Scrolling Capabilites to the user (if supported)
if(IsSettableProperty(pCDataSource->m_pIUnknown, DBPROP_CANSCROLLBACKWARDS, DBPROPSET_ROWSET))
SetProperty(DBPROP_CANSCROLLBACKWARDS, DBPROPSET_ROWSET, &m_cPropSets, &m_rgPropSets, DBTYPE_BOOL, VARIANT_TRUE, dwPropOptions);
if(IsSettableProperty(pCDataSource->m_pIUnknown, DBPROP_CANFETCHBACKWARDS, DBPROPSET_ROWSET))
SetProperty(DBPROP_CANFETCHBACKWARDS, DBPROPSET_ROWSET, &m_cPropSets, &m_rgPropSets, DBTYPE_BOOL, VARIANT_TRUE, dwPropOptions);
//Allow the user to change data (if supported)
if(IsSettableProperty(pCDataSource->m_pIUnknown, DBPROP_IRowsetChange, DBPROPSET_ROWSET))
SetProperty(DBPROP_IRowsetChange, DBPROPSET_ROWSET, &m_cPropSets, &m_rgPropSets, DBTYPE_BOOL, VARIANT_TRUE, dwPropOptions);
if(IsSettableProperty(pCDataSource->m_pIUnknown, DBPROP_UPDATABILITY, DBPROPSET_ROWSET))
SetProperty(DBPROP_UPDATABILITY, DBPROPSET_ROWSET, &m_cPropSets, &m_rgPropSets, DBTYPE_I4, DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE, dwPropOptions);
//Some providers might need IRowsetLocate to position on BLOBs (MSDASQL)
if(IsSettableProperty(pCDataSource->m_pIUnknown, DBPROP_IRowsetLocate, DBPROPSET_ROWSET))
SetProperty(DBPROP_IRowsetLocate, DBPROPSET_ROWSET, &m_cPropSets, &m_rgPropSets, DBTYPE_BOOL, VARIANT_TRUE, dwPropOptions);
//Notifications are very useful debugging info (if supported)
if(IsSettableProperty(pCDataSource->m_pIUnknown, DBPROP_IConnectionPointContainer, DBPROPSET_ROWSET))
SetProperty(DBPROP_IConnectionPointContainer, DBPROPSET_ROWSET, &m_cPropSets, &m_rgPropSets, DBTYPE_BOOL, VARIANT_FALSE, dwPropOptions);
//WJH822
SetProperty(DBPROP_IConnectionPointContainer, DBPROPSET_ROWSET, &m_cPropSets, &m_rgPropSets, DBTYPE_BOOL, VARIANT_FALSE, dwPropOptions);
//DBPROP_ISequentialStream
if(GetOptionsObj()->m_dwRowsetOpts & ROWSET_BLOB_ISEQSTREAM &&
IsSettableProperty(pCDataSource->m_pIUnknown, DBPROP_ISequentialStream, DBPROPSET_ROWSET))
SetProperty(DBPROP_ISequentialStream, DBPROPSET_ROWSET, &m_cPropSets, &m_rgPropSets, DBTYPE_BOOL, VARIANT_TRUE, dwPropOptions);
//DBPROP_ILockBytes
if(GetOptionsObj()->m_dwRowsetOpts & ROWSET_BLOB_ILOCKBYTES &&
IsSettableProperty(pCDataSource->m_pIUnknown, DBPROP_ILockBytes, DBPROPSET_ROWSET))
SetProperty(DBPROP_ILockBytes, DBPROPSET_ROWSET, &m_cPropSets, &m_rgPropSets, DBTYPE_BOOL, VARIANT_TRUE, dwPropOptions);
//DBPROP_IStorage
if(GetOptionsObj()->m_dwRowsetOpts & ROWSET_BLOB_ISTORAGE &&
IsSettableProperty(pCDataSource->m_pIUnknown, DBPROP_IStorage, DBPROPSET_ROWSET))
SetProperty(DBPROP_IStorage, DBPROPSET_ROWSET, &m_cPropSets, &m_rgPropSets, DBTYPE_BOOL, VARIANT_TRUE, dwPropOptions);
//DBPROP_IStream
if(GetOptionsObj()->m_dwRowsetOpts & ROWSET_BLOB_ISTREAM &&
IsSettableProperty(pCDataSource->m_pIUnknown, DBPROP_IStream, DBPROPSET_ROWSET))
SetProperty(DBPROP_IStream, DBPROPSET_ROWSET, &m_cPropSets, &m_rgPropSets, DBTYPE_BOOL, VARIANT_TRUE, dwPropOptions);
//Now also set these properties on our Command Object
if(pCCommand->m_pICommandProperties)
{
//SetProperties
m_pCListBox->OutputPreMethod("ICommandProperties::SetProperties(%d, 0x%08x)", m_cPropSets, m_rgPropSets);
XTEST_(hWnd, hr = pCCommand->m_pICommandProperties->SetProperties(m_cPropSets, m_rgPropSets),S_OK);
m_pCListBox->OutputPostMethod(hr, "ICommandProperties::SetProperties(%d, 0x%08x)", m_cPropSets, m_rgPropSets);
if(hr == DB_S_ERRORSOCCURRED || hr == DB_E_ERRORSOCCURRED)
DisplayPropErrors(hWnd, m_cPropSets, m_rgPropSets);
TESTC(hr);
}
}
CLEANUP:
return TRUE;
}
////////////////////////////////////////////////////////////////
// CMDIChild::RefreshControls
//
/////////////////////////////////////////////////////////////////
BOOL CMDIChild::RefreshControls()
{
CDataSource* pCDataSource = m_pCRowset->m_pCDataSource;
CSession* pCSession = m_pCRowset->m_pCSession;
CCommand* pCCommand = m_pCRowset->m_pCCommand;
HWND hWndToolbar = m_pCMainWindow->m_hWndToolbar;
//ToolBar Buttons
SendMessage(hWndToolbar, TB_ENABLEBUTTON, IDMENU_CONNECT, TRUE);
SendMessage(hWndToolbar, TB_ENABLEBUTTON, IDMENU_DISCONNECT, TRUE);
SendMessage(hWndToolbar, TB_ENABLEBUTTON, IDMENU_CREATESESSIONWINDOW, (BOOL)pCDataSource->m_pIDBCreateSession);
SendMessage(hWndToolbar, TB_ENABLEBUTTON, IDMENU_RUN, pCDataSource->m_pISourcesRowset || pCSession->m_pIOpenRowset || pCCommand->m_pICommand);
SendMessage(hWndToolbar, TB_ENABLEBUTTON, IDMENU_EXECUTE, (BOOL)pCCommand->m_pICommand);
SendMessage(hWndToolbar, TB_ENABLEBUTTON, IDMENU_RESTARTPOSITION, (BOOL)m_pCRowset->m_pIRowset);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -