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

📄 main.cpp

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

						//We may not be interested in this Message...
						if(!pThis->m_fWarnMaxEditBuffer)
							return 0;

						HWND hWndEditBox = (HWND)lParam; // handle of edit control  
						LONG dwSelection = 0;
						BOOL fNotifyWnd = (LOWORD(wParam) == IDC_LISTBOX);

						//Indicate the the user that the Edit Box Buffer
						//Has exceded the Maximum size
 						dwSelection = wMessageBox(hWnd, MB_TASKMODAL | MB_ICONHAND | MB_OKCANCEL | MB_DEFBUTTON1, 
							wsz_ERROR, L"The \"%s\" has exceeded the maximum buffer size.\n\n"
										L"Standard Edit Controls have a limited buffer size, RichEdit Edit Controls do not, please make sure RICHED32.DLL is installed on your system to prevent this message.\n\n"
										L"Press 'OK' to remove all old lines, Press 'Cancel' to ignore all new lines.", fNotifyWnd ? L"Notification Window" : L"Command Window");

						//Handle users request...
						if(dwSelection == IDOK)
						{
							//Remove all old Lines...
							SendMessage(hWndEditBox, WM_SETTEXT, 0, (LPARAM)"");
							pThis->m_fWarnMaxEditBuffer = TRUE;
						}
						else
						{
							//Ignore all new lines...
							//(just bascially ignore this message...)
							pThis->m_fWarnMaxEditBuffer = FALSE;
						}
					}
					return 0;
				};

				break;
			}

			//Get the "this" pointer
			CMainWindow* pThis = (CMainWindow*)GetThis(hWnd);
			HRESULT hr = S_OK;

			switch (GET_WM_COMMAND_ID(wParam, lParam))
			{
				//Bring up FullConnect dialog
				case IDMENU_CONNECT: 
				{	
					EXC_TEST(pThis->FullConnect(hWnd));
					EXC_TEST(pThis->RefreshControls());
					return 0;
				}

				//IDataInitialize - Using ServiceComponents
				case IDMENU_IDATAINITIALIZE_CREATEDBINSTANCE:
				case IDMENU_IDATAINITIALIZE_CREATEDBINSTANCEEX:
					return 0;

				case IDMENU_IDATAINITIALIZE_LOADSTRINGFROMSTORAGE:
					if(pThis->m_pCConnectDlg->pIDataInitialize())
					{
						WCHAR wszFileName[MAX_QUERY_LEN];
						wszFileName[0] = wEOL;

						//Display Common Dialog to obtain File To Load...
						EXC_TEST(hr = BrowseOpenFileName(pThis->m_hInst, hWnd, "IDataInitialize::LoadStringFromStorage", wszFileName, MAX_QUERY_LEN));
						if(SUCCEEDED(hr))
						{
							WCHAR* pwszInitString = NULL;	
	
							//Now LoadStringFromStorage
							EXC_TEST(hr = pThis->m_pCConnectDlg->LoadInitString(wszFileName, &pwszInitString));
							if(SUCCEEDED(hr))
							{
								if(pwszInitString)
								{
									wcsncpy(pThis->m_pCConnectDlg->m_wszInitString, pwszInitString, MAX_QUERY_LEN);
									pThis->m_pCConnectDlg->m_wszInitString[MAX_QUERY_LEN-1] = wEOL;
								}
							
								//Need to bring up the GetDataSource Dialog
								EXC_TEST(DialogBoxParam(pThis->m_hInst, MAKEINTRESOURCE(IDD_DATAINIT_GETDATASOURCE), hWnd, CConnectDlg::GetDataSourceProc, (LPARAM)pThis->m_pCConnectDlg));
								EXC_TEST(pThis->RefreshControls());
							}
							SAFE_FREE(pwszInitString);
						}
					}
					return 0;

							
				case IDMENU_IDATAINITIALIZE_GETDATASOURCE:
					if(pThis->m_pCConnectDlg->pIDataInitialize())
					{
						//Need to bring up the GetDataSource Dialog
						EXC_TEST(DialogBoxParam(pThis->m_hInst, MAKEINTRESOURCE(IDD_DATAINIT_GETDATASOURCE), hWnd, CConnectDlg::GetDataSourceProc, (LPARAM)pThis->m_pCConnectDlg));
						EXC_TEST(pThis->RefreshControls());
					}
					return 0;

				//Bring up IDBPromptInitialize (PromptDataSource)
				case IDMENU_PROMPTINITIALIZE_PROMPTDATASOURCE: 
					if(pThis->m_pCConnectDlg->pIDBPromptInitialize())
					{
						EXC_TEST(pThis->m_pCConnectDlg->PromptDataSource(DBPROMPTOPTIONS_PROPERTYSHEET));
						EXC_TEST(pThis->RefreshControls());
					}
					return 0;

				//Bring up IDBPromptInitialize (PromptFileName)
				case IDMENU_PROMPTINITIALIZE_PROMPTFILENAME: 
					if(pThis->m_pCConnectDlg->pIDBPromptInitialize())
					{
						EXC_TEST(pThis->m_pCConnectDlg->PromptFileName());
						EXC_TEST(pThis->RefreshControls());
					}
					return 0;

				//Bring up Recent DataSource
				case IDMENU_RECENTCONFIG1: 
				case IDMENU_RECENTCONFIG2:
				case IDMENU_RECENTCONFIG3: 
				case IDMENU_RECENTCONFIG4: 
				case IDMENU_RECENTCONFIG5: 
				case IDMENU_RECENTCONFIG6: 
				case IDMENU_RECENTCONFIG7: 
				case IDMENU_RECENTCONFIG8: 
				case IDMENU_RECENTCONFIG9: 
				case IDMENU_RECENTCONFIG10: 
					if(pThis->m_pCConnectDlg)
						EXC_TEST(pThis->m_pCConnectDlg->LoadRecentConfig(GET_WM_COMMAND_ID(wParam, lParam) - IDMENU_RECENTCONFIG1));
					return 0;	  

				//Bring up Recent Files
				case IDMENU_RECENTFILE1: 
				case IDMENU_RECENTFILE2:
				case IDMENU_RECENTFILE3: 
				case IDMENU_RECENTFILE4: 
				case IDMENU_RECENTFILE5: 
				case IDMENU_RECENTFILE6: 
				case IDMENU_RECENTFILE7: 
				case IDMENU_RECENTFILE8: 
				case IDMENU_RECENTFILE9: 
				case IDMENU_RECENTFILE10: 
					if(pThis->m_pCConnectDlg)
						EXC_TEST(pThis->m_pCConnectDlg->LoadRecentFile(GET_WM_COMMAND_ID(wParam, lParam) - IDMENU_RECENTFILE1));
					return 0;	  

				//Options
				case IDMENU_OPTIONS:
					if(pThis->m_pCConnectDlg)
						EXC_TEST(pThis->m_pCOptionsDlg->Display());
					return 0;

				case IDMENU_TILEHORIZONTAL: // let MDI Client tile the MDI children
					EXC_TEST(SendMessage(m_hWndMDIClient, WM_MDITILE, MDITILE_HORIZONTAL, 0));
					return 0;

				case IDMENU_TILEVERTICAL: // let MDI Client tile the MDI children
					EXC_TEST(SendMessage(m_hWndMDIClient, WM_MDITILE, MDITILE_VERTICAL, 0));
					return 0;

				case IDMENU_CASCADE: // let MDI Client cascade MDI children
					EXC_TEST(SendMessage(m_hWndMDIClient, WM_MDICASCADE, 0, 0));
					return 0;

				case IDMENU_ICONS: // let MDI Client arrange iconic MDI children
					EXC_TEST(SendMessage(m_hWndMDIClient, WM_MDIICONARRANGE, 0, 0));
					return 0;

				case IDMENU_CLOSEALL: // Close all open windows and free hstmts
					Busy();
					EXC_TEST(pThis->RemoveAllChildren());
					EXC_TEST(pThis->RefreshControls());
					Busy(OFF);
					return 0;
									
				case IDMENU_CLOSE:   // Close Active Window
				case IDMENU_DISCONNECT: 
				{	
					//Disconnect and destroy this window
					Busy();
					EXC_TEST(pThis->RemoveChild(pThis->GetActiveChild()));
					EXC_TEST(pThis->RefreshControls());
					Busy(OFF);
					return 0;
				}
									
				case IDMENU_PREVWINDOW:
				{	
					HWND hWndActive = pThis->GetActiveChild();
					if(hWndActive)
						EXC_TEST(SendMessage(m_hWndMDIClient, WM_MDINEXT, (WPARAM)hWndActive, 0));
					return 0;
				}

				case IDMENU_NEXTWINDOW:
				{	
					HWND hWndActive = pThis->GetActiveChild();
					if(hWndActive)
						EXC_TEST(SendMessage(m_hWndMDIClient, WM_MDINEXT, (WPARAM)hWndActive, 1));
					return 0;
				}

				case IDMENU_ABOUT: // bringup About dialog
					EXC_TEST(DialogBoxParam(pThis->m_hInst, MAKEINTRESOURCE(IDD_ABOUT), hWnd, AboutDlgProc, (LPARAM)pThis));
					return 0;
                                                
				case IDMENU_EXIT: // process exit request
					Busy();
					EXC_TEST(pThis->Destroy());
					Busy(OFF);
					return 0;

				default:
					//If we receive a ToolBar or Menu Message that really pertains
					//To a ChildWindow we will just pass the message on to them...
					HWND hWndActive = pThis->GetActiveChild();
					if(hWndActive)
						EXC_TEST(SendMessage(hWndActive, message, wParam, lParam));

					EXC_TEST(DefFrameProc(hWnd, m_hWndMDIClient, WM_COMMAND, wParam, lParam));
					return 0;
			}
			break;
		}

		case WM_NOTIFY:
            switch (((LPNMHDR) lParam)->code) 
            {
                case TTN_NEEDTEXT:    
				{    
					//Get the "this" pointer
					CMainWindow* pThis = (CMainWindow*)GetThis(hWnd);
			
					// Display the ToolTip text.
					static CHAR szBuf[128];
		        	LPTOOLTIPTEXT lpToolTipText = (LPTOOLTIPTEXT)lParam;
    			
					EXC_TEST(LoadString(pThis->m_hInst, lpToolTipText->hdr.idFrom, szBuf, sizeof(szBuf)));
				    lpToolTipText->lpszText = szBuf;
					return 0;
				}
            }
			break;

		case WM_CLOSE:
		{	
			//Get the "this" pointer
			Busy();
			CMainWindow* pThis = (CMainWindow*)GetThis(hWnd);
			EXC_TEST(pThis->Destroy());
			Busy(OFF);
			return 0;
		}

		case WM_DESTROY:
		{	//Get the "this" pointer
			Busy();
			CMainWindow* pThis = (CMainWindow*)GetThis(hWnd);
			EXC_TEST(pThis->Destroy());
			Busy(OFF);
			return 0;
		}

		default:
			break;
	}

	return DefFrameProc(hWnd, m_hWndMDIClient, message, wParam, lParam);
}

				

////////////////////////////////////////////////////////////////
// CMainWindow::AboutDlgProc
//
/////////////////////////////////////////////////////////////////
BOOL CALLBACK CMainWindow::AboutDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static HICON rgIcons[4];
	static ULONG iIcon = 0;
	
	switch (message)
	{
		case WM_INITDIALOG:
		{
			EXC_BEGIN	
			
			//Save the "this" pointer
			Busy();
			CMainWindow* pThis = (CMainWindow*)SetThis(hWnd, (LPARAM)lParam);

			//Load Images
			rgIcons[0] = LoadIcon(pThis->m_hInst, MAKEINTRESOURCE(IDI_ROWSETVIEWER));
			rgIcons[1] = LoadIcon(pThis->m_hInst, MAKEINTRESOURCE(IDI_NORMAL));
			rgIcons[2] = LoadIcon(pThis->m_hInst, MAKEINTRESOURCE(IDI_ROWSETICON));
			rgIcons[3] = LoadIcon(pThis->m_hInst, MAKEINTRESOURCE(IDI_READONLY));

			//Setup a timer
			EXC_TEST(SetTimer(hWnd, ID_TIMER, 100, NULL));

			//Display dynamic ProductName, Version/Build, CopyWrite...
			EXC_TEST(SendMessageFmt(GetDlgItem(hWnd, IDT_FILEINFO), WM_SETTEXT, 0,
				"%s\n"			//ProductName
				"Version %s\n"	//Version/Build
				"%s\n",			//CopyWrite
				
				"Microsoft OLE DB RowsetViewer",
				VER_PRODUCTVERSION_STR,
				VER_LEGALCOPYRIGHT_STR
				));
			
			CenterDialog(hWnd);
			Busy(OFF);
			return TRUE;
			
			EXC_END_(hWnd, EndDialog(hWnd, FALSE));
		}

		case WM_TIMER:
		{
			SendMessage(GetDlgItem(hWnd, IDI_ABOUTICON), STM_SETICON, (WPARAM)rgIcons[iIcon], (LPARAM)rgIcons[iIcon]);
			if(++iIcon >= 4)
				iIcon = 0;
			return 0;
		}

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

			switch (GET_WM_COMMAND_ID(wParam, lParam))
			{
				case IDOK:
				case IDCANCEL:
				{
					//Stop the timer
					KillTimer(hWnd, ID_TIMER);

					EndDialog(hWnd, TRUE);
					return TRUE;
				}
			}
			break;
		}//WM_COMMAND
	}
	
	return FALSE;   
}


////////////////////////////////////////////////////////////////
// CMDIChild::CMDIChild
//
/////////////////////////////////////////////////////////////////
CMDIChild::CMDIChild(HWND hWnd, HINSTANCE hInst, CMainWindow* pCMainWindow)
	: CDialogBase(hWnd, hInst)
{
	m_hWndListView	=	 NULL;
	m_hWndEditBox   =    NULL;
	m_hWndScrollBar	 =   NULL;
	m_ulWindow		= 0;

	//Objects
	ASSERT(pCMainWindow);
	m_pCMainWindow = pCMainWindow;
	
	m_pCListBox		= new CListBox(NULL, m_hInst, pCMainWindow);
	m_pCListBox->Display(pCMainWindow->m_hWnd, 0, 0, 75, 75, WS_BORDER, this);

	m_pCRowset		= new CRowset(this, new CDataSource(this));
	m_pCPropDlg		= new CPropDlg(hWnd, hInst, m_pCMainWindow, m_pCListBox);
	m_pCError		= new CError(this);
	m_pCSchemaDlg	= NULL;		//Defferred Object
	
	//SubClass of EditBox
	m_pSavedEditBoxProc = NULL;
	m_pSavedListBoxProc = NULL;
	m_pSavedListViewProc = NULL;

	//Cursor
	m_fPrevFetchForward = FALSE;
	m_lCurPos = 0;

	//ScrollBar
	m_ulMaxViewItems = 0;
	m_fEndReached = FALSE;
	m_ulScrollMax	= 200;	  

	//Properties
	m_cPropSets		= 0;
	m_rgPropSets	= NULL;

	//LoadBitmap
	m_hBitmapReadOnly = LoadBitmap(m_hInst, MAKEINTRESOURCE(IDB_READONLY));
}


////////////////////////////////////////////////////////////////
// CMDIChild::~CMDIChild
//
/////////////////////////////////////////////////////////////////
CMDIChild::~CMDIChild()

⌨️ 快捷键说明

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