void CMainWizard::OnScExportSettings(void) { CString strFilter; CString strTitle; CProcessPrivileges processPrivileges; enum { fdwFlags = OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY }; strFilter.LoadString(IDS_SETTINGS_FILTER); #if (_MFC_VER < 0x0700) CFileDialogEx dlgSaveAs(FALSE, _T("hive"), AfxGetAppName(), fdwFlags, strFilter); #else CFileDialog dlgSaveAs(FALSE, _T("hive"), AfxGetAppName(), fdwFlags, strFilter); #endif // _MFC_VER strTitle.LoadString(IDS_TITLE_EXPORT); dlgSaveAs.m_ofn.lpstrTitle = strTitle; if (dlgSaveAs.DoModal() == IDOK) { BeginWaitCursor(); CWinApp* pApp = AfxGetApp(); ASSERT_VALID(pApp); processPrivileges[SE_BACKUP_NAME] = SE_PRIVILEGE_ENABLED; HKEY hAppKey = pApp->GetAppRegistryKey(); ::RegSaveKey(hAppKey, dlgSaveAs.GetPathName(), NULL); ::RegCloseKey(hAppKey); processPrivileges[SE_BACKUP_NAME] = 0; EndWaitCursor(); } }
BOOL CLeashProperties::OnInitDialog() { CDialog::OnInitDialog(); pLeashGetTimeServerName(timeServer, TIMEHOST); SetDlgItemText(IDC_EDIT_TIME_SERVER, timeServer); if (getenv(TIMEHOST)) GetDlgItem(IDC_EDIT_TIME_SERVER)->EnableWindow(FALSE); else GetDlgItem(IDC_STATIC_TIMEHOST)->ShowWindow(FALSE); CWinApp * pApp = AfxGetApp(); if (pApp) m_initMissingFiles = m_newMissingFiles = pApp->GetProfileInt("Settings", "CreateMissingConfig", FALSE_FLAG); CheckDlgButton(IDC_CHECK_CREATE_MISSING_CFG, m_initMissingFiles); dw_initMslsaImport = dw_newMslsaImport = pLeash_get_default_mslsa_import(); switch ( dw_initMslsaImport ) { case 0: CheckDlgButton(IDC_RADIO_MSLSA_IMPORT_OFF,TRUE); break; case 1: CheckDlgButton(IDC_RADIO_MSLSA_IMPORT_ON,TRUE); break; case 2: CheckDlgButton(IDC_RADIO_MSLSA_IMPORT_MATCH,TRUE); break; } return TRUE; }
// @pymethod |PyCWinApp|AddDocTemplate|Adds a template to the application list. static PyObject * ui_app_add_doc_template(PyObject *self, PyObject *args) { PyObject *obTemplate; if (!PyArg_ParseTuple(args,"O:AddDocTemplate", &obTemplate)) // @pyparm <o PyCDocTemplate>|template||The template to be added. return NULL; if (!ui_base_class::is_uiobject(obTemplate, &PyCDocTemplate::type)) RETURN_TYPE_ERR("The parameter must be a template object"); CDocTemplate *pTempl = PyCDocTemplate::GetTemplate(obTemplate); if (pTempl==NULL) return NULL; CWinApp *pApp = GetApp(); if (!pApp) return NULL; // walk all templates in the application looking for it. CDocTemplate* pTemplate; POSITION pos = pApp->m_pDocManager ? pApp->m_pDocManager->GetFirstDocTemplatePosition() : NULL; while (pos != NULL) { pTemplate = pApp->m_pDocManager->GetNextDocTemplate(pos); if (pTemplate==pTempl) RETURN_ERR("The template is already in the application list"); } GUI_BGN_SAVE; pApp->AddDocTemplate(pTempl); GUI_END_SAVE; RETURN_NONE; }
void CMainFrame::OnDropFiles( HDROP hDropInfo ) { SetActiveWindow(); // activate us first ! CWinApp* pApp = AfxGetApp(); ASSERT(pApp != NULL); CString strFile; UINT nFilesCount=DragQueryFile(hDropInfo,INFINITE,NULL,0); for(UINT i=0; i<nFilesCount; i++) { int pathLen = DragQueryFile(hDropInfo, i, strFile.GetBuffer(MAX_PATH), MAX_PATH); strFile.ReleaseBuffer(pathLen); DWORD dwFileAttr = ::GetFileAttributes(strFile); if ((dwFileAttr & FILE_ATTRIBUTE_DIRECTORY)==FILE_ATTRIBUTE_DIRECTORY) { //目录,需要递归里面包含的文件 } else { CString strExt=strFile.Mid(strFile.GetLength()-4,4); if (strExt.CompareNoCase(_T(".xml"))==0) { pApp->OpenDocumentFile(strFile); } } } DragFinish(hDropInfo); }
void CMainFrame::OnViewDeletedrecords() { m_bShowDeletedRecords = !m_bShowDeletedRecords; CWinApp* pApp = AfxGetApp(); ASSERT_VALID(pApp); // Iterate through the application's document templates list POSITION posTemplate = pApp->GetFirstDocTemplatePosition(); while(posTemplate) { // For each document template object... CDocTemplate* pTemplate = pApp->GetNextDocTemplate(posTemplate); ASSERT_VALID(pTemplate); ASSERT_KINDOF(CDocTemplate, pTemplate); // Iterate through the template's document list POSITION posDocument = pTemplate->GetFirstDocPosition(); while(posDocument) { // For each document object... CDocument* pDoc = pTemplate->GetNextDoc(posDocument); ASSERT_VALID(pDoc); ASSERT_KINDOF(CDocument, pDoc); // reload records POSITION pos = pDoc->GetFirstViewPosition(); while (pos) ((CDBFExplorerView *)pDoc->GetNextView(pos))->ShowRecords(m_bShowDeletedRecords); } } }
BOOL CLogin::OnInitDialog() { CDialog::OnInitDialog(); CWinApp* pApp = AfxGetApp(); //determine range of accounts in history. //range begins at 1 and ends at and includes latest. Bing: "latest" is actually the count for previous logins. // //in this case, if 0 is the latest, then there is no history //and thus, don't do anything. UINT latest = pApp->GetProfileInt("History", "Latest", 0); m_ListBox.SetExtendedStyle( m_ListBox.GetExtendedStyle() | LVS_EX_FULLROWSELECT ); m_ListBox.InsertColumn(0, "Name", LVCFMT_LEFT, 75); m_ListBox.InsertColumn(1, "Zone", LVCFMT_LEFT, 75); m_ListBox.InsertColumn(2, "Server Host", LVCFMT_LEFT, 110); m_ListBox.InsertColumn(3, "Port", LVCFMT_LEFT, 75); for(UINT i = 1; i <= latest; i++) { FillBoxes(i, true); } int count = m_ListBox.GetItemCount(); if(count > 0) { VERIFY(m_ListBox.SetItemState(count-1, 0xFFFFFFFF, LVIS_SELECTED)); } // set the last login int last_login = pApp->GetProfileInt("History", "LastLogin", 0); if(last_login == 0) /* no last login */ { if(latest > 0) { last_login = latest; } } if(last_login > 0) { FillBoxes(last_login, false); } CButton *cbox = (CButton *)GetDlgItem(IDC_CHECK_PRELOGINS); if(pApp->GetProfileInt("ShowPreviousLogins", "YesNo", 1) == 0) { cbox->SetCheck(BST_UNCHECKED); } else { cbox->SetCheck(BST_CHECKED); } OnBnClickedCheckPrelogins(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
// sélection de la langue void LANG_INIT() { CWinApp* pApp = AfxGetApp(); if (pApp) { int test = pApp->GetProfileInt("Language","IntId",0); LANG_T(pApp->GetProfileInt("Language","IntId",0)); } }
void ImageDialog::OnBnClickedBrowse() { CWinApp* theApp = AfxGetApp(); char buffer[MAX_PATH]; string lastSave; lastSave = theApp->GetProfileString("Last Config", "lastSave"); int trim = lastSave.rfind("\\"); lastSave = lastSave.substr(0, trim); buffer[0] = '\0'; OPENFILENAME browse; ZeroMemory(&browse, sizeof(browse)); browse.lStructSize = sizeof(browse); browse.hwndOwner = this->m_hWnd; browse.lpstrFile = buffer; browse.nMaxFile = sizeof(buffer); browse.lpstrFilter = "All Files\0*.*\0"; browse.nFilterIndex = 1; browse.lpstrTitle = "Select Save Path/Filename"; browse.lpstrFileTitle = 0; browse.lpstrInitialDir = lastSave.c_str(); browse.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; if (GetSaveFileName(&browse) != 0) { string file(buffer); pngwriter->SetFileName(file); filePath.SetWindowText(pngwriter->GetFileName().c_str()); } }
void ImageDialog::OnBnClickedBrowseAVI() { CWinApp* theApp = AfxGetApp(); char buffer[MAX_PATH]; string lastSave; lastSave = theApp->GetProfileString("Last Config", "lastSave"); int trim = lastSave.rfind("\\"); lastSave = lastSave.substr(0, trim); buffer[0] = '\0'; OPENFILENAME browse; ZeroMemory(&browse, sizeof(browse)); browse.lStructSize = sizeof(browse); browse.hwndOwner = this->m_hWnd; browse.lpstrFile = buffer; browse.nMaxFile = sizeof(buffer); browse.lpstrFilter = "AVI Files\0*.avi\0"; browse.nFilterIndex = 1; browse.lpstrTitle = "Save to AVI File"; browse.lpstrFileTitle = 0; browse.lpstrInitialDir = lastSave.c_str(); browse.lpstrDefExt = "avi"; browse.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_OVERWRITEPROMPT; if (GetSaveFileName(&browse) != 0) { AVIFilename.SetWindowText(buffer); SetAviOptions(); aviwriter->OpenFile(); compressionButton.EnableWindow(TRUE); } }
//------------------------------------------------------------------ // main //------------------------------------------------------------------ void main() { CWinApp* pApp = AfxGetApp(); pApp->InitApplication(); pApp->InitInstance(); pApp->Run(); CMyDoc* pMyDoc = new CMyDoc; CMyView* pMyView = new CMyView; CWnd* pMyWnd = pApp->m_pMainWnd; cout << "pMyDoc->IsKindOf(RUNTIME_CLASS(CMyDoc)) " << pMyDoc->IsKindOf(RUNTIME_CLASS(CMyDoc)) << "\n"; cout << "pMyDoc->IsKindOf(RUNTIME_CLASS(CDocument)) " << pMyDoc->IsKindOf(RUNTIME_CLASS(CDocument)) << "\n"; cout << "pMyDoc->IsKindOf(RUNTIME_CLASS(CCmdTarget)) " << pMyDoc->IsKindOf(RUNTIME_CLASS(CCmdTarget)) << "\n"; cout << "pMyDoc->IsKindOf(RUNTIME_CLASS(CObject)) " << pMyDoc->IsKindOf(RUNTIME_CLASS(CObject)) << "\n"; cout << "pMyDoc->IsKindOf(RUNTIME_CLASS(CWinApp)) " << pMyDoc->IsKindOf(RUNTIME_CLASS(CWinApp)) << "\n"; cout << "pMyDoc->IsKindOf(RUNTIME_CLASS(CView)) " << pMyDoc->IsKindOf(RUNTIME_CLASS(CView)) << "\n"; cout << "pMyView->IsKindOf(RUNTIME_CLASS(CView)) " << pMyView->IsKindOf(RUNTIME_CLASS(CView)) << "\n"; cout << "pMyView->IsKindOf(RUNTIME_CLASS(CObject)) " << pMyView->IsKindOf(RUNTIME_CLASS(CObject)) << "\n"; cout << "pMyView->IsKindOf(RUNTIME_CLASS(CWnd)) " << pMyView->IsKindOf(RUNTIME_CLASS(CWnd)) << "\n"; cout << "pMyView->IsKindOf(RUNTIME_CLASS(CFrameWnd)) " << pMyView->IsKindOf(RUNTIME_CLASS(CFrameWnd)) << "\n"; cout << "pMyWnd->IsKindOf(RUNTIME_CLASS(CFrameWnd)) " << pMyWnd->IsKindOf(RUNTIME_CLASS(CFrameWnd)) << "\n"; cout << "pMyWnd->IsKindOf(RUNTIME_CLASS(CWnd)) " << pMyWnd->IsKindOf(RUNTIME_CLASS(CWnd)) << "\n"; cout << "pMyWnd->IsKindOf(RUNTIME_CLASS(CObject)) " << pMyWnd->IsKindOf(RUNTIME_CLASS(CObject)) << "\n"; cout << "pMyWnd->IsKindOf(RUNTIME_CLASS(CDocument)) " << pMyWnd->IsKindOf(RUNTIME_CLASS(CDocument)) << "\n"; }
LRESULT CFileSendDlg::OnNoThanksFileTransfer (WPARAM wParam, LPARAM lParam) { /* ::EnterCriticalSection(& CFileTransSock::Instance().m_CS); if( (DWORD)m_pSpckObjMap->m_pThreadObj != 0xfeeefeee && (DWORD)m_pSpckObjMap->m_pSockObj != 0xfeeefeee ) { CFileTransSock::Instance().RemoveSocketObj(m_pSpckObjMap->m_pThreadObj, m_pSpckObjMap->m_pSockObj); CFileTransSock::Instance().FreeSocketObj( m_pSpckObjMap->m_pSockObj); CFileTransSock::Instance().RenumberThreadArray(m_pSpckObjMap->m_pThreadObj); //20080707 } ::LeaveCriticalSection(& CFileTransSock::Instance().m_CS); */ shutdown (m_pSpckObjMap->m_pSockObj->s ,SD_BOTH ) ; //closesocket(m_pSpckObjMap->m_pSockObj->s); AfxMessageBox("상대방이 전송을 취소하였습니다."); CWinApp *pApp = AfxGetApp(); CWnd *pMainWnd = pApp->GetMainWnd(); pMainWnd->PostMessage(WM_FILE_SENDDLG_CLOSE, (WPARAM)m_szSockObjID, (LPARAM)0); //CDialog::OnOK(); return TRUE; }
// removes all the items from the history list, and optionally deletes // the registry items. Note that if the history list is generated from // a CRecentFileList, then registry entries will not be deleted void CHistoryCombo::ClearHistory(BOOL bDeleteRegistryEntries/*=TRUE*/) { ResetContent(); if (! m_sSection.IsEmpty() && bDeleteRegistryEntries) { // remove profile entries CWinApp* pApp = AfxGetApp(); ASSERT(pApp); CString sKey; for (int n = 0; n < 1000/* prevent runaway*/; n++) { sKey.Format(KEY_PREFIX_FORMAT, m_sKeyPrefix, n); CString sText = pApp->GetProfileString(m_sSection, sKey); if (sText.IsEmpty()) break; pApp->WriteProfileString(m_sSection, sKey, NULL); // remove entry } if (! m_sKeyCurItem.IsEmpty()) sKey = m_sKeyCurItem; else if (m_sKeyPrefix.IsEmpty()) sKey = _T("Last"); else sKey = m_sKeyPrefix; pApp->WriteProfileString(m_sSection, sKey, NULL); } }
void CXTPSyntaxEditPropertiesPageColor::OnDblClickSchema() { int iIndex = m_lboxName.GetCurSel(); if (iIndex == LB_ERR) return; XTP_EDIT_SCHEMAFILEINFO* pSchemaInfo = (XTP_EDIT_SCHEMAFILEINFO*)m_lboxName.GetItemData(iIndex); if (pSchemaInfo == NULL) return; if (!FILEEXISTS_S(pSchemaInfo->csValue)) return; TCHAR szDrive[_MAX_DRIVE], szDir[_MAX_DIR], szFileName[_MAX_FNAME], szEx[_MAX_EXT]; SPLITPATH_S(pSchemaInfo->csValue, szDrive, szDir, szFileName, szEx); CString csBuffer; XTPResourceManager()->LoadString( &csBuffer, XTP_IDS_EDIT_OPENSCHEMAMSG); CString csMessage; csMessage.Format(csBuffer, szFileName, szEx); if (AfxMessageBox(csMessage, MB_ICONQUESTION | MB_YESNO) == IDYES) { // close the options dialog. CPropertySheet* pWndParent = DYNAMIC_DOWNCAST(CPropertySheet, GetParent()); if (pWndParent) pWndParent->EndDialog(IDCANCEL); // open the document. CWinApp* pWinApp = AfxGetApp(); if (pWinApp) pWinApp->OpenDocumentFile(pSchemaInfo->csValue); } }
void CMainWizard::OnScImportSettings(void) { CString strFilter; CString strTitle; CProcessPrivileges processPrivileges; enum { fdwFlags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST }; strFilter.LoadString(IDS_SETTINGS_FILTER); #if (_MFC_VER < 0x0700) CFileDialogEx dlgOpen(TRUE, _T("hive"), AfxGetAppName(), fdwFlags, strFilter); #else CFileDialog dlgOpen(TRUE, _T("hive"), AfxGetAppName(), fdwFlags, strFilter); #endif // _MFC_VER strTitle.LoadString(IDS_TITLE_IMPORT); dlgOpen.m_ofn.lpstrTitle = strTitle; if (dlgOpen.DoModal() == IDOK) { BeginWaitCursor(); CWinApp* pApp = AfxGetApp(); ASSERT_VALID(pApp); processPrivileges[SE_RESTORE_NAME] = SE_PRIVILEGE_ENABLED; HKEY hAppKey = pApp->GetAppRegistryKey(); ::RegRestoreKey(hAppKey, dlgOpen.GetPathName(), REG_FORCE_RESTORE); ::RegCloseKey(hAppKey); processPrivileges[SE_RESTORE_NAME] = 0; EndWaitCursor(); } }
//--------------------------------------------------------------------------------------------------------------// UINT CChildView::GetProfileInt(LPCTSTR lpszEntry, int nDefault) { UINT nResult = nDefault; CWinApp* pApp = AfxGetApp(); if (pApp) nResult = pApp->GetProfileInt(REG_SECTION_LOG, lpszEntry, nDefault); return nResult; }
void COptionsPage::OnButtonSource(void) { CString strPrompt; strPrompt.LoadString(IDS_CHOOSE_SOURCE); CFolderDialog dlgFolder(strPrompt, m_strSource, this, BIF_NEWDIALOGSTYLE); if (dlgFolder.DoModal() == IDOK) { m_strSource = dlgFolder.GetFolderPath(); SetDlgItemText(IDC_EDIT_SOURCE, m_strSource); #if (_MFC_VER < 0x0700) CWinApp* pApp = AfxGetApp(); ASSERT_VALID(pApp); if ((m_timeWrite = pApp->GetProfileInt(SZ_REGK_TIMES, m_strSource, -1)) != -1) #else CUpdateItApp* pApp = DYNAMIC_DOWNCAST(CUpdateItApp, AfxGetApp()); ASSERT_VALID(pApp); if ((m_timeWrite = pApp->GetProfileTime(SZ_REGK_TIMES, m_strSource, -1)) != -1) #endif // _MFC_VER { m_dtpWrite.SetTime(&m_timeWrite); } CString strDefTarget = m_strSource + _T(".Update"); SetDlgItemText(IDC_EDIT_TARGET, pApp->GetProfileString(SZ_REGK_TARGETS, m_strSource, strDefTarget)); } }
void CLogin::OnBnClickedCheckPrelogins() { // TODO: Add your control notification handler code here // IDC_CHECK_PRELOGINS CButton *cbox = (CButton *)GetDlgItem(IDC_CHECK_PRELOGINS); int n = cbox->GetCheck(); CButton *add_button = (CButton *)GetDlgItem(IDC_LOGIN_NEW); CButton *remove_button = (CButton *)GetDlgItem(IDC_LOGIN_REMOVE); CWinApp* pApp = AfxGetApp(); if(n == 0) /* unchecked */ { m_ListBox.ShowWindow(SW_HIDE); add_button->ShowWindow(SW_HIDE); remove_button->ShowWindow(SW_HIDE); pApp->WriteProfileInt("ShowPreviousLogins", "YesNo", 0); } else { m_ListBox.ShowWindow(SW_SHOW); add_button->ShowWindow(SW_SHOW); remove_button->ShowWindow(SW_SHOW); pApp->WriteProfileInt("ShowPreviousLogins", "YesNo", 1); } }
int main(void) { CWinApp* pApp = AfxGetApp(); pApp->InitApplication(); pApp->InitInstance(); pApp->Run(); CMyDoc* pMyDoc = new CMyDoc; CMyView* pMyView = new CMyView; CFrameWnd* pMyFrame = (CFrameWnd*)pApp->m_pMainWnd; pMyFrame->m_pViewActive = pMyView; pMyView->m_pDocument = pMyDoc; std::cout << std::endl << "pMyFrame received a WM_CREATE, routing path : " << std::endl; AfxWndProc(0, WM_CREATE, 0, 0, pMyFrame); std::cout << std::endl << "pMyView received a WM_COMMAND, routing path : " << std::endl; AfxWndProc(0, WM_COMMAND, 0, 0, pMyView); std::cout << std::endl << "pMyFrame received a WM_COMMAND, routing path : " << std::endl; AfxWndProc(0, WM_COMMAND, 0, 0, pMyFrame); system("pause"); return 0; }
void nPreUtilities::LoadSettings() { SetDefaultSettings(); CWinApp* pApp = AfxGetApp(); bRunWithMinimizedMain = pApp->GetProfileInt("Settings", "RunWithMinimizedMain", bRunWithMinimizedMain); }
//------------------------------------------------------------------------- BOOL MRCWriteProfileBinary(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPVOID pData, DWORD nBufferSize) // Write a binary value into the registry. If the pointer to the buffer // is NULL then the current value is deleted. This can be generally used // for removing any value not just binary ones //------------------------------------------------------------------------- { CWinApp * pApp = AfxGetApp(); ASSERT(pApp != NULL); ASSERT(lpszSection != NULL); ASSERT(lpszEntry != NULL); ASSERT(pApp->m_pszRegistryKey != NULL); // We must be using the registry not // INI files for binary to be supported LONG lRes; HKEY hSecKey = pApp->GetSectionKey(lpszSection); if (hSecKey == NULL) return FALSE; if (pData == NULL) { lRes = ::RegDeleteValue(hSecKey, (LPTSTR)lpszEntry); } else { lRes = RegSetValueEx(hSecKey, lpszEntry, NULL, REG_BINARY, (LPBYTE)pData, nBufferSize); } RegCloseKey(hSecKey); return (lRes == ERROR_SUCCESS) ? TRUE : FALSE; }
BOOL DoInit() { HINSTANCE hInstance = g_Instance; int nReturnCode = -1; CWinThread* pThread = AfxGetThread(); CWinApp* pApp = AfxGetApp(); // AFX internal initialization if (!AfxWinInit(hInstance, NULL, TEXT(""), SW_SHOW)) return DoExit(); // App global initializations (rare) if (pApp != NULL && !pApp->InitApplication()) return DoExit(); // Perform specific initializations if (!pThread->InitInstance()) { if (pThread->m_pMainWnd != NULL) { TRACE(traceAppMsg, 0, "Warning: Destroying non-NULL m_pMainWnd\n"); pThread->m_pMainWnd->DestroyWindow(); } nReturnCode = pThread->ExitInstance(); return DoExit(); } return TRUE; }
//------------------------------------------------------------------------- BOOL MRCGetProfileBinary(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPVOID pData, DWORD nBufferSize) // Read the registry for a binary value. // Various assertions fail if the size of the value does not match that // which is asked for. We can assume that the registry data should always // match the current software. Any conversion required between versions // should have taken place when initializing the app //------------------------------------------------------------------------- { CWinApp * pApp = AfxGetApp(); ASSERT(lpszSection != NULL); ASSERT(lpszEntry != NULL); ASSERT(pApp->m_pszRegistryKey != NULL); // We must be using the registry not INI files //for binary to be supported HKEY hSecKey = pApp->GetSectionKey(lpszSection); if (hSecKey == NULL) return FALSE; DWORD dwType; DWORD dwCount = nBufferSize; LONG lRes = RegQueryValueEx(hSecKey, (LPTSTR)lpszEntry, NULL, (unsigned long *)&dwType, (LPBYTE)pData, (unsigned long *)&dwCount); RegCloseKey(hSecKey); ASSERT(lRes != ERROR_MORE_DATA); // Is Data in the registry larger than the buffer? // We should have converted registry data on start up. if (lRes == ERROR_SUCCESS) { ASSERT(dwType == REG_BINARY); ASSERT(dwCount = nBufferSize); // The data should be the expected size return TRUE; } return FALSE; }
LRESULT CFrameWnd::OnDDEExecute( WPARAM wParam, LPARAM lParam ) /*************************************************************/ { HWND hWndClient = (HWND)wParam; HGLOBAL hMem = (HGLOBAL)lParam; ::PostMessage( hWndClient, WM_DDE_ACK, (WPARAM)m_hWnd, MAKELPARAM( 0x8000, hMem ) ); CString str; LPVOID lpMem = ::GlobalLock( hMem ); #ifdef _UNICODE if( !::IsWindowUnicode( hWndClient ) ) { str = (LPCSTR)lpMem; } else { #endif str = (LPCTSTR)lpMem; #ifdef _UNICODE } #endif ::GlobalUnlock( hMem ); CWinApp *pApp = AfxGetApp(); ASSERT( pApp != NULL ); LPTSTR lpszCommand = str.GetBuffer(); pApp->OnDDECommand( lpszCommand ); str.ReleaseBuffer(); return( 0L ); }
// 在 Frame中发消息给View U32 CPluginApp_i::SendMessageToView(UINT ulMsg, WPARAM wParam, LPARAM lParam) { CWinApp* pWinApp = AfxGetApp(); if(pWinApp) { POSITION DocTemplatePos = pWinApp->GetFirstDocTemplatePosition(); //while(DocTemplatePos) { CMultiDocTemplate* pDocTemp = (CMultiDocTemplate*)pWinApp->GetNextDocTemplate(DocTemplatePos); // POSITION pos = pDocTemp->GetFirstDocPosition (); // Find the doc within the same doctemplate. while (pos) { CDocument* pDoc = pDocTemp->GetNextDoc (pos); POSITION ViewPos = pDoc->GetFirstViewPosition (); CView* pView = pDoc->GetNextView (ViewPos); if(pView) { CMDIChildWnd* pFrame = (CMDIChildWnd*)pView->GetParentFrame(); if(pFrame == this) { //OutputDebugString("Find!\n"); pView->SendMessage(ulMsg, wParam, lParam); } } } } } return 0; }
//------------------------------------------------------------------ // main //------------------------------------------------------------------ void main() { CWinApp* pApp = AfxGetApp(); pApp->InitApplication(); pApp->InitInstance(); pApp->Run(); CMyDoc* pMyDoc = new CMyDoc; CMyView* pMyView = new CMyView; CFrameWnd* pMyFrame = (CFrameWnd*)pApp->m_pMainWnd; // output Message Map construction AFX_MSGMAP* pMessageMap = pMyView->GetMessageMap(); cout << endl << "CMyView Message Map : " << endl; MsgMapPrinting(pMessageMap); pMessageMap = pMyDoc->GetMessageMap(); cout << endl << "CMyDoc Message Map : " << endl; MsgMapPrinting(pMessageMap); pMessageMap = pMyFrame->GetMessageMap(); cout << endl << "CMyFrameWnd Message Map : " << endl; MsgMapPrinting(pMessageMap); pMessageMap = pApp->GetMessageMap(); cout << endl << "CMyWinApp Message Map : " << endl; MsgMapPrinting(pMessageMap); }
///////////////////////////////////////////////////////////////////////////// // Create font from info in the application profile. Reads info in the form // facename, ptsize, weight, italic // zBOOL ZFontUI::GetProfileFont( zCPCHAR cpcKey, zCPCHAR cpcVal, CFont& font, CDC *pDC ) { CWinApp *pApp = AfxGetApp( ); ASSERT_VALID( pApp ); CString zs = pApp->GetProfileString( cpcKey, cpcVal ); if ( zs.IsEmpty( ) ) return( FALSE ); LOGFONT lf; zmemset( &lf, 0, sizeof( LOGFONT ) ); lf.lfCharSet = DEFAULT_CHARSET; int bItalic; int nPtSize; // scanf is overkill, but I'm lazy if ( sscanf( (zCPCHAR) zs, "%[a-zA-Z ],%d,%d,%d", lf.lfFaceName, &nPtSize, &lf.lfWeight, &bItalic ) != 4 ) { return( FALSE ); } lf.lfHeight = MulDiv( -nPtSize, // convert ptsize to logical units ::GetDeviceCaps( pDC ? pDC->m_hDC : ::GetDC( 0 ), LOGPIXELSY ), 72 ); lf.lfItalic = bItalic; // because lf.lfItalic is a BYTE font.DeleteObject( ); // bye return( font.CreateFontIndirect( &lf ) ); }
virtual void ProcessGUIMessages() { // Adapted from MFC's CWinThread::Run() (thrdcore.cpp). _AFX_THREAD_STATE* pState = AfxGetThreadState(); CWinApp* pApp = AfxGetApp(); BOOL bIdle = TRUE; LONG lIdleCount = 0; // phase1: check to see if we can do idle work while (bIdle && !::PeekMessage(&pState->m_msgCur, NULL, NULL, NULL, PM_NOREMOVE)) { // call OnIdle while in bIdle state if (!pApp->OnIdle(lIdleCount++)) bIdle = FALSE; // assume "no idle" state } // phase2: pump messages while available while (::PeekMessage(&pState->m_msgCur, NULL, NULL, NULL, PM_NOREMOVE)) { // pump message, but quit on WM_QUIT if (!pApp->PumpMessage()) { Terminate(); pApp->ExitInstance(); } } ::Sleep(0); }
//--------------------------------------------------------------------------------------------------------------// BOOL CChildView::WriteProfileInt(LPCTSTR lpszEntry, int nValue) { BOOL bOk = FALSE; CWinApp* pApp = AfxGetApp(); if (pApp) bOk = pApp->WriteProfileInt(REG_SECTION_LOG, lpszEntry, nValue); return bOk; }
// @pymethod |PyCWinApp|OpenDocumentFile|Opens a document file by name. static PyObject * ui_open_document_file(PyObject *self, PyObject *args) { TCHAR *fileName; PyObject *obfileName; if (!PyArg_ParseTuple(args, "O:OpenDocumentFile", &obfileName )) // @pyparm string|fileName||The name of the document to open. return NULL; if (!PyWinObject_AsTCHAR(obfileName, &fileName)) return NULL; CWinApp *pApp = GetApp(); if (!pApp) return NULL; if (((CProtectedWinApp *)pApp)->GetMainFrame()->GetSafeHwnd()==0) RETURN_ERR("There is no main frame in which to create the document"); GUI_BGN_SAVE; CDocument *pDoc = pApp->OpenDocumentFile(fileName); GUI_END_SAVE; PyWinObject_FreeTCHAR(fileName); if (PyErr_Occurred()) return NULL; if (pDoc==NULL) RETURN_NONE; return ui_assoc_object::make(PyCDocument::type, pDoc)->GetGoodRet(); }
void CRegisterDlg::OnOK() { CMD5 crypt; CString strTemp; UpdateData(); m_strName.TrimLeft(); m_strName.TrimRight(); m_strKey.TrimLeft(); m_strKey.TrimRight(); strTemp = m_strName.Left(32); strTemp += MD5_HASH_KEY; crypt.setPlainText(strTemp); if (!m_strKey.Compare(crypt.getMD5Digest())) { CWinApp* pApp = AfxGetApp(); UpdateData(); pApp->WriteProfileString("Options", "Name", m_strName); pApp->WriteProfileString("Options", "Key", m_strKey); MessageBox("Registration key accepted! Thank you for registering.", "Success"); } else { MessageBox("Invalid registration key. Please try again.", "Error"); return; } CDialog::OnOK(); }