-
March 23rd, 2014, 04:56 AM
#16
Re: Displaying a jpeg image
Hi,
I checked the file name again and i found that i was making mistake in the extension.
D:\>dir images
Volume in drive D has no label.
Volume Serial Number is 8E4F-05BE
Directory of D:\images
03/21/2014 10:12 PM <DIR> .
03/21/2014 10:12 PM <DIR> ..
03/13/2014 02:21 PM 9,634 after_cut2.jpg
1 File(s) 9,634 bytes
2 Dir(s) 512,298,229,760 bytes free
D:\>
Code:
void CRotateImageScrollView::OnDraw(CDC* pDC)
{
CRotateImageScrollDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
CString szStr,szstr1;
szStr= "D:\\images\\after_cut2.jpg";
HRESULT hr=img.Load(szStr);
CRect m_ShowDRect;
m_ShowDRect=CRect(0,0,img.GetWidth(),img.GetHeight());
SetScrollSizes(MM_TEXT,CSize(img.GetWidth(),img.GetHeight()));
img.Draw(pDC->m_hDC,CRect(&m_ShowDRect));
// TODO: add draw code for native data here
}
void CRotateImageScrollView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
Invalidate();
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
}
Thanks for solving this difficult problem. Sorry for taking your time. If I do not write call Invalidate() in OnInitialUpdate(), it would give Debug Assertion Failed message again.
Zulfi.
Last edited by Zulfi Khan2; March 23rd, 2014 at 05:06 AM.
-
March 23rd, 2014, 05:11 AM
#17
Re: [RESOLVED] Displaying a jpeg image
Hi,
Still I am getting "Debug Assertion Failed" message. If I minimize the output window and then display it again. Kindly guide me. This problem is not yet solved.
Zulfi.
Last edited by Zulfi Khan2; March 23rd, 2014 at 05:43 AM.
-
March 23rd, 2014, 05:48 AM
#18
Re: [RESOLVED] Displaying a jpeg image
Originally Posted by Zulfi Khan2
If I do not write call Invalidate() in OnInitialUpdate(), it would give Debug Assertion Failed message again.
What does Invalidate have to do with the assertion?
What exactly is on the line (and around it) where the assertion failed?
I also have to repeat my following question:
Originally Posted by VictorN
Besides, why do you call it in OnDraw handler? The same question - about loading an image. Why not to do it once somewhere in OnInitialUpdate?
Victor Nijegorodov
-
March 23rd, 2014, 06:09 AM
#19
Re: [RESOLVED] Displaying a jpeg image
Hi,
Actually,
for Question:
why do you call it in OnDraw handler?
I dont have any obligation to use OnDraw(). I just want to display image but OnInitialUpdate doesnt have CDC*.
I would say:
You must draw only in response to WM_PAINT message that means (for CView derived classes) - withiin OnDraw() method.
Even though its not CView derived class, when i wrote this code in OnInitialUpdate() i wont get pDC (i.e CDC* pDC). So i declared the variable (CDC* pDC) and I wrote this whole code in OnInitialUpdate( ) but its not even showing the output window when i click Debug->start without debugging.
What Invalidate has to do with Assertion??
I am just guessing b/c when view changes it calls OnInitialupdate and the Invalidate code calls OnDraw(...)
What exactly is on the line (and around it) where the assertion failed?
I hope this is your answer:
\VCProg\VC2008\RotateImageScroll\Debug\RotateImageScroll.exe
File: c:\program files (x86) \ microsoft visual Studio 9.0\vc\atlmfc\include\atlImage.h
Expression: m_hBitmap==0
I have even tried by commenting SetScrollSizes (in OnDraw) method in code in previous post. (#16)
Kindly guide me.
Zulfi.
Last edited by Zulfi Khan2; March 23rd, 2014 at 06:29 AM.
-
March 23rd, 2014, 08:03 AM
#20
Re: [RESOLVED] Displaying a jpeg image
Originally Posted by Zulfi Khan2
I dont have any obligation to use OnDraw(). I just want to display image but OnInitialUpdate doesnt have CDC*.
...
Even though its not CView derived class, when i wrote this code in OnInitialUpdate() i wont get pDC (i.e CDC* pDC). So i declared the variable (CDC* pDC) and I wrote this whole code in OnInitialUpdate( )
You do have the "obligation to use OnDraw()". It is by design. It is how Windows application works.
OnInitialUpdate is (how its name sounds) for initialisation, not for drawing. Besides, using any wrong or uninitialized or absent DC (your pDC was set to NULL) is wrong!
Originally Posted by Zulfi Khan2
...its not even showing the output window when i click Debug->start without debugging.
Why do you "start without debugging"? You have to debug, so, please start with debugging!
Originally Posted by Zulfi Khan2
I am just guessing b/c when view changes it calls OnInitialupdate and the Invalidate code calls OnDraw(...)
OnInitialupdate is called not when view changes but when view has been created before displaying it.
And yes, Invalidate causes window to be redrawn. But it is called by the framework before displaying the view, so you do NOT need to call it from OnInitialupdate.
Originally Posted by Zulfi Khan2
I hope this is your answer:
\VCProg\VC2008\RotateImageScroll\Debug\RotateImageScroll.exe
File: c:\program files (x86) \ microsoft visual Studio 9.0\vc\atlmfc\include\atlImage.h
Expression: m_hBitmap==0
It means, I guess, that the bitmap handle (m_hBitmap member of CImage class) is supposed to be NULL, but it is not.
The problem appears to be because you load the image every time the OnDraw is called without destroyng the existent one. Besides, you produces the resource leaks!
Therefore I suggested you to load the image only once - in OnInitialupdate.
Originally Posted by Zulfi Khan2
I have even tried by commenting SetScrollSizes (in OnDraw) method in code in previous post. (#16)
SetScrollSizes has nothing to do with your problems.
Dear Zulfi Khan,
as Igor already wrote you, now there "is time for you to get back to school bench and learn C++ basics".
I'd also recommend you to download the MFC sample SCRIBBLE, debug it to see and learn how it works!
Victor Nijegorodov
-
March 23rd, 2014, 08:58 AM
#21
Re: [RESOLVED] Displaying a jpeg image
Hi,
Thanks. Its working now. These are very difficult concepts. No teacher can tell me. Only professional people like you can provide me insight. I would download the Scribble stuff but I am more interested in Computer Graphics content.
Code:
void CRotateImageScrollView::OnDraw(CDC* pDC)
{
CRotateImageScrollDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
CString szStr,szstr1;
CRect m_ShowDRect;
m_ShowDRect=CRect(0,0,img.GetWidth(),img.GetHeight());
//SetScrollSizes(MM_TEXT,CSize(img.GetWidth(),img.GetHeight()));
img.Draw(pDC->m_hDC,CRect(&m_ShowDRect));
// TODO: add draw code for native data here
}
void CRotateImageScrollView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CString szStr;
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
szStr= "D:\\images\\after_cut2.jpg";
HRESULT hr=img.Load(szStr);
}
//*view.h
#include "atlimage.h"
#include "atltypes.h"
#pragma once
class CRotateImageScrollView : public CScrollView
{
protected: // create from serialization only
CRotateImageScrollView();
DECLARE_DYNCREATE(CRotateImageScrollView)
// Attributes
public:
CRotateImageScrollDoc* GetDocument() const;
// Operations
public:
CImage img;
// Overrides
:
:
:
};
Zulfi.
Last edited by Zulfi Khan2; March 23rd, 2014 at 09:10 AM.
-
March 23rd, 2014, 09:12 AM
#22
Re: [RESOLVED] Displaying a jpeg image
...and your final code is? There's 'working' and working! Just because some code appears to be doing what is expected, doesn't mean that the code is 'correct'. Time after time I've seen c++ code that 'seems to work' but isn't correct and doesn't really work properly - it just gives the impression it does!
These are very difficult concepts
Yes, but do you now understand them - that is the important point. Can you explain every line in the program - what is does and why it's needed.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
March 23rd, 2014, 10:12 AM
#23
Re: [RESOLVED] Displaying a jpeg image
Hi,
Thanks for your attention. VC has a very tough code. I have heard people saying that its a cut and paste language. You dont write any code. You just search the code and paste it in your program. However with some effort we develop familiarity and understanding of the code. But knowledge of underlying VC framework is difficult and so the commands (or keyword) associated with it. Simple programming statements can be grasped with time. In this code I understand all statements accept the ones which are specifically related to VC framework.
Thanks for your time.
Zulfi.
Last edited by Zulfi Khan2; March 23rd, 2014 at 01:01 PM.
-
March 24th, 2014, 11:48 AM
#24
Re: [RESOLVED] Displaying a jpeg image
Originally Posted by Zulfi Khan2
I have heard people saying that its a cut and paste language. You dont write any code. You just search the code and paste it in your program.
Those people do not know what they're talking about.
Even if you don't do any GUI or MFC, C++ by itself is not an easy language, and is definitely not a "cut and paste" language.
Regards,
Paul McKenzie
-
March 24th, 2014, 12:32 PM
#25
Re: [RESOLVED] Displaying a jpeg image
Originally Posted by Zulfi Khan2
I would download the Scribble stuff but I am more interested in Computer Graphics content.
You may be interested in whatever you want, but you cannot ignore programming basics. If you want to create Windows programs, you need to learn basics of programming Windows prior to getting any further to what you're interested in. I provided you three Win32 API samples, but it turned out you preferred to go with MFC. Which implies you have to get along with MFC basics as well prior to getting to programming graphics with MFC.
Please keep in mind that this is going to happen each time you meet with another technology you're unfamiliar with. First you learn the technology basics, then you learn how to adapt it to your needs.
Adapting technology by no means implies a copy-paste "technique." This is a dead end. You have to understand every single line you put to your code.
Best regards,
Igor
-
March 24th, 2014, 01:26 PM
#26
Re: [RESOLVED] Displaying a jpeg image
Hi,
Thanks for your replies. I just want to improve the things related to VC guides. I have many books of VC but none of them tell me about the data types of VC. Only yesterday i came to know about HRESULT and that its similar to integer. If you want i can tell you their names but none of the books tell me about the data types yet its a basic. I bought these books as a effort to increase my knowledge about VC. However it went in vain. They have lengthy chapters related to Doc/View architecture which in my view is a secondary stuff. I bought the original VC and got scribble Manual with C++ book but it doesnt say anything about the basics i.e the data type of VC. I am just saying this because if we dont have good books we cant have good knowledge.
Any way I thank you people for your patience and continued support towards me and towards other people asking for help from you.
Code Guru is better than any other source of knowledge related to VC.
Zulfi.
-
March 24th, 2014, 01:33 PM
#27
Re: [RESOLVED] Displaying a jpeg image
Did you ever try to use (read/search for the info in) MSDN?
Victor Nijegorodov
-
March 24th, 2014, 02:39 PM
#28
Re: [RESOLVED] Displaying a jpeg image
none of the books tell me about the data types yet its a basic
I think you are looking at the wrong books!
For c++ programming with Visual Studio
Beginning Visual c++ 2012 by Ivor Horton
http://www.amazon.co.uk/Ivor-Hortons...visual+c%2B%2B
For programming with Windows API
Programming Windows by Charles Petzold
http://www.amazon.co.uk/Programming-...ywords=petzold
For MFC
Programming Windows with MFC by Jeoff Prosise
http://www.amazon.co.uk/Programming-...fc+programming
Once you have mastered the basics, then there are other more advanced books - but you must master the basics first. It's like having to learn to walk before you can run.
Last edited by 2kaud; March 24th, 2014 at 02:41 PM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
March 25th, 2014, 12:19 AM
#29
Re: [RESOLVED] Displaying a jpeg image
Hi,
Thanks for your information. I have lots of VC books definitely more than 10. So I am not going to spend any more on VC books. I am with VC since 1997. However if there is a specialized book like for Computer Graphics i would surely buy it.
Did you ever try to use (read/search for the info in) MSDN?
Just now i searched MSDN for "data types in " it showed me (vb, vb.net, C++, C##). Where is VC++??
Sorry i rarely get good response from MSDN.
Zulfi.
-
March 25th, 2014, 06:50 AM
#30
Re: [RESOLVED] Displaying a jpeg image
Originally Posted by Zulfi Khan2
Hi,
Thanks for your information. I have lots of VC books definitely more than 10. So I am not going to spend any more on VC books. I am with VC since 1997. However if there is a specialized book like for Computer Graphics i would surely buy it.
You definitely have to understand the difference between programming language C++ and product Visual C++. As well, you have to learn to tell product VC from technologies like Win32 API, COM, ODBC, OpenGL, .NET, etc. and frameworks like MFC, ATL, Qt, etc. Technologies are typically language independent, while frameworks are mostly not. But any of those require a decent knowledge of programming language those are used with.
I don't know how good that lots of books at explaining this difference. Maybe it's worth to go through those once again? Or start buying books on particular frameworks but not on VC in general?
Just now i searched MSDN for "data types in " it showed me (vb, vb.net, C++, C##). Where is VC++??
Sorry i rarely get good response from MSDN.
In fact, books have to help you to start understanding official documentation language, that's it. As you still find yourself not getting along with MSDN, you need to keep working on books. Or try to switch to other technology stack, like Java or C#/.NET.
Best regards,
Igor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|