|
You need to offset the rectangle into which you're blitting by m_nScrollPos.
So, something like:
BitBlt(dc.m_hDC,70,180,rect.right,rect.bottom,memdc,0,0,SRCCOPY);
would become something like
BitBlt(dc.m_hDC,70,180-m_nScrollPos,rect.right,rect.bottom-m_nScrollPos,memdc,0,0,SRCCOPY);
Also - I don't think you should be using rect.bottom - that should be m_rcOriginalRect.bottom - you want to blit the images to fit into the original window size, not the current window size?
I've replicated your problem, anyway, before using this to fix it. Here's my paint code. I use CImage objects to hold the image (CImage isn't available in VC6 before you ask) and CRect s to hold sizes. baseSize_ is equivalent to your m_OriginalHeight , while offset_ contains the current scroll position. The images are being blitted to each fill half of the original window size. This code works, anyway.
PAINTSTRUCT ps;
CDC* paintDC = BeginPaint(&ps);
CRect rcImage1(baseSize_);
rcImage1.bottom /= 2;
CRect rcImage2;
rcImage2.SubtractRect(baseSize_, rcImage1);
rcImage1.OffsetRect(-offset_);
rcImage2.OffsetRect(-offset_);
image1_.StretchBlt(*paintDC, rcImage1, SRCCOPY);
image2_.StretchBlt(*paintDC, rcImage2, SRCCOPY);
EndPaint(&ps);
HTH!!!
|
|
|
|
|
Hi Stuart,
I am not able to understand the code snippet what you have given,Can you please explain me clearly..?
Thanks
Venkatesh.
|
|
|
|
|
PAINTSTRUCT ps;
CDC* paintDC = BeginPaint(&ps);
CRect rcImage1(baseSize_);
rcImage1.bottom /= 2;
CRect rcImage2;
rcImage2.SubtractRect(baseSize_, rcImage1);
rcImage1.OffsetRect(-offset_);
rcImage2.OffsetRect(-offset_);
image1_.StretchBlt(*paintDC, rcImage1, SRCCOPY);
image2_.StretchBlt(*paintDC, rcImage2, SRCCOPY);
EndPaint(&ps);
It's a lot neater when you use utility classes like CRect and CPoint rather than just using int s - and this approach would be easy to generalise to the case where you have a horizontal scrollbar as well.
|
|
|
|
|
Hi Stuart,
Thanks a lot for provide me the code snippet with neat explanation. But still i have small doubt.
what is this baseSize_..? What data i have pass to this variable..?
what is -offset_..? and offset_ ..?how to declare this variables..?
and my images are in one location, how to pass that location information to these image variables..?
Can you please give me answer for my questions..?
Thanks in advance..
Thanks
Venkatesh.
|
|
|
|
|
As I said in my earlier message:
Stuart Dootson wrote: baseSize_ is equivalent to your m_OriginalHeight, while offset_ contains the current scroll position
You already have these variables, just with different names.
-offset_ ? As I said, offset_ is a CPoint - read the MFC documentation! What do you think -offset_ might mean....
venki502 wrote: my images are in one location, how to pass that location information to these image variables
No idea what you mean by that.
|
|
|
|
|
Hi Stuart,
Thanks for your patience, please don't mind any thing, because i am new to this environment, that's the reason i am posing more questions.
As i told you, i need to display bitmap images on dialog box.
I have images on C:\, now i need to display images from there..
image1_.StretchBlt(*paintDC, rcImage1, SRCCOPY);
image2_.StretchBlt(*paintDC, rcImage2, SRCCOPY);
Current i am working in VC6.0 version. As u mentioned in prevoius forum that CImage is not available in VC6.0.
Now how i have to give the path to these two variables.
Thanks in advance.
Thanks
Venkatesh.
|
|
|
|
|
You already had the image loading code - that's fine. The BitBlt calls were fine as well - you just need to unpack the rcImagen members into the appropriate parameters - here's how with rcImage1 :
m_ifilename2 = "C:\\Venkatesh\\Sample1.bmp";
m_Bmap=(HBITMAP)::LoadImage(NULL,m_ifilename2,IMAGE_BITMAP,600,39,LR_LOADFROMFILE | LR_DEFAULTSIZE) ;
memdc=::CreateCompatibleDC(dc.m_hDC);
::SelectObject(memdc,m_Bmap);
BitBlt(dc.m_hDC,rcImage.left,rcImage1.top,rcImage1.right,rcImage1.bottom,memdc,0,0,SRCCOPY);
|
|
|
|
|
Hi Stuart,
Thanks for you quick response on this.. Based on your suggestions i am using below code snippet in my application.
I have written this code in OnPaint function.
CPaintDC dc(this); // device context for painting
PAINTSTRUCT ps;
CDC* paintDC = BeginPaint(&ps);
CRect rcImage1(baseSize_t);
rcImage1.bottom /= 2;
CRect rcImage2;
rcImage2.SubtractRect(baseSize_t, rcImage1);
rcImage1.OffsetRect(-offset_);
rcImage2.OffsetRect(-offset_);
HBITMAP m_Bmap;
HDC memdc;
CString m_ifilename1,m_ifilename2;
m_ifilename2 = "C:\\Venkatesh\\Sample1.bmp";
m_Bmap=(HBITMAP)::LoadImage(NULL,m_ifilename2,IMAGE_BITMAP,600,39,LR_LOADFROMFILE | LR_DEFAULTSIZE) ;
memdc=::CreateCompatibleDC(dc.m_hDC);
::SelectObject(memdc,m_Bmap);
BitBlt(dc.m_hDC,rcImage1.left,rcImage1.top,rcImage1.right,rcImage1.bottom,memdc,0,0,SRCCOPY);
DeleteObject(m_Bmap);
DeleteObject(memdc);
I have declared two variables like below mentioned way:
CRect baseSize_t;
CPoint offset_;
I have assigned baseSize_t like baseSize_t = m_rcOriginalRect;
Now i able to compile this program successfully. But i am not able to get any image on the dialog box. So immediately i have debugged the app and came to know that rcImage1 and rcImage 2 are containing some garbage values like this:-
rcImage1 :- top = 842150480,bottom=84215089,left=842150454,right=842151261.
the same thing happened for rcImage2 also...
Based on above code can you please tell me, where i did wrong..?
Thanks
Venkatesh.
|
|
|
|
|
venki502 wrote: I have assigned baseSize_t like baseSize_t = m_rcOriginalRect;
Have you checked its value looks OK? What about offset_ - what have you set that to?
|
|
|
|
|
Hi stuart,
Yes the value of baseSize_t looks like ok..
below I am providing the value of that variable: -
top = 29,bottom=716,left=3,right=810.
i haven't set any value to offset_t variable.
what should i do..?
Thanks in advance...
Thanks
Venkatesh.
|
|
|
|
|
That'll be the problem. Set offset_.x to 0, offset_.y to the scroll bar position - you called it m_nScrollPos . I'd recommend using and updating offset_.y rather than m_nScrollPos , although you could just put thi in your OnPaint :
CPoint offset_(0, m_nScrollPos);
|
|
|
|
|
Hi Stuart,
I just did this and ran my app, but still no progress. I am facing with the same problem. When i scroll down, the image is getting erasing.
Can you please tell where i am going wrong..? Or Give me your email id, i will mail you my exe file, so that you can understand my problem easily... Please kindly help me in this because it is very urgent requirement for me..
Thanks in advance...
Thanks
Venkatesh.
|
|
|
|
|
Seems to me you're not setting offset_ correctly. That's the problem you've had from the start - offsetting the images correctly.
I'll post my files tomorrow when I'm at work - that's where they are, not here at home.
|
|
|
|
|
OK - as I promised, here's my code (or at least the relevant bits of it).
Here's the relevant bits of the dialog class declaration:
class CaaaDlg : public CDialog
{
public:
protected:
private:
void OnResized();
CImage image1_;
CImage image2_;
CRect baseSize_;
CPoint offset_;
};
And the relevant (bits of) the method implementations:
CaaaDlg::CaaaDlg(CWnd* pParent )
: CDialog(CaaaDlg::IDD, pParent),
offset_(0, 0)
{
image1_.Load(path to image 1);
image2_.Load(path to image 1);
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CaaaDlg::OnPaint()
{
if (IsIconic())
{
}
else
{
PAINTSTRUCT ps;
CDC* paintDC = BeginPaint(&ps);
CRect rcImage1(baseSize_);
rcImage1.bottom /= 2;
CRect rcImage2;
rcImage2.SubtractRect(baseSize_, rcImage1);
rcImage1.OffsetRect(-offset_);
rcImage2.OffsetRect(-offset_);
image1_.StretchBlt(*paintDC, rcImage1, SRCCOPY);
image2_.StretchBlt(*paintDC, rcImage2, SRCCOPY);
EndPaint(&ps);
}
}
void CaaaDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
SCROLLINFO si = { sizeof(si), 0 };
GetScrollInfo(SB_VERT, &si, SIF_ALL);
CPoint newOffset(offset_);
switch (nSBCode)
{
case SB_LINEDOWN:
newOffset.y += si.nPage / 10;
break;
case SB_LINEUP:
newOffset.y -= si.nPage / 10;
break;
case SB_PAGEDOWN:
newOffset.y += si.nPage;
break;
case SB_THUMBTRACK:
case SB_THUMBPOSITION:
newOffset.y = nPos;
break;
case SB_PAGEUP:
newOffset.y -= si.nPage;
break;
default:
return;
}
CRect currSize;
GetClientRect(&currSize);
const int maxOffset = baseSize_.Height() - currSize.Height();
newOffset.y = max(min(newOffset.y, maxOffset), 0);
SetScrollPos(SB_VERT,newOffset.y,TRUE);
ScrollWindow(0,offset_.y-newOffset.y);
offset_ = newOffset;
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}
void CaaaDlg::OnResized()
{
CRect currSize;
GetClientRect(&currSize);
SCROLLINFO si;
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_DISABLENOSCROLL|SIF_ALL;
si.nMin = 0;
si.nMax = baseSize_.Height()-1;
si.nPage = currSize.Height();
CPoint oldOffset(offset_);
if(offset_.y + si.nPage > baseSize_.Height()) offset_.y = baseSize_.Height() - si.nPage;
if(offset_.y < 0) offset_.y = 0;
si.nTrackPos = si.nPos = offset_.y;
SetScrollInfo(SB_VERT, &si, TRUE);
if (oldOffset != offset_)
{
SetScrollPos(SB_VERT,offset_.y,TRUE);
ScrollWindow(0,oldOffset.y-offset_.y);
}
}
|
|
|
|
|
Hi Stuart,
Your code snippet answered my question, ... what a brillant coding...
Thank you very much for helping me regarding this..
I am very happy now.. thanks a lot for your help and your patience...
You are Rock
Thanks
Venkatesh.
|
|
|
|
|
Hi Stuart,
With the help of your example code, i am able to draw 10 images on dialog box, now what i want is i am not able to identify the pixels for creating checkboxes.
i want one check box for each image...
Can you please tell me how i have to proceed for creating check box....
please help me regarding this case also....
Thanks
Venkatesh.
|
|
|
|
|
CreateWindow with a class of BUTTON and window style including BS_CHECKBOX , one for each image.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi Stuart,
I am creating the check box dynamically using below code snippet,
CButton *check_box; // I have delared the variable in header file
////In OnPaint function i am writing below code
check_box = new CButton;
check_box->Create("Venkatesh",WS_CHILD | WS_VISIBLE|BS_AUTOCHECKBOX|BS_LEFTTEXT,
CRect(rcImage2.left,rcImage2.top,rcImage2.right,rcImage2.bottom),this,0x11);
I want to know how to specify the rectange parameters in this function..
Please let me know, so that i will go ahead...
Thanks
Venkatesh.
|
|
|
|
|
venki502 wrote: I want to know how to specify the rectange parameters in this function..
The values for the rectangle? Damn, I don't know - depends where you want to put it.
All I know is that you don't need to offset them by the scroll position like you did with the images.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi Stuart,
Yes, i did that, i have given below rectangle pixels at the time of creation. CRect(277,175,365,200).
I want to create check box in that location, but initially i am able to get that on my dialog, next when i scroll down it is getting erasing..
The same problem, earlier i have faced with the images.
today i have tried to set the pixels just like what we did for the images. but its' not working..
Can you please suggest me the right way to do this..?
Thanks in advance...
Thanks
Venkatesh
|
|
|
|
|
Hmmm - this worked fine for me:
- Create the check boxes in
OnInitDialog :
CRect rcCheck1(baseSize_);
rcCheck1.bottom /= 2;
CRect rcCheck2;
rcCheck2.SubtractRect(baseSize_, rcCheck1);
rcCheck1.left = rcCheck1.right - 100;
rcCheck2.left = rcCheck2.right - 100;
check1_.Create(_T("1"), WS_CHILD|WS_VISIBLE|BS_CHECKBOX, rcCheck1, this, 101);
check2_.Create(_T("2"), WS_CHILD|WS_VISIBLE|BS_CHECKBOX, rcCheck2, this, 102);
- Draw the images 100 pixels narrower (as I've made the checkboxes 100 pixels wide). I added the following two lines in
OnPaint right before the OffsetRect method calls to do that:
rcImage1.right -=100;
rcImage2.right -=100;
Oh, and check1_ and check2_ are members of the dialog class, of type CButton .
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi Stuart,
Thanks for valuable information on this.... I have tried the same thing in my application, it is working fine.
With the help your example code i have created one slider bar, and using MCI functions i trying to play the call. I am able to play the call, but the slider bar is not moving.
Can you please let me know why i am not able to get that..
Please help me regarding this also..
Thanks in advance..
Thanks
Venkatesh.
|
|
|
|
|
Never used MCI, got no idea, sorry.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi Stuart,
I need one more small help regarding line creation on images. I am able to get images and check boxes on dialog box. Now i want to create one horizontal line on images. I have tried with the same logic which i have used for images and check boxes.
But if i moved vertical scroll bar down, then the line is also moving and getting erasing..
Can you please help me out in this regards, because this is last component of my application.
Thanks in advance..
Thanks
Venkatesh.
|
|
|
|
|
venki502 wrote: one horizontal line on images
How you doing that?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|