home *** CD-ROM | disk | FTP | other *** search
- // wbmfc.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "afxpriv.h"
- #include "wbmfc.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CWBApp
-
- IMPLEMENT_DYNAMIC(CWBApp, CWinApp)
-
- BOOL CWBApp :: WBAppInit(const char *ApplName, const char *UserName,
- const char *Password, const char *ServerPath)
- {
- int err;
-
- err = ::link_kernel((LPSTR)ServerPath, SW_MINIMIZE);
- if (err != KSE_OK)
- {
- OnInitErr(err);
- return FALSE;
- }
-
- err = ::interf_init(m_cdp, 0);
- if (err != KSE_OK)
- {
- ::unlink_kernel();
- OnInitErr(err);
- return FALSE;
- }
- m_Linked = TRUE;
- if (UserName == WBAPPI_NOLOGIN)
- return TRUE;
-
- if (UserName == NULL)
- {
- HWND hAct = GetActiveWindow();
- SetForegroundWindow(hAct);
- m_LoggedOn = ::Alogin(hAct);
- }
- else
- {
- if (Password == NULL)
- Password = "";
- m_LoggedOn = !::Login((LPSTR)UserName, (LPSTR)Password);
- if (!m_LoggedOn)
- OnLoginErr();
- m_pMainWnd->SetFocus();
- }
- if (!m_LoggedOn)
- {
- ::interf_close();
- ::unlink_kernel();
- return FALSE;
- }
-
- if (ApplName && Set_application((LPSTR)ApplName))
- {
- OnSetAppErr();
- ::interf_close();
- ::unlink_kernel();
- m_Linked = FALSE;
- m_LoggedOn = FALSE;
- return FALSE;
- }
- return TRUE;
- }
-
-
-
- BEGIN_MESSAGE_MAP(CWBApp, CWinApp)
- //{{AFX_MSG_MAP(CWBApp)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CWBApp message handlers
- /////////////////////////////////////////////////////////////////////////////
- // CWBFrameWnd
-
- const char USERMENUH[] = "USERMENUH";
- const char USERMENUHW[] = "USERMENUHW";
-
- IMPLEMENT_DYNCREATE(CWBFrameWnd, CMDIFrameWnd)
-
- void CWBFrameWnd::UpdateMenuProps(HMENU hMainMenu, HMENU hWinMenu)
- {
- ::SetProp(m_hWnd, USERMENUH, (HANDLE)hMainMenu);
- if (hWinMenu == (HMENU) -1)
- hWinMenu = GetWindowMenuPopup(hMainMenu);
- ::SetProp(m_hWnd, USERMENUH, (HANDLE)hWinMenu);
- }
-
- BEGIN_MESSAGE_MAP(CWBFrameWnd, CMDIFrameWnd)
- //{{AFX_MSG_MAP(CWBFrameWnd)
- ON_WM_ACTIVATE()
- ON_WM_CREATE()
- ON_WM_CLOSE()
- ON_WM_DESTROY()
- ON_WM_INITMENUPOPUP()
- ON_WM_SIZE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CWBFrameWnd message handlers
-
- LRESULT CWBFrameWnd::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- // TODO: Add your specialized code here and/or call the base class
- if (message == WM_CREATE && FramePars.Flags)
- return 0;
- if (::WinBaseFrameProc(m_hWnd, message, wParam, lParam) == 0L)
- return 0L;
- return CMDIFrameWnd::DefWindowProc(message, wParam, lParam);
- }
-
- static CWBViewWnd *OpenViewPtr;
-
- BOOL CWBFrameWnd::OnCommand(WPARAM wParam, LPARAM lParam)
- {
- // TODO: Add your specialized code here and/or call the base class
-
- HWND hView = GetCmdHWND(wParam, lParam);
- WORD ID = GetCmdID(wParam, lParam);
- WORD Cmd = GetCmdCMD(wParam, lParam);
-
- if (ID == IDM_HELP_GENERIC)
- return FALSE;
- else if (ID == 999 && ::IsWindow(hView))
- {
- if (Cmd == 1 && OpenViewPtr && OpenViewPtr->m_hWnd == NULL)
- {
- OpenViewPtr->SubclassWindow(hView);
- OpenViewPtr = NULL;
- }
- else if ((Cmd == 1 || Cmd == 11 || Cmd == 13) && (::GetParent(hView) == m_hWndMDIClient))
- {
- CWBAuxMDIWnd *MDIWnd = new CWBAuxMDIWnd();
- if (MDIWnd)
- MDIWnd->SubclassWindow(hView);
- }
- return FALSE;
- }
- return CMDIFrameWnd::OnCommand(wParam, lParam);
- }
-
- int CWBFrameWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (FramePars.Flags == WBF_NO_TOOLBAR || WBF_NO_STATUSBAR)
- {
- int res = CMDIFrameWnd::OnCreate(lpCreateStruct);
- if (res)
- return(res);
- Init_window_env(m_hWnd, m_hWndMDIClient, 0, FramePars.Flags);
- }
- else
- {
- if (FramePars.WinMenu == 0x8000)
- {
- HMENU hMenu = ::GetMenu(m_hWnd);
- if (hMenu != NULL)
- FramePars.WinMenu = ::GetMenuItemCount(hMenu) - 2;
- }
- lpCreateStruct->lpCreateParams = (LPVOID)&FramePars;
- if (::WinBaseFrameProc(m_hWnd, WM_CREATE, 0, LPARAM(lpCreateStruct)) == -1)
- return -1;
-
- m_hWndMDIClient = ::GetDlgItem(m_hWnd, CLIENT_ID);
- }
- HMENU hMenu = ::GetMenu(m_hWnd);
- ::SetProp(m_hWnd, USERMENUH, hMenu);
- hMenu = ::GetSubMenu(hMenu, FramePars.WinMenu);
- ::SetProp(m_hWnd, USERMENUHW, hMenu);
-
- // TODO: Add your specialized creation code here
-
- return 0;
- }
-
- void CWBFrameWnd::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
- {
- // TODO: Add your message handler code here
- Default();
- }
-
-
- void CWBFrameWnd::OnClose()
- {
- // TODO: Add your message handler code here and/or call default
- Default();
- }
-
- void CWBFrameWnd::OnDestroy()
- {
- CMDIFrameWnd::OnDestroy();
-
- // TODO: Add your message handler code here
- ((CWBApp *)AfxGetApp())->Logout();
- }
-
- void CWBFrameWnd::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
- {
- if (::WinBaseFrameProc(m_hWnd, WM_INITMENUPOPUP, (UINT)pPopupMenu->m_hMenu, MAKELPARAM(nIndex, bSysMenu)) == 0L)
- return;
- if (!bSysMenu)
- {
- HWND hAct = (HWND)::SendMessage(m_hWndMDIClient, WM_MDIGETACTIVE, 0, 0);
- if (hAct)
- {
- LRESULT chtype = ::SendMessage(hAct, SZM_MDI_CHILD_TYPE, 0, 0);
- if (chtype == EDIT_MDI_CHILD)
- return;
- if (pPopupMenu->m_hMenu == GetWindowMenuPopup(::GetMenu(m_hWnd)))
- {
- UINT Cnt = pPopupMenu->GetMenuItemCount();
- for (UINT ID = 0; ID < Cnt; ID++)
- {
- UINT Stat = pPopupMenu->GetMenuState(ID, MF_BYPOSITION);
- if (Stat & MF_SEPARATOR)
- break;
- pPopupMenu->EnableMenuItem(ID, MF_BYPOSITION | MF_ENABLED);
- }
- return;
- }
- }
- }
- CMDIFrameWnd::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
-
- // TODO: Add your message handler code here
- }
-
- void CWBFrameWnd::OnSize(UINT nType, int cx, int cy)
- {
- // TODO: Add your message handler code here
- if (FramePars.Flags)
- CMDIFrameWnd::OnSize(nType, cx, cy);
- else
- Default();
- }
-
- void CWBFrameWnd::RecalcLayout(BOOL bNotify)
- {
- // TODO: Add your specialized code here and/or call the base class
- if (FramePars.Flags)
- {
- CMDIFrameWnd::RecalcLayout(bNotify);
- return;
- }
- if (m_bInRecalcLayout)
- return;
- m_bInRecalcLayout = TRUE;
-
- CRect Rect;
- GetClientRect(&Rect);
- if (Rect.right == 0 || Rect.bottom == 0)
- SetWindowPos(NULL, 0, 0, 640, 480, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER);
-
- #ifdef WIN32
- RepositionBars(0, (UINT)-1, GetWindowLong(m_hWndMDIClient, GWL_ID));
- #else
- RepositionBars(0, (UINT)-1, GetWindowWord(m_hWndMDIClient, GWW_ID));
- #endif
- m_bInRecalcLayout = FALSE;
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CWBViewWnd
-
- IMPLEMENT_DYNCREATE(CWBViewWnd, CMDIChildWnd)
-
- BOOL CWBViewWnd :: Open(const char *ViewDef, tcursnum Base, uns32 Flags,
- trecnum Pos, FARPROC Filter, CWBViewWnd *ParWnd)
- {
- if (OpenViewPtr)
- return(FALSE);
- OpenViewPtr = this;
-
- window_id hView = ::Open_view((LPSTR)ViewDef, Base, Flags, Pos, Filter, ParWnd ? ParWnd->m_hWnd : NULL, NULL);
- return((BOOL)hView);
- }
-
-
- BOOL CWBViewWnd :: Open_query_view(const char * ViewDef, tcursnum Base, BOOL Order,
- char *Query, FARPROC Filter, CWBViewWnd *ParWnd)
- {
- if (OpenViewPtr)
- return(FALSE);
- OpenViewPtr = this;
-
- window_id hView = ::Open_view(ViewDef, Base, QUERY_VIEW, 0, Filter, ParWnd ? ParWnd->m_hWnd : NULL, NULL);
- return((BOOL)hView);
- }
-
- BOOL CWBViewWnd :: Select_records(const char *ViewDef, tcursnum Base, uns32 Flags,
- short Limit, trecnum *Bindl, FARPROC Filter, CWBViewWnd *ParWnd)
- {
- if (OpenViewPtr)
- return(FALSE);
- OpenViewPtr = this;
-
- window_id hView = ::Select_records((LPSTR)ViewDef, Base, Flags, Limit, Bindl, Filter, ParWnd ? ParWnd->m_hWnd : NULL, NULL);
- return((BOOL)hView);
- }
-
-
- BOOL CWBViewWnd :: Relate_record(const char *LocalAttr, const char *ViewDef, tcursnum Base,
- uns32 Flags, FARPROC Filter, const char *RemoteAttr)
- {
- if (OpenViewPtr)
- return(FALSE);
- OpenViewPtr = this;
-
- window_id hView = ::Relate_record(LocalAttr, (LPSTR)ViewDef, Base, Flags, Filter, NULL, RemoteAttr);
- return((BOOL)hView);
- }
-
-
- BEGIN_MESSAGE_MAP(CWBViewWnd, CMDIChildWnd)
- //{{AFX_MSG_MAP(CWBViewWnd)
- ON_WM_CLOSE()
- ON_WM_DESTROY()
- ON_WM_MDIACTIVATE()
- ON_WM_SIZE()
- ON_WM_HSCROLL()
- ON_WM_VSCROLL()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CWBViewWnd message handlers
-
- BOOL CWBViewWnd::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
- {
- *pResult = ViewWndProc(m_hWnd, WM_NOTIFY, wParam, lParam);
- if (*pResult)
- return(TRUE);
- return(CMDIChildWnd::OnNotify(wParam, lParam, pResult));
- }
-
- LRESULT CWBViewWnd::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- // TODO: Add your specialized code here and/or call the base class
-
- return ViewWndProc(m_hWnd, message, wParam, lParam);
- }
-
- void CWBViewWnd::PostNcDestroy()
- {
- // TODO: Add your specialized code here and/or call the base class
- delete this;
- }
-
- void CWBViewWnd::OnClose()
- {
- // TODO: Add your message handler code here and/or call default
-
- Default();
- }
-
- void CWBViewWnd::OnDestroy()
- {
- Default();
-
- // TODO: Add your message handler code here
-
- }
-
- void CWBViewWnd::OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd)
- {
- Default();
-
- // TODO: Add your message handler code here
- CMDIChildWnd::OnMDIActivate(bActivate, pActivateWnd, pDeactivateWnd);
- }
-
- void CWBViewWnd::OnUpdateFrameMenu(BOOL bActive, CWnd* pActivateWnd, HMENU hMenuAlt)
- {
- HMENU hMenu = hMenuAlt;
- if (bActive && !hMenu && pActivateWnd->IsKindOf(RUNTIME_CLASS(CWBViewWnd)))
- hMenu = ((CWBViewWnd *)pActivateWnd)->GetMenu();
- CMDIChildWnd::OnUpdateFrameMenu(bActive, pActivateWnd, hMenu);
- }
-
- void CWBViewWnd::OnSize(UINT nType, int cx, int cy)
- {
- Default();
-
- // TODO: Add your message handler code here
-
- }
-
- void CWBViewWnd::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- // TODO: Add your message handler code here and/or call default
-
- Default();
- }
-
- void CWBViewWnd::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- // TODO: Add your message handler code here and/or call default
-
- Default();
- }
- /////////////////////////////////////////////////////////////////////////////
- // CWBModalViewWnd
-
- IMPLEMENT_DYNCREATE(CWBModalViewWnd, CFrameWnd)
-
- BOOL CWBModalViewWnd :: Open(const char *ViewDef, tcursnum Base, uns32 Flags,
- trecnum Pos, FARPROC Filter, CWBViewWnd *ParWnd)
- {
- if (OpenViewPtr)
- return(FALSE);
- OpenViewPtr = (CWBViewWnd *)this;
-
- window_id hView = ::Open_view((LPSTR)ViewDef, Base, Flags | MODAL_VIEW, Pos, Filter, ParWnd ? ParWnd->m_hWnd : NULL, NULL);
- return((BOOL)hView);
- }
-
- BOOL CWBModalViewWnd :: Open_query_view(const char * ViewDef, tcursnum Base, BOOL Order,
- char *Query, FARPROC Filter, CWBViewWnd *ParWnd)
- {
- if (OpenViewPtr)
- return(FALSE);
- OpenViewPtr = (CWBViewWnd *)this;
-
- window_id hView = ::Open_view(ViewDef, Base, QUERY_VIEW, 0, Filter, ParWnd ? ParWnd->m_hWnd : NULL, NULL);
- return((BOOL)hView);
- }
-
- BOOL CWBModalViewWnd :: Select_records(const char *ViewDef, tcursnum Base, uns32 Flags,
- short Limit, trecnum *Bindl, FARPROC Filter, CWBViewWnd *ParWnd)
- {
- if (OpenViewPtr)
- return(FALSE);
- OpenViewPtr = (CWBViewWnd *)this;
-
- window_id hView = ::Select_records((LPSTR)ViewDef, Base, Flags | MODAL_VIEW, Limit, Bindl, Filter, ParWnd ? ParWnd->m_hWnd : NULL, NULL);
- return((BOOL)hView);
- }
-
-
- BOOL CWBModalViewWnd :: Relate_record(const char *LocalAttr, const char *ViewDef, tcursnum Base,
- uns32 Flags, FARPROC Filter, const char *RemoteAttr)
- {
- if (OpenViewPtr)
- return(FALSE);
- OpenViewPtr = (CWBViewWnd *)this;
-
- window_id hView = ::Relate_record(LocalAttr, (LPSTR)ViewDef, Base, Flags | MODAL_VIEW, Filter, NULL, RemoteAttr);
- return((BOOL)hView);
- }
-
-
- BEGIN_MESSAGE_MAP(CWBModalViewWnd, CFrameWnd)
- //{{AFX_MSG_MAP(CWBModalViewWnd)
- ON_WM_CLOSE()
- ON_WM_DESTROY()
- ON_WM_HSCROLL()
- ON_WM_SIZE()
- ON_WM_VSCROLL()
- //}}AFX_MSG_MAP
- ON_MESSAGE(WM_DISABLEMODAL, OnDisableModal)
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CWBModalViewWnd message handlers
-
- BOOL CWBModalViewWnd::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
- {
- *pResult = ViewWndProc(m_hWnd, WM_NOTIFY, wParam, lParam);
- if (*pResult)
- return(TRUE);
- return(CFrameWnd::OnNotify(wParam, lParam, pResult));
- }
-
- LRESULT CWBModalViewWnd::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- // TODO: Add your specialized code here and/or call the base class
-
- return CFrameWnd::DefWindowProc(message, wParam, lParam);
- }
-
- void CWBModalViewWnd::PostNcDestroy()
- {
- // TODO: Add your specialized code here and/or call the base class
-
- delete this;
- }
-
- void CWBModalViewWnd::OnClose()
- {
- // TODO: Add your message handler code here and/or call default
-
- Default();
- }
-
- void CWBModalViewWnd::OnDestroy()
- {
- Default();
-
- // TODO: Add your message handler code here
-
- }
-
- void CWBModalViewWnd::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- // TODO: Add your message handler code here and/or call default
-
- Default();
- }
-
- void CWBModalViewWnd::OnSize(UINT nType, int cx, int cy)
- {
- Default();
-
- // TODO: Add your message handler code here
-
- }
-
- void CWBModalViewWnd::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- // TODO: Add your message handler code here and/or call default
-
- Default();
- }
- /////////////////////////////////////////////////////////////////////////////
- // CWBAuxMDIWnd
-
- IMPLEMENT_DYNCREATE(CWBAuxMDIWnd, CMDIChildWnd)
-
- BEGIN_MESSAGE_MAP(CWBAuxMDIWnd, CMDIChildWnd)
- //{{AFX_MSG_MAP(CWBAuxMDIWnd)
- ON_WM_CLOSE()
- ON_WM_DESTROY()
- ON_WM_MDIACTIVATE()
- ON_WM_SETFOCUS()
- ON_WM_SIZE()
- ON_WM_VSCROLL()
- ON_WM_HSCROLL()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CWBAuxMDIWnd message handlers
-
- void CWBAuxMDIWnd::OnClose()
- {
- // TODO: Add your message handler code here and/or call default
-
- Default();
- }
-
- void CWBAuxMDIWnd::OnDestroy()
- {
- Default();
-
- // TODO: Add your message handler code here
-
- }
-
- void CWBAuxMDIWnd::OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd)
- {
- Default();
-
- // TODO: Add your message handler code here
-
- }
-
- void CWBAuxMDIWnd::OnSetFocus(CWnd* pOldWnd)
- {
- Default();
-
- // TODO: Add your message handler code here
-
- }
-
- void CWBAuxMDIWnd::OnSize(UINT nType, int cx, int cy)
- {
- Default();
-
- // TODO: Add your message handler code here
-
- }
-
- void CWBAuxMDIWnd::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- // TODO: Add your message handler code here and/or call default
-
- Default();
- }
-
- void CWBAuxMDIWnd::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- // TODO: Add your message handler code here and/or call default
-
- Default();
- }
-
- LRESULT CWBAuxMDIWnd::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- // TODO: Add your specialized code here and/or call the base class
-
- return(OrigWndProc(m_hWnd, message, wParam, lParam));
- }
-
- void CWBAuxMDIWnd::PostNcDestroy()
- {
- // TODO: Add your specialized code here and/or call the base class
-
- delete this;
- }
-