|
i can get the code to compile just fine but when i go to launch my application i get an assertion error, i narrowed down the block of code that might be causing it but i also think i am not correctly writing the code to display the bitmap.
this block of code in my OnInitDialog function is where i get the problem from i think.
m_st1.GetClientRect( &rectStaticClient );
rectStaticClient.NormalizeRect();
m_size.cx=rectStaticClient.Size().cx;
m_size.cy=rectStaticClient.Size().cy;
m_size.cx = rectStaticClient.Width();
m_size.cy = rectStaticClient.Height();
m_st1.ClientToScreen( &rectStaticClient );
ScreenToClient( &rectStaticClient);
m_pt.x = rectStaticClient.left;
m_pt.y = rectStaticClient.top;
GetObject( m_hBmpNew , sizeof(BITMAP), &m_bmInfo );
VERIFY(m_hBmpOld = (HBITMAP)SelectObject(m_dcMem, m_hBmpNew ) );
offsetx= m_pt.x;
offsety=m_pt.y;
InvalidateRect(&rectStaticClient);
not really messed with graphics coding much before, if soemone could help me out with whats possibly going on i would really appreciate it.
|
|
|
|
|
The assert comes from the previous selected bitmap in your memory DC - 'm_hBmpOld' is null.
To display a bitmap you have to paint it OnPaint() not to select it to an DC (DisplayContext).
HDC mdc;<br />
HGDIOBJ obmp;<br />
BITMAP bmi;<br />
<br />
if(m_hbmp && GetObject(m_hbmp,sizeof(bmi),&bmi))<br />
{<br />
mdc = CreateCompatibleDC(hdc);<br />
obmp = SelectObject(mdc,m_hbmp);<br />
<br />
BitBlt(hdc,offsetx,offsety,bmi.biWidth,bmi.biHeight,mdc,0,0,SRCCOPY);<br />
<br />
SelectObject(mdc,obmp);<br />
DeleteDC(mdc);<br />
}
|
|
|
|
|
tried using the code and sayign hdc is undeclared and when i make it a hdc variable it says oen fo them was used without being initialized. how i set up my dialog was i made a picture control and from there not quite sure exactly what to do, the code you gave by its self wont just display my image as i am sure more code is needed but i get multiple assertions when i load my app and if i ignore them it loads but no image loaded.
this is my code so far(most commented out though) that would do the image loading, but i get multiple assertions.
afx_msg BOOL CPLoader::OnInitDialog()
{
/*CClientDC dc(this);
m_dcMem.CreateCompatibleDC(&dc);
m_hbmp = (HBITMAP) LoadImage(
AfxGetInstanceHandle(),
"plogo.bmp",
IMAGE_BITMAP,
300,
65,
LR_LOADFROMFILE);
m_st1.SetBitmap(m_hbmp);
if( m_hBmpNew == NULL )
{
AfxMessageBox("Failed to Load Image");
}
else
{
m_st1.GetClientRect( &rectStaticClient );
rectStaticClient.NormalizeRect();
m_size.cx=rectStaticClient.Size().cx;
m_size.cy=rectStaticClient.Size().cy;
m_size.cx = rectStaticClient.Width();
m_size.cy = rectStaticClient.Height();
m_st1.ClientToScreen( &rectStaticClient );
ScreenToClient( &rectStaticClient);
m_pt.x = rectStaticClient.left;
m_pt.y = rectStaticClient.top;
GetObject( m_hBmpNew , sizeof(BITMAP), &m_bmInfo );
//VERIFY(m_hBmpOld = (HBITMAP)SelectObject(m_dcMem, m_hBmpNew ) );
offsetx= m_pt.x;
offsety=m_pt.y;
InvalidateRect(&rectStaticClient);
}*/
return true;
}
afx_msg void CPLoader::OnPaint()
{
HDC mdc, hdc;
HGDIOBJ obmp;
BITMAP bmi;
if(m_hbmp && GetObject(m_hbmp,sizeof(bmi),&bmi))
{
mdc = CreateCompatibleDC(hdc);
obmp = SelectObject(mdc,m_hbmp);
BitBlt(hdc,offsetx,offsety,bmi.bmWidth,bmi.bmHeight,mdc,0,0,SRCCOPY);
SelectObject(mdc,obmp);
DeleteDC(mdc);
}
/*if(IsIconic())
{
CPaintDC dc(this);
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);
}
else
{
CPaintDC dc(this);
dc.BitBlt(offsetx, offsety, m_size.cx, m_size.cy,
&m_dcMem, sourcex, sourcey, SRCCOPY);
CDialog::OnPaint();
}*/
}
this is based off of an article i read on this site that seemed to do as i wanted but i guess i did not set up right.
|
|
|
|
|
you have to modify your code for using MFC:
CPaintDC dc(this);<br />
<br />
HDC mdc;<br />
HGDIOBJ obmp;<br />
BITMAP bmi;<br />
<br />
if((HBITMAP)m_hbmp && ::GetObject(m_hbmp,sizeof(bmi),&bmi))<br />
{<br />
mdc = ::CreateCompatibleDC(dc.m_hDC);<br />
obmp = ::SelectObject(mdc,m_hbmp);<br />
<br />
::BitBlt(dc.m_hDC,offsetx,offsety,bmi.bmWidth,bmi.bmHeight,mdc,0,0,SRCCOPY);<br />
<br />
::SelectObject(mdc,obmp);<br />
::DeleteDC(mdc);<br />
}
Please mark your code as 'code'.
|
|
|
|
|
Hello,
What does it mean when a structure member declaration is followed by a colon, then a number, as in:
typedef struct tagMENUBARINFO
{
DWORD cbSize;
RECT rcBar;
HMENU hMenu;
HWND hwndMenu;
BOOL fBarFocused:1;
BOOL fFocused:1;
} MENUBARINFO, *PMENUBARINFO, *LPMENUBARINFO;
The "fBarFocused " member has a ":1 " after it. What does that mean?
Thank you very much,
Rich
|
|
|
|
|
|
It specifies how many bits are used to store the variable. In this case it is one bit. Look up "bit fields" in MSDN or see http://www.codeproject.com/cpp/bitbashing.asp[^]
You may be right
I may be crazy
But it just may be a lunatic you’re looking for
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
As the others have said, it says that that field takes up one bit.
However, don't be tempted to use bit fields in your own structures. They are highly non-portable, even when compiling for the same platform. Different Windows compilers may treat them in different ways. Even different versions of the same compiler on the same platform can treat them differently. Use them only if you can guarantee that you will only ever compile your code with the same compiler (same version, same vendor etc...). The problem is that the C standard does not specify in which order the fields are to appear in memory - compilers are free to do whatever they like.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Just wondering because...some things...strings, iterators, lists, etc are nice and clean in java and c#, but are ugly or lacking in c++.
Over time i see code project articles try to bring some of that c# goodness to c++, like with delegates, foreach, and properties...so is their any library out there that does this in a big way...make c++ like C# with memory leaks i mean :P
|
|
|
|
|
|
If you've looked at Boost you'd be asking the opposite question. For example the multi index containers and the Boost graph library are unbelivable and only available in C++. Some of what you mention has been available (in the STL) for years, in fact before dotNET even existed - std::string and iterators for example.
Steve
|
|
|
|
|
Hi,
I am having a 16bit ascii file which contains signed integers from -8191 to +8191. These integers are stored in a file in a single row without any delimiters. Can anyone gimme a sample code which can read this kind of file for the signed integers (b/n -8191 and +8191) stored in it or do I need any more info to perform this?
thanks,
-Pav.
|
|
|
|
|
So are you wanting to read the file two bytes at a time? If so, just use a short . To see if you are on the right track, try:
FILE *pFile = fopen("", "rb");
short num1, num2, num3;
fread(&num1, sizeof(short), 1, pFile);
fread(&num2, sizeof(short), 1, pFile);
fread(&num3, sizeof(short), 1, pFile);
fclose(pFile); Now if num1 , num2 , and num3 are correct, you're on your way.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
What do you mean by "16 bit ascii"? Do you mean a UNICODE text file? or do you mean that the numbers are stored in a 16 bit binary format (every 16 bits or two bytes is another number)?
How the the numbers are stored in the file will determine how you have to read it.
You may be right
I may be crazy
But it just may be a lunatic you’re looking for
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
It's a 16 bit binary format. The numbers are stored one after the other without any delimiters.
thanks,
-Pav
|
|
|
|
|
So the file is a series of short s. Simply open the file and read in one short at a time.
You may be right
I may be crazy
But it just may be a lunatic you’re looking for
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
Has anyone built a C++ app that uses the STL but does NOT use the CRT? Is this possible?
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
Save an Orange - Use the VCF!
|
|
|
|
|
Not possible, STL uses the CRT.
You may be right
I may be crazy
But it just may be a lunatic you’re looking for
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
I was thinking that in some ways, STL is the CRT so the two cannot really be separated...but here's a thought:
If you define the STL to be just a collection of header-files, and the CRT to be things like new[], delete[] etc
Then it would be possible to write your own implementation of global new[], delete[], plus provide a few other necessary house-keeping routines like mainCRTStartup. Add the compiler option to strip the CRT, and maybe one could cobble something together which, when linked to your 'custom' CRT, could be twisted enough to meet the original requirement...
can't imagine why anyone would want to do this..
james
http://www.catch22.net
|
|
|
|
|
I have oppsite question. it should have more sense.
if you do not use stl stuff ,how to unlinke stl lib from my project?
it seem stl is default linked to any c++ project(I use vc)
|
|
|
|
|
What can be used on windows xp to debug an application at runtime? I cant step through it because its an exe thats launched by another exe, and it calls some dlls, which might be where the problem is occuring,
thanks,
sb
|
|
|
|
|
Is there a way of sending my class a pointer to my view's DC. I would like to draw to the DC and then "blit" it back to the screen. Until now I have only been able to get the DC for the main window.
Thanks.
|
|
|
|
|
CFrameWnd::GetActiveView will return a pointer to your CView derived window, you can call GetDC on that view
You may be right
I may be crazy
But it just may be a lunatic you’re looking for
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
I tried what you suggested and I get an "illegal call of non-static member function" error.
CView* pView = CFrameWnd::GetActiveView();<br />
CDC* pDC = myview->GetDC();
I am new to the whole MFC programming scene so I am sure I am doing something really silly.
Thanks for the help.
-- modified at 14:00 Tuesday 28th February, 2006
|
|
|
|
|
masnu wrote: CView* pView = CFrameWnd::GetActiveView();
GetActiveView() is not a static function (i.e., one that can be called without an actual object). You must call it in the context of a CFrameWnd object, not CFrameWnd itself.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|