|
Mike
Ok so dbuf is a pointer to a single byte in your case.
byte* dbuf = (byte*)pBuffer;
Does this not point to the first byte in my pBuffer? How do I access the rest?
In my case the buffer pBuffer contains all of the byte data for a bitmap image the image is size 768 * 576 = 442368 bytes plus any header information etc etc.
Thanks
Dave
|
|
|
|
|
Dave Harper wrote:
How do I access the rest?
Use the pointer like an array: dbuf[0] accesses the first, dbuf[1] accesses the second byte, etc.
- Mike
|
|
|
|
|
Thanks i see now.
One problem is how do I find how many bytes are in pBuffer or dbuf to know how far to increment the array?
I have tryed sizeof(pBuffer) also sizeof(dbuf) problem is it returns 4 as the result do you know of a way i can write the info to a txt file to be able to see whats going on? im using ofstream at the moment it doesnt display byte info correctly.
Thanks
Dave
|
|
|
|
|
Dave Harper wrote:
I have tryed sizeof(pBuffer) also sizeof(dbuf) problem is it returns 4 as the result
That is because pBuffer is a pointer and that pointer is a 32-bit memory address and 32 bits is 4 bytes.
|
|
|
|
|
Dave Harper wrote:
One problem is how do I find how many bytes are in pBuffer or dbuf to know how far to increment the array?
You cannot get this information from the pointer itself; the SDK should provide a way to get the size of the buffer or at least a way for you to calculate it yourself.
Dave Harper wrote:
I have tryed sizeof(pBuffer) also sizeof(dbuf) problem is it returns 4 as the result
When you use sizeof() on a pointer type, the result is the size of the pointer itself -- 4 bytes.
- Mike
|
|
|
|
|
|
Yup I sure do my head is thinking to hard not seeing the light
Thanks
Dave
|
|
|
|
|
What part of my response was incorrect?
- Mike
|
|
|
|
|
None mate its just me, sometimes i think so hard about solving something i cant see the woods for the trees.
Thanks
Dave
|
|
|
|
|
My console app consists of several classes of objects that interact with each other based on user input and predefined conditions.
Say I have classes: house, street, building, car, and world. I only need one instance of the class world, we'll call it myworld, and I need each object to be able to access functions and attributes of myworld. World is already declared as a class in world.h and it is implemented in world.cpp. When I try to create myworld in my globals header file, all of the objects dont recognize it as a type. If I create myworld just before the main function, everything works, I get no errors, until I try to access it from other objects. For example, on creation of a building object, I want to be able to modify the myworld objects count of buildings in the world.
Some people have suggested simply making all of my classes subclasses in the class world, I really dont want to do that for sake of organization. My class definitions are long.
What is the best way to go about this? I just want one instance of a class thats available globally.
|
|
|
|
|
The 'proper, modern way' would be to use a singleton[^]. But you should probably start off using a global static class. Declare an instance of your class as static at the bottom of its header file.
Ryan
|
|
|
|
|
I declared a global static class, and it was indeed available to all objects. Thank you for the advice. Eventually I'll do the singleton method. The only problem now is, for some reason, objects are incapable of modifying public attributes or calling public methods of the global class.
Lets go back to my example. Before I had the global class, when constructing a "building" object, I had to pass it the myworld object constructor. The constructor would initialize certain variables, and call some initializing member functions. It would also call a member function of the myworld object, that would essentially(on the myworld object side) just increment the building count attribute of the world class. Before and after building object construction, I cout'ed myworld object's building count. It didnt change.
Now, with the static global object myworld, the results are the same. Myworld just refuses to change. Building has been made a friend class to the world class. In fact, nothing is private in the world class.
Just to check my coding, I called world class member functions and modified building counts directly from the main function, and it worked. It just doesnt seem to want to be modified by another object.
Any ideas?
|
|
|
|
|
immanis wrote:
Some people have suggested simply making all of my classes subclasses in the class world, I really dont want to do that...
Nor would you want to since nothing else (i.e., house, street, building, car) is a type of world.
One solution would be to mimic the way MFC does it. When you create a project, you have a CWinApp -derived class (e.g., CMyApp). Nothing else in the project is derived from CMyApp, yet you have access to CMyApp via functions like AfxGetApp() . Make sense?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Hi,
I have created my own splitter window control, I then added all of the functionality from an article on CodeProject which enables me to show/hide columns and rows. However some of the assertion errors seem to be causing me problems.
Would you be able to see what the problem could be?
<br />
<br />
class CViewSplitter : public CSplitterWnd<br />
{<br />
...<br />
typedef std::list<int> LIST_INT;<br />
<br />
bool MaximizeActiveView();<br />
void RestoreViews();<br />
bool MaximizeView(int row, int col);<br />
<br />
void HideColumn(int colHide);<br />
void ShowColumn(int colShow);<br />
void HideRow(int colRow);<br />
void ShowRow(int row);<br />
...<br />
};<br />
<br />
<br />
bool CViewSplitter::MaximizeView(int row, int col)<br />
{<br />
ASSERT(row <= m_nRows && col <= m_nCols);<br />
<br />
bMaximized = true;<br />
<br />
if(row == 0) HideRow(1); else HideRow(0);<br />
if(col == 0) HideColumn(1); else HideColumn(0);<br />
<br />
return true;<br />
}<br />
<br />
void CViewSplitter::RestoreViews()<br />
{<br />
bMaximized = false;<br />
<br />
ShowColumn(0); ShowColumn(1);<br />
ShowRow(0); ShowRow(1);<br />
}<br />
<br />
bool CViewSplitter::MaximizeActiveView()<br />
{<br />
int nActiveRow, nActiveCol;<br />
<br />
if(GetActivePane(&nActiveRow, &nActiveCol) != NULL)<br />
return MaximizeView(nActiveRow, nActiveCol);<br />
else<br />
return false;<br />
}<br />
<br />
void CViewSplitter::ShowColumn(int col)<br />
{<br />
ASSERT_VALID(this);<br />
ASSERT(m_nCols <= m_nMaxCols);<br />
<br />
std::list<int>::iterator col_pos; <br />
<br />
col_pos = std::find(m_shown_cols.begin(),m_shown_cols.end(),col);<br />
<br />
if(col_pos!=m_shown_cols.end())<br />
{<br />
return;<br />
}<br />
<br />
int place = AbsToRelPosition(m_shown_cols, col);<br />
<br />
m_nCols++;
<br />
m_shown_cols.push_back(col);<br />
m_shown_cols.sort();<br />
m_hid_cols.remove(col);<br />
<br />
RenumeratePanes();<br />
<br />
RestoreColInfo(place,col);<br />
RecalcLayout();<br />
}<br />
<br />
void CViewSplitter::HideColumn(int colHide)<br />
{<br />
ASSERT_VALID(this);<br />
ASSERT(m_nCols > 1);<br />
ASSERT(colHide < m_nMaxCols);<br />
<br />
std::list<int>::iterator col_pos; <br />
<br />
col_pos = std::find(m_shown_cols.begin(),m_shown_cols.end(),colHide);<br />
<br />
if(col_pos==m_shown_cols.end())<br />
{<br />
ASSERT(0);<br />
return;<br />
}<br />
<br />
int place = std::distance(m_shown_cols.begin(),col_pos);<br />
<br />
int rowActive, colActive;<br />
if (GetActivePane(&rowActive, &colActive) != NULL &&<br />
colActive == place)<br />
{<br />
if (++colActive >= m_nCols)<br />
colActive = 0;<br />
SetActivePane(rowActive, colActive);<br />
}<br />
<br />
m_shown_cols.remove(colHide);<br />
m_hid_cols.push_back(colHide);<br />
<br />
m_nCols--;<br />
<br />
RenumeratePanes();<br />
<br />
RemoveColInfo(place,colHide);<br />
<br />
RecalcLayout();<br />
}<br />
<br />
void CViewSplitter::HideRow(int rowHide)<br />
{<br />
ASSERT_VALID(this);<br />
ASSERT(m_nRows > 1);<br />
ASSERT(rowHide < m_nMaxRows);<br />
<br />
std::list<int>::iterator row_pos; <br />
<br />
row_pos = std::find(m_shown_rows.begin(),m_shown_rows.end(),rowHide);<br />
<br />
if(row_pos==m_shown_rows.end())<br />
{<br />
ASSERT(0);<br />
return;<br />
}<br />
<br />
int place = std::distance(m_shown_rows.begin(),row_pos);<br />
<br />
int rowActive, colActive;<br />
if (GetActivePane(&rowActive, &colActive) != NULL &&<br />
rowActive == place)<br />
{<br />
if (++rowActive >= m_nRows)<br />
rowActive = 0;<br />
SetActivePane(rowActive, colActive);<br />
}<br />
<br />
<br />
m_shown_rows.remove(rowHide);<br />
m_hid_rows.push_back(rowHide);<br />
<br />
<br />
m_nRows--;<br />
<br />
RenumeratePanes();<br />
<br />
RemoveRowInfo(place,rowHide);<br />
<br />
RecalcLayout();<br />
}<br />
<br />
void CViewSplitter::ShowRow(int row)<br />
{<br />
ASSERT_VALID(this);<br />
ASSERT(m_nRows <= m_nMaxRows);<br />
<br />
std::list<int>::iterator row_pos; <br />
<br />
row_pos = std::find(m_shown_rows.begin(),m_shown_rows.end(),row);<br />
<br />
if(row_pos!=m_shown_rows.end())<br />
{<br />
return;<br />
}<br />
<br />
int place = AbsToRelPosition(m_shown_rows, row);<br />
<br />
m_nRows++;
<br />
m_shown_rows.push_back(row);<br />
m_shown_rows.sort();<br />
m_hid_rows.remove(row);<br />
<br />
RenumeratePanes();<br />
<br />
RestoreRowInfo(place, row);<br />
RecalcLayout();<br />
}
Any help would be greatly appreciated!
Yours Sincerely,
Lea Hayes
|
|
|
|
|
Hint: way too much code here. Trim it down to something more manageable and ask a specific question. You'll get tons more help that way.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Hi
I am trying to print bmp/jpeg image from an mfc application, but the image size is very small.
Can someone tell me how to get the original size while printing?
Here is my code.
Thankyou.
BOOL CView::OnPreparePrinting ( CPrintInfo *info )
{
info -> SetMaxPage ( 1 ) ;
return DoPreparePrinting ( info ) ;
}
void CView::OnPrepareDC ( CDC *pDC, CPrintInfo* info )
{
CView::OnPrepareDC ( pDC, info ) ;
if ( pDC -> IsPrinting( ) )
int n = info -> m_nCurPage ;
pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetWindowExt(10000,10000);
pDC->SetViewportExt(18000,18000);
pDC->SetViewportOrg(500,1000);
}
}
|
|
|
|
|
The document should have information on the bitmap, since it had to load it from a file, or create it outright.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
After creating a printer DC in your printing function calculate desired destination rectangle taking into account a size of paper:
CSize paper_res;
paper_res.cx = dcPrinter.GetDeviceCaps(HORZRES);
paper_res.cy = dcPrinter.GetDeviceCaps(VERTRES);
Try to set dcPrinter's map mode as MM_TEXT and to use dcPrinter.StrechBlt(...)
|
|
|
|
|
|
hello everybody,
I want to store strings in the format of lines in an edit box or an rich edit box.
I had done by using CString variable but it doesn't taking the '\n' escape sequence which displays the next part of the string in a new line.
any solutions,
please help.
Thanking you
Neelesh K J Jain.
|
|
|
|
|
You need to use \r\n instead of \n
|
|
|
|
|
In addition to niall's response, you also need to make szure the control has the ES_MULTILINE style.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Hi all,
Im having real trouble trying to get consistent output in print preview. I am drawing a page of text and by varrying the zoom state, the text height differs by a few pixels for any given line. I know why this is occuring because the CPreviewDC->MirrorFont() function does some odd things with the fonts in order to display them. I havent got a clue how to get around this, any help would be greatly appreciated.
Cheers,
Andy.
|
|
|
|
|
Hi,
I want to develop an application in VC++ which should work on Windows and Mac.
How do i go ahead, pls guide me out in this aspect.
Thanks a zillion for your help.
Cheers
Pawan
|
|
|
|
|
The Mac cross compiler version of VC++ is long gone, so you won't be able to use VC++ for the Mac version. Have a look at wxWindows.
|
|
|
|