BOOL CMFCControlContainer::SubclassDlgControls() { if (m_pWnd->GetSafeHwnd() != NULL) { // Subclass Feature Pack controls: CWnd* pWndChild = m_pWnd->GetWindow(GW_CHILD); while (pWndChild != NULL) { ASSERT_VALID(pWndChild); TCHAR lpszClassName [MAX_CLASS_NAME + 1]; ::GetClassName(pWndChild->GetSafeHwnd(), lpszClassName, MAX_CLASS_NAME); CWnd* pWndSubclassedCtrl = CreateDlgControl(lpszClassName); if (pWndSubclassedCtrl != NULL) { m_arSubclassedCtrls.Add((CObject*)pWndSubclassedCtrl); pWndSubclassedCtrl->SubclassWindow(pWndChild->GetSafeHwnd()); } pWndChild = pWndChild->GetNextWindow(); } return TRUE; } return FALSE; }
int InputBox(HWND hwnd, LPCTSTR prompt, LPCTSTR title, LPTSTR buffer, INT buflength) { HGLOBAL hgbl; LPWORD lpw; LRESULT ret; DWORD style; hgbl = GlobalAlloc(GMEM_ZEROINIT, 1024); if(!hgbl) return 0; LPVOID lpv = GlobalLock(hgbl); // Prepare the dialog box style = DS_SETFONT | DS_CENTER | DS_3DLOOK | WS_POPUP | WS_SYSMENU | DS_MODALFRAME | WS_CAPTION | WS_VISIBLE; lpw = InitDialog(lpv, title, style, 4, "MS Sans Serif", 8, 0, 0, 319, 47); // OK-Button style = WS_CHILD | WS_VISIBLE | WS_TABSTOP |BS_DEFPUSHBUTTON; lpw = CreateDlgControl(lpw, BUTTON_CLASS, IDOK, "OK", style, 264, 7, 48, 15); // Cancel-Button style = WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON; lpw = CreateDlgControl(lpw, BUTTON_CLASS, IDCANCEL, "Abbrechen", style, 264, 26, 48, 15); // Text to prompt style = WS_CHILD | WS_VISIBLE | SS_LEFT; lpw = CreateDlgControl(lpw, STATIC_CLASS, ID_INFOTEXT, prompt, style, 10, 9, 129, 16); // Edit-Control style = WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP; lpw = CreateDlgControl(lpw, EDIT_CLASS, ID_INPUT, "", style, 10, 26, 249, 13); GlobalUnlock(hgbl); int data[2] = {(int)buffer, buflength}; ret = DialogBoxIndirectParamA(NULL, (LPDLGTEMPLATE)hgbl, hwnd, (DLGPROC)InputBoxDlgProc, (int)data); GlobalFree(hgbl); return (ret > 0) ? ret : 0; }
BOOL COccManager::CreateDlgControls(CWnd* pWndParent, void* lpResource, _AFX_OCC_DIALOG_INFO* pOccDlgInfo) { // if there are no OLE controls in this dialog, then there's nothing to do if (pOccDlgInfo->m_pNewTemplate == NULL) return TRUE; ASSERT(pWndParent != NULL); HWND hwParent = pWndParent->GetSafeHwnd(); BOOL bDialogEx = IsDialogEx(pOccDlgInfo->m_pNewTemplate); BOOL bSuccess = TRUE; if (lpResource != NULL) { ASSERT(pOccDlgInfo != NULL); ASSERT(pOccDlgInfo->m_ppOleDlgItems != NULL); DLGITEMTEMPLATE** ppOleDlgItems = pOccDlgInfo->m_ppOleDlgItems; UNALIGNED WORD* lpnRes = (WORD*)lpResource; int iItem = 0; HWND hwAfter = HWND_TOP; while (bSuccess && *lpnRes != 0) { #ifndef _MAC WORD nIDC = *lpnRes++; WORD nMsg = *lpnRes++; DWORD dwLen = *((UNALIGNED DWORD*&)lpnRes)++; #else // Unfortunately we can't count on these values being // word-aligned (and dwLen is word-swapped besides), so // we have to pull them out a byte at a time to avoid // address errors on 68000s. WORD nIDC; WORD nMsg; DWORD dwLen; memcpy(&nIDC, lpnRes++, sizeof(WORD)); memcpy(&nMsg, lpnRes++, sizeof(WORD)); memcpy((WORD*)&dwLen + 1, lpnRes++, sizeof(WORD)); memcpy(&dwLen, lpnRes++, sizeof(WORD)); #endif #define WIN16_LB_ADDSTRING 0x0401 #define WIN16_CB_ADDSTRING 0x0403 ASSERT(nMsg == LB_ADDSTRING || nMsg == CB_ADDSTRING || nMsg == WIN16_LB_ADDSTRING || nMsg == WIN16_CB_ADDSTRING || nMsg == WM_OCC_LOADFROMSTREAM || nMsg == WM_OCC_LOADFROMSTREAM_EX || nMsg == WM_OCC_LOADFROMSTORAGE || nMsg == WM_OCC_LOADFROMSTORAGE_EX || nMsg == WM_OCC_INITNEW); if (nMsg == WM_OCC_LOADFROMSTREAM || nMsg == WM_OCC_LOADFROMSTREAM_EX || nMsg == WM_OCC_LOADFROMSTORAGE || nMsg == WM_OCC_LOADFROMSTORAGE_EX || nMsg == WM_OCC_INITNEW) { // Locate the DLGITEMTEMPLATE for the new control, and the control // that should precede it in z-order. DLGITEMTEMPLATE* pDlgItem; while (((pDlgItem = ppOleDlgItems[iItem++]) == NULL) && (pDlgItem != (DLGITEMTEMPLATE*)(-1))) { if (hwAfter == HWND_TOP) hwAfter = GetWindow(hwParent, GW_CHILD); else hwAfter = GetWindow(hwAfter, GW_HWNDNEXT); ASSERT(hwAfter != NULL); // enough non-OLE controls? } ASSERT(pDlgItem != NULL); // enough dialog item templates? HWND hwNew = NULL; if (pDlgItem != (DLGITEMTEMPLATE*)(-1)) { #ifdef _DEBUG WORD id = bDialogEx ? (WORD)((DLGITEMTEMPLATEEX*)pDlgItem)->id : pDlgItem->id; ASSERT(id == nIDC); // make sure control IDs match! #endif // Create the OLE control now. hwNew = CreateDlgControl(pWndParent, hwAfter, bDialogEx, pDlgItem, nMsg, (BYTE*)lpnRes, dwLen); } if (hwNew != NULL) { if (GetParent(hwNew) == hwParent) hwAfter = hwNew; } else bSuccess = FALSE; } // skip past data lpnRes = (WORD*)((LPBYTE)lpnRes + (UINT)dwLen); } } if (bSuccess) BindControls(pWndParent); return bSuccess; }