SetWindowPos() doesn't work properly in windows7/8

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<p style="margin-bottom:0.0001pt <span style="font-size:small <span style="line-height:normal I am trying to save an image(main window) as jpeg.i open a file dialog to set the file name.so i set main window as a parent window.Here is the code for that.
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New CExportImage exportDlg(NULL, this);
<p style="margin-bottom:0.0001pt; line-height:normal
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New; color:blue if <span style="font-size:10pt; font-family:Courier New ( exportDlg.DoModal() == IDOK )
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New {
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New exportDlg.doExport();
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New }
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New CExportImage::CExportImage(CWnd* pParent, CWnd* pParentWnd)
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New : CFileDialog(FALSE)
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New {
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New CTabCtrl *pTab=theMainFrame->GetTabCtrl();
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New <span style="color:blue int iStartPage = pTab->GetCurSel() + 1;
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New <span style="color:green //{{AFX_DATA_INIT(CExportImage)
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New m_rangeType = 1; <span style="color:green //
use range, not all as default.
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New m_endPage = iStartPage; <span style="color:green // set the range to the cur page.
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New m_startPage = iStartPage; <span style="color:green // ..
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New m_qualitySlider = 75;
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New <span style="color:green //}}AFX_DATA_INIT
<p style="margin-bottom:0.0001pt; line-height:normal
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New m_qualitySlider = gLastJpgQuality;
<p style="margin-bottom:0.0001pt; line-height:normal
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New TCHAR filterFmt[]=_NO_NO(<span style="color:#a31515 "JPEG %s (*.JPG)|*.JPG|DIB %s (*.DIB)|*.DIB||");
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New <span style="color:blue static TCHAR filter[100];
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New _stprintf(filter,filterFmt,CResString(IDS_STRING1205),CResString(IDS_STRING1205));
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New AddNulls(filter);
<p style="margin-bottom:0.0001pt; line-height:normal
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New <span style="color:blue static TCHAR fileName[_MAX_PATH];
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New _tcscpy(fileName, (LPCTSTR)sLastImageTemplate);
<p style="margin-bottom:0.0001pt; line-height:normal
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New; color:green // m_ofn.hwndOwner = pParentWnd->m_hWnd;
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New m_ofn.hwndOwner = (pParentWnd==NULL) ? NULL : pParentWnd->m_hWnd;
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New m_ofn.lpstrFilter = filter;
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New ............................
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New .....................
<span style="font-size:10pt; line-height:14px; font-family:Courier New }
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New After DoModal(), i am trying to export the image(main window).Here is the code for that.
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:small The problem is, the file dialog exists in my JPG Image along with the mainwindow.i am using <span style="font-family:Courier New; font-size:13px exportDlg.DoModal()
== IDOK. After this condition i am trying to export the image. <span style="font-family:Courier New; font-size:13px i have used the following code to set the main window as top
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-family:Courier New; font-size:13px theMainFrame->SetWindowPos(&CWnd::wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW); <span style="font-size:small
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New Can anyone help me to solve this problem? Thanks in advance.It happens only in windows 7/8
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New BOOL CExportImage::doExport()
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New {
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New <span style="color:green // Save the current page
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New CTabCtrl *pTab=theMainFrame->GetTabCtrl();
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New <span style="color:blue int iStartPage = pTab->GetCurSel();
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New RECT rect, botRect;
<p style="margin-bottom:0.0001pt; line-height:normal
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New CString sTemplate = m_strUserPathName;
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New sTemplate.MakeUpper();
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New sTemplate.TrimRight(); <span style="color:green // remove any trailing whitespace
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New TCHAR drive[_MAX_DRIVE];
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New TCHAR dir[_MAX_DIR];
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New TCHAR name[_MAX_FNAME];
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New TCHAR ext[_MAX_EXT];
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New _tsplitpath(sTemplate, drive, dir, name, ext);
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New CString sExtTmp = ext;
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New <span style="color:blue if ( sExtTmp == _NO_NO(<span style="color:#a31515 ".JPG") ||
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New sExtTmp == _NO_NO(<span style="color:#a31515 ".DIB") )
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New {
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New sTemplate = drive;
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New sTemplate += dir;
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New sTemplate += name;
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New }<span style="font-family:Courier New; font-size:10pt
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New <span style="color:blue for ( <span style="color:blue int iCurPage = m_startPage; iCurPage<=m_endPage;
iCurPage++ )
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New {
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New <span style="color:green // switch to the page to be printed.
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New pTab->SetCurSel(iCurPage-1);
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New theMainFrame->OnUpdatePage(UPDATE_PAGENO);
<p style="margin-bottom:0.0001pt; line-height:normal
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New <span style="color:green // Capture the window to a bitmap.
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New COXScreenGrabber ScreenGrabber;
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New CWnd m_wndMDIClient;
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New m_wndMDIClient.Attach(theMainFrame->m_hWndMDIClient);
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New <span style="color:green // Get the rectangle of the Graph area.
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New m_wndMDIClient.GetWindowRect(&rect);
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New <span style="color:green // Get the rectangle of the frame.
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New theMainFrame->GetWindowRect(&botRect);
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New <span style="color:green // extend our capture rectangle to the bottom of
the frame.
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New rect.bottom=botRect.bottom;
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New theMainFrame->SetWindowPos(&CWnd::wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New ScreenGrabber.GrabRectangle(rect);
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New COXDIB* pDib = ScreenGrabber.GetGrabDIB();
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New theMainFrame->SetWindowPos(&CWnd::wndNoTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New m_wndMDIClient.Detach();
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New <span style="white-space:pre ………………………………………..
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New <span style="white-space:pre ………………………………………..
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:10pt; font-family:Courier New <br/>


View the full article
 
Back
Top