SubEdit::SubEdit (HWND hwndParent, int id) : Edit (hwndParent, id) { _wprocOld = (PWinProc) GetWindowLong (Hwnd (), GWL_WNDPROC); SetWindowLong (Hwnd (), GWL_USERDATA, (LONG) this); SetWindowLong (Hwnd (), GWL_WNDPROC, (LONG) SubProc); }
//------------------------------------------------------------------------- // get the string from a dialog text object //------------------------------------------------------------------------- Bool GWinDialog::GetDialogInt(int& Integer, int DialogItem) { int Success = FALSE; Integer = GetDlgItemInt( Hwnd(), DialogItem, &Success, TRUE ); return Success; }
//------------------------------------------------------------------------- // set the string on a dialog text item //------------------------------------------------------------------------- Bool GWinDialog::SetDialogInt(int& Integer, int DialogItem) { if ( !SetDlgItemInt( Hwnd(), DialogItem, Integer, TRUE ) ) { return FALSE; } return TRUE; }
//------------------------------------------------------------------------- // set the string on a dialog text item //------------------------------------------------------------------------- Bool GWinDialog::SetDialogString(GString& String, int DialogItem) { if ( !SetDlgItemText( Hwnd(), DialogItem, (char*)String ) ) { return FALSE; } return TRUE; }
/*---------------------------------------------------------------------------------------------- Given a tree item, retrieves the text of that item. Parameters: hItem [in] The tree item whose text we want. pszText [out] The buffer into which to put the text. cText [in] The size of the buffer which will receive the text. ----------------------------------------------------------------------------------------------*/ void NetworkTreeView::_GetItemText(HTREEITEM hItem, achar * pszText, int cText) { Assert(hItem); TVITEM item; item.hItem = hItem; item.mask = TVIF_TEXT; item.pszText = pszText; item.cchTextMax = cText; TreeView_GetItem(Hwnd(), &item); }
/*---------------------------------------------------------------------------------------------- Create a new TssEdit. ptss can be NULL if the control should start out empty. ----------------------------------------------------------------------------------------------*/ void TssEdit::Create(HWND hwndPar, int cid, DWORD dwStyle, HWND hwndToolTip, ITsString * ptss, ILgWritingSystemFactory * pwsf, int ws, IActionHandler * pacth) { AssertPtr(pwsf); PreCreate(pwsf, ws, ptss, pacth); m_cid = cid; m_hwndToolTip = hwndToolTip; m_wsBase = ws; m_qwsf = pwsf; if (!m_wsBase) CheckHr(pwsf->get_UserWs(&m_wsBase)); // get the user interface writing system id. // Create the window. WndCreateStruct wcs; wcs.lpszClass = _T("AfVwWnd"); wcs.hwndParent = hwndPar; wcs.SetWid(cid); wcs.style = dwStyle; CreateHwnd(wcs); // Add a tool tip. if (HasToolTip()) { // Add the combo information to the tooltip. TOOLINFO ti = { isizeof(ti), TTF_IDISHWND }; #ifdef DEBUG static StrApp s_str; s_str.Format(_T("Missing a tooltip for edit control with ID %d"), m_cid); ti.lpszText = const_cast<achar *>(s_str.Chars()); #else // !DEBUG ti.lpszText = _T("Dummy text"); #endif // !DEBUG ti.hwnd = Hwnd(); ti.uId = (uint)ti.hwnd; ::GetClientRect(Hwnd(), &ti.rect); ::SendMessage(m_hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti); } PostCreate(ptss); }
//------------------------------------------------------------------------- // get the string from a dialog text object //------------------------------------------------------------------------- Bool GWinDialog::GetDialogString(GString& String, int DialogItem) { String.Chars().Resize(200); String.Chars()[0] = 0; if ( !GetDlgItemText( Hwnd(), DialogItem, String.Data(), String.Length() ) ) { String.Clear(); return FALSE; } return TRUE; }
/*---------------------------------------------------------------------------------------------- Adding something to the tree. It inserts iImage and pszText under the hParent node as the last sibling. Parameters: hParent [in] The tree node that will be the parent of the item being inserted. pszText [in] The text of the item to insert. iImage [in] The image of the item to insert. A value of -1 means that no image is inserted into the tree. rid [in] The string resource to load. Returns the HTREEITEM of the newly inserted item, or NULL if it fails. ----------------------------------------------------------------------------------------------*/ HTREEITEM NetworkTreeView::InsertItem(HTREEITEM hParent, achar * pszText, int iImage) { TV_INSERTSTRUCT is; is.hParent = hParent; is.hInsertAfter = TVI_LAST; is.item.mask = TVIF_TEXT; if (-1 != iImage) is.item.mask |= (TVIF_IMAGE | TVIF_SELECTEDIMAGE); is.item.pszText = pszText; is.item.cchTextMax = _tcslen(pszText); is.item.iImage = iImage; is.item.iSelectedImage = iImage; return TreeView_InsertItem(Hwnd(), &is); }
/*---------------------------------------------------------------------------------------------- This function must be called before the treeview control has been initialized with any data. (i.e. before any items are inserted into it.) ----------------------------------------------------------------------------------------------*/ void NetworkTreeView::SubclassTreeView(HWND hwnd) { SubclassHwnd(hwnd); Assert(GetCount() == 0); // Initialize image list into the tree control if (!m_himlTree) m_himlTree = AfGdi::ImageList_Create(17, 17, ILC_COLORDDB | ILC_MASK, 5, 5); HBITMAP hbmpImageTree = AfGdi::LoadBitmap(ModuleEntry::GetModuleHandle(), MAKEINTRESOURCE(kridImagesNetwork)); ImageList_AddMasked(m_himlTree, hbmpImageTree, RGB(255,255,255)); AfGdi::DeleteObjectBitmap(hbmpImageTree); HIMAGELIST himlProjOld = TreeView_SetImageList(Hwnd(), m_himlTree, TVSIL_NORMAL); if (himlProjOld) AfGdi::ImageList_Destroy(himlProjOld); // Populate the network tree _PopulateTopNetworkNodes(); }
//------------------------------------------------------------------------- // send a message to a dialog item //------------------------------------------------------------------------- LRESULT GWinDialog::SendDialogItemMessage(int DialogItem, int Message, WPARAM wParam, LPARAM lParam) { return SendDlgItemMessage( Hwnd(), DialogItem, Message, wParam, lParam ); }
//------------------------------------------------------------------------- // return handle of an item on the dialog //------------------------------------------------------------------------- HWND GWinDialog::GetDialogItem(int DialogItem) { return GetDlgItem( Hwnd(), DialogItem ); }
/*---------------------------------------------------------------------------------------------- Called in response to the user clicking on a Group within the tree view of the network. The idea is to wait until the user clicks before filling in the contents of the node. Otherwise we'd have to fill in the entire tree, and this can take a very, very long time. The function tests to see if we have filled in the contents yet; and if not, does the work. ----------------------------------------------------------------------------------------------*/ void NetworkTreeView::_ExpandGroupNode(TVITEM *item) { // Check to see if the item's image is a Group image. Otherwise, we are not at any node // that this function is concerned with. if (kridImageWorkgroup != item->iImage) return; CWaitCursor wait; // Now retrieve the first child. If there is no child, or if the child is not a // "placeholder", then we have nothing to do. If it is a placeholder, then get rid of it. HTREEITEM hChild = TreeView_GetChild(Hwnd(), item->hItem); if (NULL == hChild) return; achar szItemText[512]; _GetItemText(hChild, szItemText, sizeof(szItemText)); if (0 != _tcscmp(szItemText, _T("placeholder"))) return; TreeView_DeleteItem(Hwnd(), hChild); // Get the text of the Group that we'll be expanding. _GetItemText(item->hItem, szItemText, sizeof(szItemText)); // Get the parent netresource, by scanning down from the top of the hierarchy. achar szNetwork[512]; DWORD cNetwork = sizeof(szNetwork); if (false == _FindChildNetResource(_T("Entire Network"), NULL, szNetwork, &cNetwork)) return; achar szGroup[512]; DWORD cGroup = sizeof(szGroup); if (false == _FindChildNetResource(szItemText, (NETRESOURCE*)szNetwork, szGroup, &cGroup)) { // If we failed, we might be in Windows 2000; so try again, this time with the // "Microsoft Windows Network" as an intermediate node. achar szMicrosoftWindowsNetwork[512]; DWORD cMicrosoftWindowsNetwork = sizeof(szMicrosoftWindowsNetwork); if (!_FindChildNetResource(_T("Microsoft Windows Network"), (NETRESOURCE *)szNetwork, szMicrosoftWindowsNetwork, &cMicrosoftWindowsNetwork)) { return; } if (!_FindChildNetResource(szItemText, (NETRESOURCE*)szMicrosoftWindowsNetwork, szGroup, &cGroup)) { return; } } // Finally, enumerate the machines into the tree node HANDLE hEnum; if (NO_ERROR == WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, (NETRESOURCE*)szGroup, &hEnum)) { DWORD dwCount = 1; char szBuffer[512]; DWORD dwBufferSize = sizeof(szBuffer); while (NO_ERROR == WNetEnumResource(hEnum, &dwCount, &szBuffer, &dwBufferSize)) { NETRESOURCE *netResource = (NETRESOURCE*)szBuffer; if (NULL != netResource->lpRemoteName && *netResource->lpRemoteName) { InsertItem(item->hItem, _CreateDisplayableNetworkName(netResource->lpRemoteName), kridImageComputer); } dwBufferSize = sizeof(szBuffer); } WNetCloseEnum(hEnum); } }
//------------------------------------------------------------------------- // update window's scrollbar info if applicable //------------------------------------------------------------------------- void GWinControl::UpdateScrollBars() { // only needed if window is setup if ( !Hwnd() ) return; // SCROLLINFO ScrollInfo; ScrollInfo.cbSize = sizeof(SCROLLINFO); // update vert scroll bar if ( StyleFlags() & GWinControlFlags::VertScroll ) { int Min = 0; int Max = 0; int Jump = 0; int Pos = 0; Bool Enable = GetVertScrollProperties( Min, Max, Jump, Pos ); ScrollInfo.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; if ( Enable ) { ScrollInfo.nMin = Min; ScrollInfo.nMax = Max; ScrollInfo.nPage = Jump; ScrollInfo.nPos = Pos; ScrollInfo.fMask |= SIF_DISABLENOSCROLL; // disable if invalid/useless properties (eg. min==max) } else { // remove scroll bar by invalidating properies and NOT setting SIF_DISABLENOSCROLL flag ScrollInfo.nMin = 0; ScrollInfo.nMax = 0; ScrollInfo.nPage = 0; ScrollInfo.nPos = 0; ScrollInfo.fMask &= ~SIF_DISABLENOSCROLL; } SetScrollInfo( Hwnd(), SB_VERT, &ScrollInfo, TRUE ); } // update horz scroll bar if ( StyleFlags() & GWinControlFlags::HorzScroll ) { int Min = 0; int Max = 0; int Jump = 0; int Pos = 0; Bool Enable = GetHorzScrollProperties( Min, Max, Jump, Pos ); ScrollInfo.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; if ( Enable ) { ScrollInfo.nMin = Min; ScrollInfo.nMax = Max; ScrollInfo.nPage = Jump; ScrollInfo.nPos = Pos; ScrollInfo.fMask |= SIF_DISABLENOSCROLL; // disable if invalid/useless properties (eg. min==max) } else { // remove scroll bar by invalidating properies and NOT setting SIF_DISABLENOSCROLL flag ScrollInfo.nMin = 0; ScrollInfo.nMax = 0; ScrollInfo.nPage = 0; ScrollInfo.nPos = 0; ScrollInfo.fMask &= ~SIF_DISABLENOSCROLL; } SetScrollInfo( Hwnd(), SB_HORZ, &ScrollInfo, TRUE ); } }