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

📄 main.cpp

📁 用测试OLE DB提供者的一个程序。能够测试出OEL DB提供者到底实现了哪些接口?很灵的。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	if(!m_hWndToolbar || !m_hWndStatusbar || !m_hWndMDIClient)
	{
		wMessageBox(hWnd, 
			MB_OK|MB_ICONHAND|MB_SYSTEMMODAL,
			wsz_ERROR, L"Unable to load ToolBar, StatusBar, and MDIClient Windows!"); 
		PostMessage(hWnd, WM_CLOSE, 0, 0);
		return FALSE;
	}

	//Load Cursors
	m_hCurSizeNS = LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENS));
	return TRUE;
}


////////////////////////////////////////////////////////////////
// CMainWindow::RefreshControls
//
/////////////////////////////////////////////////////////////////
BOOL CMainWindow::RefreshControls()
{
	if(GetActiveChild() == NULL)
	{
		//Turn off all buttons except for INITIALIZE
		SendMessage(m_hWndToolbar, TB_ENABLEBUTTON, IDMENU_CONNECT,				TRUE);
		SendMessage(m_hWndToolbar, TB_ENABLEBUTTON, IDMENU_DISCONNECT,			FALSE);
		SendMessage(m_hWndToolbar, TB_ENABLEBUTTON, IDMENU_CREATESESSIONWINDOW,	FALSE);
		SendMessage(m_hWndToolbar, TB_ENABLEBUTTON, IDMENU_RUN,					FALSE);
		SendMessage(m_hWndToolbar, TB_ENABLEBUTTON, IDMENU_EXECUTE,				FALSE);
		SendMessage(m_hWndToolbar, TB_ENABLEBUTTON, IDMENU_RESTARTPOSITION,		FALSE);
		SendMessage(m_hWndToolbar, TB_ENABLEBUTTON, IDMENU_REFRESH,				FALSE);
		SendMessage(m_hWndToolbar, TB_ENABLEBUTTON, IDMENU_GETSCHEMAROWSET,		FALSE);
//		SendMessage(m_hWndToolbar, TB_ENABLEBUTTON, IDMENU_INSERTROW,			FALSE);
//		SendMessage(m_hWndToolbar, TB_ENABLEBUTTON, IDMENU_DELETEROWS,			FALSE);
//		SendMessage(m_hWndToolbar, TB_ENABLEBUTTON, IDMENU_SETDATA,				FALSE);
		SendMessage(m_hWndToolbar, TB_ENABLEBUTTON, IDMENU_UPDATE,				FALSE);
		SendMessage(m_hWndToolbar, TB_ENABLEBUTTON, IDMENU_UNDO,				FALSE);

		//Reset Window Count
		m_ulChildWindows = 0;
	}
	return TRUE;
}


////////////////////////////////////////////////////////////////
// CMainWindow::DisplayStatusBarItem
//
/////////////////////////////////////////////////////////////////
BOOL CMainWindow::DisplayStatusBarItem(UINT uResourceID)
{
	CHAR szBuffer[MAX_NAME_LEN+1];
	szBuffer[0] = EOL;

	//Load the string from the StringTable in the resource
	if(uResourceID)
		LoadString(m_hInst, uResourceID, szBuffer, MAX_NAME_LEN);

	return SendMessage(m_hWndStatusbar, WM_SETTEXT, 0, (LPARAM)szBuffer);
}

	
////////////////////////////////////////////////////////////////
// CMainWindow::GetActiveChild
//
/////////////////////////////////////////////////////////////////
HWND CMainWindow::GetActiveChild()
{
	return GetWindow(m_hWndMDIClient, GW_CHILD);
}

////////////////////////////////////////////////////////////////
// CMainWindow::GetActiveChildObj
//
/////////////////////////////////////////////////////////////////
CMDIChild* CMainWindow::GetActiveChildObj()
{
	HWND hWndChild = GetActiveChild();
	return hWndChild ? (CMDIChild*)GetThis(hWndChild) : NULL;
}


////////////////////////////////////////////////////////////////
// CMainWindow::FullConnect
//
/////////////////////////////////////////////////////////////////
BOOL CMainWindow::FullConnect(HWND hWnd)
{
	//Need to first bring up Connection Dialog
	ASSERT(m_pCConnectDlg);
	return m_pCConnectDlg->Display();
}


////////////////////////////////////////////////////////////////
// CMainWindow::RemoveChild
//
/////////////////////////////////////////////////////////////////
BOOL CMainWindow::RemoveChild(HWND hWnd)
{
	if(hWnd)
	{
		//Obtain CMDIChild object pointer
		CMDIChild* pCMDIChild = (CMDIChild*)GetThis(hWnd);

		//Tell the window to destroy itself
		SendMessage(m_hWndMDIClient, WM_MDIDESTROY, (WPARAM)hWnd, 0);
		
		//Now that the window has been destoryed
		//Delete our CMDIChild which corresponds to that window
		SAFE_DELETE(pCMDIChild);
	}
	return TRUE;
}


////////////////////////////////////////////////////////////////
// CMainWindow::RemoveAllChildren
//
/////////////////////////////////////////////////////////////////
BOOL CMainWindow::RemoveAllChildren()
{
	HWND	hWndTemp;	//temp window handle

	//hide MDI Client Windows to avoid repaints
	ShowWindow(m_hWndMDIClient,SW_HIDE);
	
	//Loop through all ChildWindows and Remove
	while(hWndTemp = GetActiveChild())
		RemoveChild(hWndTemp);

	ShowWindow(m_hWndMDIClient, SW_SHOW);
	return TRUE;
}


////////////////////////////////////////////////////////////////
// BOOL CMainWindow::WantedMenuPos
//
/////////////////////////////////////////////////////////////////
BOOL CMainWindow::WantedMenuPos(HMENU hMenu, UINT uPos, DWORD* pdwFlags)
{
	ASSERT(pdwFlags);
	*pdwFlags = 0;
	
	ULONG ulMenuID = GetMenuItemID(hMenu, uPos);

	//Need to handle the "MDI Window" menu
	if(hMenu == GetSubMenu(GetMenu(m_hWnd), 10/*IDMENU_WINDOW*/) && uPos >= 12) 
		return TRUE;
	
	//SubMenu
	if(ulMenuID == ULONG_MAX)
	{
		//Recursive Alogorytm
		HMENU hSubMenu = GetSubMenu(hMenu, uPos);
		INT iItems = GetMenuItemCount(hSubMenu);
		for(LONG i=0; i<iItems; i++)
		{
			if(WantedMenuPos(hSubMenu, i, pdwFlags))
			{
				*pdwFlags = 0;
				return TRUE;
			}
		}
	
		return FALSE;
	}
		
	//Item
	switch(ulMenuID)
	{
		//FILE
		case IDMENU_EXIT:
			return TRUE;

		//WINDOW
		case IDMENU_CLOSE:
		case IDMENU_CLOSEALL:
		case IDMENU_NEXTWINDOW:
		case IDMENU_PREVWINDOW:
		case IDMENU_CASCADE:
		case IDMENU_TILEHORIZONTAL: 
		case IDMENU_TILEVERTICAL: 
		case IDMENU_ICONS: 
			return GetActiveChild() ? TRUE : FALSE;

		//CONNECT
		case IDMENU_CONNECT:
		case IDMENU_OPTIONS:
			return TRUE;
		case IDMENU_DISCONNECT:
			return GetActiveChild() ? TRUE : FALSE;
	
		//Recent Configurations
		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:
			return m_pCConnectDlg->m_listConfigs.GetCount();

		//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:
			return m_pCConnectDlg->m_listFiles.GetCount();

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

		case IDMENU_IDATAINITIALIZE_GETDATASOURCE:
		case IDMENU_IDATAINITIALIZE_LOADSTRINGFROMSTORAGE:
			return (BOOL)m_pCConnectDlg->pIDataInitialize();

		//IDBPromptInitialize - Using ServiceComponents
		case IDMENU_PROMPTINITIALIZE_PROMPTDATASOURCE:
		case IDMENU_PROMPTINITIALIZE_PROMPTFILENAME:
			return (BOOL)m_pCConnectDlg->pIDBPromptInitialize();

		//HELP
//		case IDMENU_HELP:
		case IDMENU_ABOUT:
			return TRUE;

		//Otherwise we have no clue what this command is...
		default:
			break;
	}

	return FALSE;
}


////////////////////////////////////////////////////////////////
// CMainWindow::MainWndProc
//
/////////////////////////////////////////////////////////////////
LONG CALLBACK CMainWindow::MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_CREATE:
        {
			//Save the "this" pointer
			Busy();
			CREATESTRUCT* pCS = (CREATESTRUCT*)lParam;
			CMainWindow* pThis = (CMainWindow*)SetThis(hWnd, (LPARAM)pCS->lpCreateParams);
			CenterDialog(hWnd);
			
			EXC_TEST(pThis->InitControls(hWnd));
			EXC_TEST(pThis->RefreshControls());
			Busy(OFF);
			return 0;
		}

		// Resize children
		case WM_SIZE:
        {
			//Get the "this" pointer
			CMainWindow* pThis = (CMainWindow*)GetThis(hWnd);

			WORD	wWidth = LOWORD(lParam);	//width of rectangle
			WORD	wHeight = HIWORD(lParam);	//height of rectangle

			// calculate proper text height for tool and status bars
			SIZE sizeToolBar	= GetWindowSize(pThis->m_hWndToolbar);
			SIZE sizeStatusBar	= GetWindowSize(pThis->m_hWndStatusbar);

			if(wWidth && wHeight)
			{
				MoveWindow(pThis->m_hWndToolbar, 0, 0, wWidth, sizeToolBar.cy, TRUE);
				MoveWindow(pThis->m_hWndStatusbar, 0, wHeight-sizeStatusBar.cy, wWidth, sizeStatusBar.cy, TRUE);
				MoveWindow(m_hWndMDIClient, 0, sizeToolBar.cy, wWidth, wHeight-sizeToolBar.cy-sizeStatusBar.cy, TRUE);
			}

			//TODO- for some reason this call makes the MDIChild start under the toolbar?
			//DefFrameProc(hWnd, m_hWndMDIClient, message, wParam, lParam);
			return 0;
        }
		
		// Initialize popup menus
		case WM_INITMENUPOPUP:
        {
	        //Ignore the msg if it is for a system menu
			if(HIWORD(lParam))
				break;
			
			HMENU hPopupMenu = (HMENU)wParam;
			UINT  uPos  = LOWORD(lParam);

			//Get the "this" pointer
			CMainWindow* pThis = (CMainWindow*)GetThis(hWnd);
			 
			//Go through the menu items for current popup menu
			//and enable/disable menu item, if required
			
			//Our algortym is to turn (by defualt) all menu items off.
			//If there are any we want we (know about) then turn them on.
			
			//Also note that WantedMenuPos is a recursive algortym.  This is for the
			//case where I need to detmerine if a "submenu->" is enabled or diasbled.
			//The only way to really tell is to know if there are any subitems that
			//are needed, but some of the subitems inturn may be "submenu->".
			//Therefore a item will be enabled if there is at least one subitem 
			//The is wanted, and disabled if there are no subitems wanted.
			INT iMenuItems = GetMenuItemCount(hPopupMenu);
			DWORD dwFlags = 0;
			for(LONG i=0; i<iMenuItems; i++)
			{
				dwFlags = 0;
				EnableMenuItem(hPopupMenu, i, MF_BYPOSITION | MF_GRAYED);
				if(pThis->WantedMenuPos(hPopupMenu, i, &dwFlags))
				{
					EnableMenuItem(hPopupMenu, i, MF_BYPOSITION | MF_ENABLED);
					CheckMenuItem(hPopupMenu, i, MF_BYPOSITION | dwFlags);
				}
			}

			//Maybe the ChildWindow wants this?
			//TODO we have back pointers now, there is no real reason to send
			//messages arround.  Use GetThis(hWndActive) to get the Child object...
			HWND hWndActive = pThis->GetActiveChild();
			if(hWndActive)
				SendMessage(hWndActive, message, wParam, lParam);
			
			//Reset Resent Configurations
			if(uPos==6 && GetMenuItemID(hPopupMenu, 0)==IDMENU_RECENTCONFIG1)
			{
				CHAR szBuffer[MAX_NAME_LEN+10];
				CList<CHAR*>* pCList = &pThis->m_pCConnectDlg->m_listConfigs;
				ASSERT(pCList);

				//Remove all menu items
				for(i=0; i<iMenuItems; i++)
					DeleteMenu(hPopupMenu, 0, MF_BYPOSITION);

				//Display all Recent Configs
				LONG cRecentConfigs = pCList->GetCount();
				for(i=0; i<cRecentConfigs; i++)
				{
					sprintf(szBuffer, "&%d - %s", i+1, pCList->GetAt(pCList->FindIndex(i)));
					AppendMenu(hPopupMenu, MF_STRING, IDMENU_RECENTCONFIG1 + i, szBuffer);
				}
			}
			
			//Reset Resent Files
			if(uPos==7 && GetMenuItemID(hPopupMenu, 0)==IDMENU_RECENTFILE1)
			{
				CHAR szBuffer[MAX_NAME_LEN+10];
				CList<CHAR*>* pCList = &pThis->m_pCConnectDlg->m_listFiles;
				ASSERT(pCList);

				//Remove all menu items
				for(i=0; i<iMenuItems; i++)
					DeleteMenu(hPopupMenu, 0, MF_BYPOSITION);

				//Display all Recent Files
				LONG cRecentFiles = pCList->GetCount();
				for(i=0; i<cRecentFiles; i++)
				{
					sprintf(szBuffer, "&%d - %s", i+1, pCList->GetAt(pCList->FindIndex(i)));
					AppendMenu(hPopupMenu, MF_STRING, IDMENU_RECENTFILE1 + i, szBuffer);
				}
			}

			return 0;
		}
		
		// Update status bar to reflect menu selection
		case WM_MENUSELECT:
		{	
			//Get the "this" pointer
			CMainWindow* pThis = (CMainWindow*)GetThis(hWnd);
			pThis->DisplayStatusBarItem(LOWORD(wParam));
			return 0;
		}
		
		// Process menu commands
		case WM_COMMAND:
		{
			//Filter out any Control Notification codes
			if(GET_WM_COMMAND_CMD(wParam, lParam) > 1)
			{
				//TODO - I'm not sure why the Frame Window receives the EditBox's
				//Notifications?  It should be the Parent which is the MDIChild.
				switch(GET_WM_COMMAND_CMD(wParam, lParam))
				{
					case EN_MAXTEXT:	
					{
						//Get the "this" pointer

⌨️ 快捷键说明

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