|
This is annoying code for an experienced c++ programer to read... You are mixing couts with fopens which is generally bad practice. As for the answer to your question how about an fprintf(fb,<insert what you want to go to the file here>);
John
|
|
|
|
|
In my SDI application, I have a menu option that brings up a typical "Options" dialog. The dialog is actually a property sheet with several property pages. The menu handler is in the document. The document owns the configuration data as it is needed at various other places, including the view. At this point, what is your take on how to get the document's configuration data to the individual property pages (and back)?
Thanks,
DC
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
I am now in the middle of working on various property pages/sheets and these are the methods I am using:
First, I store the configuration data in a structure. I copy this data to an instance in the function call that creates the property sheet and pages. If the user clicks OK (or Apply, though I rarely use Apply) the data is stored in the registry (or wherever such things are saved) and in the original instance. Often, I don't to a binary copy, but use functions to save since other things, such as font changes, have to be done with the new settings.
BTW, to share the temporary options I pass a reference to the constructors of the property pages.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
In MFC the OnSetActive and OnKillActive will invoke the dynamic data exchange member function. You can load data from a data structure ahead of the control loading, and save it after the controls write the data to the member variables back to the data structure. This works out well, because you can validate the data and fail the data exchange to disallow the property page from being changed.
I make a class or data structure to hold the data, it is usually owned by the app, but in your case the document, so in the first call to OnInitDialog, when the page is first constructed, you could obtain and perhaps store the pointer to the configuration data structure or class. Or else obtain it dynamically from the document each time you need a load or a save of the data.
|
|
|
|
|
Does anyone know if there is an easy way of taking a device context and exporting it as an image?
I have an application which uses a home-grown class for displaying graphs, and I need to be able to export the charts as images for inclusion in MSWord/HTML reports.
Thanks!
|
|
|
|
|
You need to create a bitmap (CreateBitmap()), get a memory DC for that bitmap, then bit-blt from your source DC into the bitmap DC. There are several articles on this site that describe how to save the bitmap in different formats; here's one: http://www.codeproject.com/bitmap/jscdibdata.asp
This posting is provided “AS IS” with no warranties, and confers no rights. You assume all risk for your use. © 2003 Microsoft Corporation. All rights reserved.
|
|
|
|
|
Thanks! I thought it was something like that, but I just wanted to make sure before I reinvented the wheel
|
|
|
|
|
I have the following string '00001762'. Sometimes it can be '00000562'. How do I remove all unwanted 0 before the actual number?
|
|
|
|
|
If you are using MFC, try CString::TrimLeft() .
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
I am not using MFC. I am reading the data from file into char[10].
|
|
|
|
|
Then you'll need to manually do what CString::LeftTrim() does, something like:
void MyTrim( LPTSTR lpszString )
{
LPCTSTR lpsz = lpszString;
while ('0' == *lpsz)
lpsz = _tcsinc(lpsz);
if (lpsz != lpszString)
{
int nLength = _tcslen(lpszString) - (lpsz - lpszString);
memmove(lpszString, lpsz, (nLength + 1) * sizeof(TCHAR));
}
}
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
Can anyone give me some pointers on how to handle an operator dragging a message out of Outlook and dropping it onto a control in my program. My control currently handles receiving files dragged from explorer by registering itself as a drop target using RegisterDragDrop() with an implementation of the IDropTarget interface that looks for CF_HDROP formats.
I'm assuming there is a 'standard' way to handle a dropped message from Outlook as explorer creates a file containing the message if you drag from Outlook and drop onto the desktop.
Systems AXIS Ltd - Software for Business ...
|
|
|
|
|
I am having an annoying problem trying to open a document file by double-clicking on the file. It used to work, but I don't remember what I did to make it not work. I get the following message:
Cannot find the file (double clicked file path) or one of it's components. Make sure the path and filename are correct and that all required libraries are available.
Any Ideas?
Gary Kirkham
A working Program is one that has only unobserved bugs
I thought I wanted a career, turns out I just wanted paychecks
|
|
|
|
|
The actual opening of the document is tied with the Folder Settings found from Windows Explorer. You insert a new file type binding into this long list to tell Windows that whenever user wants to open this type of file, it will start your program.
The problem you're describing indicates that your program's files are not functioning properly. Have you tried to start your program without opening a file ? Like, just by running it ?
Naturally, you should check the Folder Settings to make sure that the path located in there points to the correct destination where your program resides. Also, make sure that your source code can handle the opening of files. In the Windows world, when a document is double-clicked, Windows checks whether the file type has a binding, and if it does, it calls the specified program and issues the filename as the first parameter.
Hope this will help. If the problem is with some other type of a document (i.e. not your own), then post more details on the type of file etc..
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
The file opens properly when I do a File-Open from the menu. Everything in the registry appears to be proper. The file extension is associated with the correct executable. When I double-click the file it starts the program, gives the error message, and then fails to load the file.
Gary Kirkham
A working Program is one that has only unobserved bugs
I thought I wanted a career, turns out I just wanted paychecks
|
|
|
|
|
Hi there, i'm doing image processing in VC++6. How can i perform thresholding (converting color to b&w) on an image, as fast as possible? I'm able to do using GetPixel & SetPixel but it is too slow. Anyway i can access the pixels directly??
Here is the code
//Image width=height=Big=360 px
int Big=360;
//Create a DC for buffering image
CDC MemDC,*pDC;
CBitmap MemBitmap;
// Get Current DC from dialog box,
pDC = myDlg->GetDC();
MemDC.CreateCompatibleDC(pDC);
//
MemBitmap.CreateCompatibleBitmap(pDC,Big,Big);
CBitmap *pOldBitmap = MemDC.SelectObject(&MemBitmap);
//------------custom hardware function that draws image from camera to DC-----------//
imgPlot ((GUIHNDL)MemDC.GetSafeHdc(), (void *)ImaqBuffer, 0, 0, Big, Big, 410, 10, plotFlag));
//-------------------------------------------
//My thresholding function, which is very slow!!!
//check every pixel, if it is bigger than threshold then turn it black
//and white otherwise
//**********
for(int i=0;i<360;i++)
for(int j=0;j<360;j++)
{
if(MemDC->GetPixel(i,j)<=RGB(64,128,255))
MemDC->SetPixel(i,j,RGB(0,0,0));
else
MemDC->SetPixel(i,j,RGB(255,255,255));
}
pDC->BitBlt(10,10,Big,Big,&MemDC,0,0,SRCCOPY); //See Note 3
MemDC.SelectObject(pOldBitmap);
//---------------------------
The code is too slow for real time. How can i do thresholding faster?
|
|
|
|
|
Haven't messed with bitmaps in a while, but try GetBitmapBits(), which will give you an array of bytes containing the bitmap. Then run through this array changing values. Then call SetBitmapBits() with the modified array. This should be much faster.
____________________________________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. (Rich Cook)
|
|
|
|
|
Hi there, can you give me an example of using the GetBitmapBits()? I cant find any example on it.
|
|
|
|
|
This is copied from a test app I wrote (real quick, so don't be too critical - it works).
CPaintDC dc(this);
CRect cRect; GetClientRect( cRect );
int nWidth = cRect.Width();
int nHeight = cRect.Height();
CBitmap cBitmap;
cBitmap.LoadBitmap( IDB_BITMAP1 );
DWORD* pBuffer = new DWORD[ nWidth * nHeight ];
DWORD dwSize = cBitmap.GetBitmapBits( nWidth * nHeight,
pBuffer );
for ( int y = 0 ; y < nHeight ; y++ )
{
for ( int x = 0; x < nWidth ; x++ )
{
if ( *(pBuffer+x+nWidth*y) < RGB( 64, 128 , 256 ) )
{
*(pBuffer+x+nWidth*y) = 0;
}
else
{
*(pBuffer+x+nWidth*y) = 0x00FFFFFF;
}
}
}
cBitmap.SetBitmapBits( nWidth * nHeight ,
pBuffer );
CDC cMemDC;
cMemDC.CreateCompatibleDC( &dc );
cMemDC.SelectObject( &cBitmap );
dc.BitBlt( 0,
0,
nWidth,
nHeight,
&cMemDC,
0,
0,
SRCCOPY );
delete [] pBuffer;
|
|
|
|
|
Thanks a lot for the help. Looking at the code you gave me, seems that it would be faster than the one i just figured out, :P
i havent try your code yet, coz i just got wrote myself a working code. Here is the code that i wrote,
//the test image "bmptest.bmp" is a color bmp 360x360 pixels
------------------------------------------
CDC *pDC;
CDC memDCLoad;
CBitmap m_bmpBitmap;
pDC = this->GetDC();
CString m_sBitmap;
m_sBitmap="bmptest.bmp";
memDCLoad.CreateCompatibleDC(pDC);
HBITMAP hBitmap =(HBITMAP)::LoadImage(AfxGetInstanceHandle(),m_sBitmap,IMAGE_BITMAP,0,0,
LR_LOADFROMFILE|LR_DEFAULTCOLOR);
if(hBitmap)
{
if(m_bmpBitmap.DeleteObject())
m_bmpBitmap.Detach();
m_bmpBitmap.Attach(hBitmap);
}
memDCLoad.SelectObject(&m_bmpBitmap);
pDC->BitBlt(0,0,360,360,&memDCLoad,0,0,SRCCOPY);
BYTE test[(4*360*360)];
void* pbBits = test;// One bit per pixel
m_bmpBitmap.GetBitmapBits(4*360*360, &pbBits);
for(int i=0;i<360*360;i++)
{
//BGR=000 //black
//BGR=255,255,255//white
int temp=i*4;
//test[temp+0]=0;//blue
//test[temp+1]=0;//green
//test[temp+2]=0;//red
//test[temp+3]=255;//padding
BYTE gray= (byte)(test[temp+2]*0.299
+test[temp+1]*0.587
+test[temp+0]*0.114);
if(gray<=230)
{
test[temp+0]=0;//blue
test[temp+1]=0;//green
test[temp+2]=0;//red
}
else
{
test[temp+0]=255;//blue
test[temp+1]=255;//green
test[temp+2]=255;//red
}
}
m_bmpBitmap.SetBitmapBits(4*360*360, &pbBits);
pDC->BitBlt(360,0,360,360,&memDCLoad,0,0,SRCCOPY);
|
|
|
|
|
My inner loop could be much simpler and faster:
for ( int x = 0 ; x < dwSize ; x++ )
{
if ( pBuffer[x] < RGB( 64, 128 , 256 ) )
{
pBuffer[x] = 0;
}
else
{
pBuffer[x] = 0x00FFFFFF;
}
}
I was thinking two-dimensions, but it's really just one one big buffer
|
|
|
|
|
The function for thresholding works extremely fast compared by using SetPixel and GetPixel. However, i got another problem now.
My camera (frame grabber) returns the captured image in a CDC object only. And not in a Cbitmap. A CDC object does not have SetBitmapbits and GetBitmapBits members, so i cant call those. I can only access pixels in CDC using GetPixel and SetPixel. (Correct me if i'm wrong). And using Get & SetPixel is too slow, hence i needed a faster algorithm which you came up with. To use getbitmapbits, the object must be a CBItmap.
However, my question is now, how to copy contents of a CDC/DC buffer or object (already contains data) to a CBitmap object for processing, and then back to CDC object?
//------------custom hardware function that draws image from camera to DC-----------//
imgPlot ((GUIHNDL)MemDC.GetSafeHdc(), (void *)ImaqBuffer, 0, 0, Big, Big, 410, 10, plotFlag));
//-------------------------------------------
MemDC is a DC. Now contains an image copied from the camera buffer (ImaqBuffer) using a driver function.
How to copy MemDC to a CBitmap and do the thresholding with the function you came up with?
After finishing, how to copy the CBitmap back to MemDC for plotting on window etc.
THanks for the great help.
|
|
|
|
|
try using MemDC.GetCurrentBitmap() which returns a pointer to a CBitmap. Then you can do the thresholding with it.
|
|
|
|
|
Thanks, i tried that (GetCurrentBitmap), and it is exactly what i needded. Thanks a lot! You're a genius! Guess it works! Thanks a lot.
I'll find u againg, if i've got problem.. haha :P
|
|
|
|
|
uus99 wrote:
The code is too slow for real time. How can i do thresholding faster?
Can you get the hardware to give you a pointer to the image data instead of ploting it to a dc?
John
|
|
|
|
|