问题描述
我现在使用以下代码移动窗口并绘制背景窗口,当我将窗口移动到屏幕边缘时,应用程序的背景(位图类型的图片)受到干扰.如何解决此问题? lang ="c ++"> void CDemoDlg :: OnLButtonDown(UINT nFlags,CPoint点){// TODO:在此处添加消息处理程序代码和/或调用默认值创建myRect;GetWindowRect(& myRect); // 保存当前光标坐标GetCursorPos(& point);// ScreenToClient(& point); SendMessage(WM_NCLBUTTONDOWN,HTCAPTION, 0 ); __ super :: OnLButtonDown(nFlags,point);} 无效 CDemoDlg :: OnMouseMove(UINT nFlags,CPoint点){// TODO:在此处添加消息处理程序代码和/或调用默认值创建myRect;GetWindowRect(& myRect);CPoint固化点;GetCursorPos(& curpoint); { MoveWindow(curpoint.x-point.x,curpoint.y-point.y,myRect.right-myRect.left,myRect.bottom-myRect.top,TRUE); } __ super :: OnMouseMove(nFlags,point);}无效 CDemoDlg :: OnPaint(){如果(IsIconic()){CPaintDC dc(此); // 用于绘画的设备上下文SendMessage(WM_ICONERASEBKGND,(WPARAM)dc.GetSafeHdc(), 0 );// 客户端矩形中的中心图标 int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON);CRect rect;GetClientRect(& rect); int x =(rect.Width()-cxIcon + 1 )/ 2 ; int y =(rect.Height()-cyIcon + 1 )/ 2 ;// 绘制图标dc.DrawIcon(x,y,m_hIcon);}其他{CPaintDC dc(此);CRect rect;GetClientRect(& rect);// ScreenToClient(rect); 位图bmp;HBITMAP hBmp = :: LoadBitmap(:: AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_MAIN_BG));:: GetObject(hBmp, sizeof (bmp),& bmp);HDC hDC = :: CreateCompatibleDC(NULL);SelectObject(hDC,hBmp);:: BitBlt(dc.m_hDC, 0 , 0 ,rect.Width(),rect.Height( ),hDC, 0 , 0 ,SRCCOPY);CDialog :: OnPaint();}}
当我使用鼠标事件将应用程序移出屏幕限制"之外时,这会引起问题.如何停止超出屏幕限制的应用程序边缘.
I have used the following codes to move window and paint the background window now when I move window to edges of the screen the background of my application which is a picture of bitmap type gets disturbed.How to solve this problem?
void CDemoDlg::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CRect myRect; GetWindowRect(&myRect); //save current cursor coordinate GetCursorPos(&point); //ScreenToClient(&point); SendMessage(WM_NCLBUTTONDOWN, HTCAPTION, 0); __super::OnLButtonDown(nFlags, point); } void CDemoDlg::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CRect myRect; GetWindowRect( &myRect); CPoint curpoint; GetCursorPos(&curpoint); { MoveWindow(curpoint.x - point.x, curpoint.y - point.y, myRect.right - myRect.left, myRect.bottom - myRect.top, TRUE); } __super::OnMouseMove(nFlags, point); } void CDemoDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CPaintDC dc(this); CRect rect; GetClientRect(&rect); //ScreenToClient(rect); BITMAP bmp; HBITMAP hBmp = ::LoadBitmap(::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_MAIN_BG)); ::GetObject(hBmp, sizeof(bmp), &bmp); HDC hDC = ::CreateCompatibleDC(NULL); SelectObject(hDC, hBmp); ::BitBlt(dc.m_hDC, 0, 0, rect.Width(), rect.Height(), hDC, 0, 0, SRCCOPY); CDialog::OnPaint(); } }
Its causing problem when I move the app with mouse event out side the screen Limits. How can I stop the app edges crossing the screen limits.
这篇关于尝试将应用程序边缘移动到屏幕限制之外时,如何停止移动它的边缘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!