|
I think your maybe your problem is of bmp.Load();(your answer to my reply)
|
|
|
|
|
You said createcompatiblebitmap has a problem but where you used it? and whats error?
|
|
|
|
|
the error come from ASSERT on the handle of the pDC in this function:
BOOL CGdiObject::Attach(HGDIOBJ hObject)
{
ASSERT(m_hObject == NULL);
...
}
i try CreateCompatibleBitmap :
void MyView::OnPrint(CDC *pDC, CPrintInfo *pInfo)
{
CBitmap bmp;
if (bmp.LoadBitmap(IDB_BITMAP_1))
{
BITMAP bmpInfo;
bmp.GetBitmap(&bmpInfo);
CDC dcMemory;
BOOL result;
result=dcMemory.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp);
bmp.CreateCompatibleBitmap(&dcMemory,bmpInfo.bmWidth,bmpInfo.bmHeight);
result=pDC->BitBlt(x, y, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory,
0, 0, SRCCOPY );
dcMemory.SelectObject(pOldBitmap);
}
}
|
|
|
|
|
jerome_data wrote: bmp.CreateCompatibleBitmap(&dcMemory,bmpInfo.bmWidth,bmpInfo.bmHeight);
CreateCompatibleBitmap initializes a bitmap compatible to mentioned DC.
In your case, its already initialized. Thats why assert is there. Comment this line, as it is not required.
|
|
|
|
|
Good eye
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Thanks !
But, seems like OP is not interested to reply back, once his problem is known.
|
|
|
|
|
You assign IDB_BITMAP_1 to bmp object and then create a another bitmap you can before CreateCompatibleBitmap use of bmp.detach() and create your bitmap
|
|
|
|
|
Used this code to print a bitmap on printer and display
void YourClass::PrintBitmap(CDC *pDC, CPrintInfo *pInfo,UINT Bitmap,int x,int y)
{
LPBITMAPINFO info; // Structure for storing the DIB information,
// it will be used by 'StretchDIBits()'
HBITMAP hbit; // Handle to the bitmap to print
BITMAP bm; // Structure used for obtaining information
// about the bitmap (size, color depth...)
int nColors = 0; // Used to store the number of colors the DIB has
int sizeinfo = 0; // Will contain the size of info
RGBQUAD rgb[256]; // Used to store the DIB color table
// The following line loads the bitmap from resource bitmap
hbit = (HBITMAP) LoadImage(AfxGetInstanceHandle(),
MAKEINTRESOURCE(Bitmap),
IMAGE_BITMAP,
0,
0,
LR_CREATEDIBSECTION);
// Obtain information about 'hbit' and store it in 'bm'
GetObject(hbit, sizeof(BITMAP), (LPVOID) &bm);
nColors = (1 << bm.bmBitsPixel);
if(nColors > 256)
nColors=0; // This is when DIB is 24 bit.
// In this case there is not any color table information
// Now we need to know how much size we have to give for storing "info" in memory.
// This involves the proper BITMAPINFO size and the color table size.
// Color table is only needed when the DIB has 256 colors or less.
sizeinfo = sizeof(BITMAPINFO) + (nColors * sizeof(RGBQUAD)); // This is the size required
info = (LPBITMAPINFO) malloc(sizeinfo); // Storing info in memory
// Before 'StretchDIBits()' we have to fill some "info" fields.
// This information was stored in 'bm'.
info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
info->bmiHeader.biWidth = bm.bmWidth;
info->bmiHeader.biHeight = bm.bmHeight;
info->bmiHeader.biPlanes = 1;
info->bmiHeader.biBitCount = bm.bmBitsPixel * bm.bmPlanes;
info->bmiHeader.biCompression = BI_RGB;
info->bmiHeader.biSizeImage = bm.bmWidthBytes * bm.bmHeight;
info->bmiHeader.biXPelsPerMeter = 0;
info->bmiHeader.biYPelsPerMeter = 0;
info->bmiHeader.biClrUsed = 0;
info->bmiHeader.biClrImportant = 0;
// If the bitmap is a compressed bitmap (BI_RLE for example), the 'biSizeImage' can not
// be calculated that way. A call to 'GetDIBits()' will fill the 'biSizeImage' field with
// the correct size.
// Now for 256 or less color DIB we have to fill the "info" color table parameter
if(nColors <= 256)
{
HBITMAP hOldBitmap;
HDC hMemDC = CreateCompatibleDC(NULL); // Creating an auxiliary device context
hOldBitmap = (HBITMAP) SelectObject(hMemDC, hbit); // Select 'hbit' in 'it'
GetDIBColorTable(hMemDC, 0, nColors, rgb); // Obtaining the color table information
// Now we pass this color information to "info"
for(int iCnt = 0; iCnt < nColors; ++iCnt)
{
info->bmiColors[iCnt].rgbRed = rgb[iCnt].rgbRed;
info->bmiColors[iCnt].rgbGreen = rgb[iCnt].rgbGreen;
info->bmiColors[iCnt].rgbBlue = rgb[iCnt].rgbBlue;
}
SelectObject(hMemDC, hOldBitmap);
DeleteDC(hMemDC);
}
// Let's get 'StretchDIBiting'! 'pDC' is the printer DC
HDC hdc = pDC->GetSafeHdc(); // Getting a safe handle
// Stretching all the bitmap on a destination rectangle of size (size_x, size_y)
// and upper left corner at (initial_pos_x, initial_pos_y)
StretchDIBits(hdc,
x,
y,
bm.bmWidth,
bm.bmHeight,
0,
0,
bm.bmWidth,
bm.bmHeight,
bm.bmBits,
info,
DIB_RGB_COLORS,
SRCCOPY);
// This mode, DIB_RGB_COLORS indicate the color table are pure RGB values
// The mode DIB_PAL_COLORS indicate the color table items are index to the local palette items
DeleteObject(hbit);
free(info)
}
|
|
|
|
|
There are three list which include objects of my classes.(car,bus,lorry) All the objects have an unique id number. I want to find the object which has a id that has given as parameter. (as using template method of c++)
For example
my classes are;
class car{
string colour1;
int id;
int weight1;
}
class bus{
string colour2;
int id;
int weight2;
}
class lorry{
string colour3;
int id;
int weight3;
}
Is it necessary to write same names of the variables (id) to apply template method to my application?
Thanks.
|
|
|
|
|
I assume you mean something like this:
template <typename T>
inline int GetID(const T &obj)
{
return obj.id;
}
There are a number of methods you could use to handle differently named variables. Given the general case above you could introduce an exception using template specialisation as follows for example:
template <>
inline int GetID<rocket>(const rocket &obj)
{
return obj.rocket_id;
}
Steve
|
|
|
|
|
carList for car
busList for bus
lorryList for lorry
I have a method;
int find(type list, int id) //type can be three posibilities (carList,busList,lorryList)
{
for(i){
if(list[i].id == id){
return id;
}
}
}
Is this method right for my porpose as logical?
|
|
|
|
|
I can't tell. Is it a template? It doesn't look like one. What is type ?
Steve
|
|
|
|
|
I am trying to implement a "Column Chooser" for a ListCtrl in a Dialog based application - very much like Outlook's "Field Chooser" or Maarten Hoeben's "Report control - an Outlook 2000 style SuperGrid Report Control", here in The Code Project.
My problems so far are:
a. Maarten Hoeben's solution is way over the top for me, when I already have an existing application with a ListCtrl and HeaderCtrl already working (except for this extra feature!).
b. The CDialogBar solution is very neat and looks great but it is based on CFrameWnd, which contains things like OnBarCheck and OnUpdateControlBarMenu. My application is based on CDialog.
c. The standard CHeaderCtrl only supports Drag & Drop within the control - i.e. changing the order of columns by dragging and dropping. With the "Outlook" "Field Chooser" approach, I need to drag/drop columns from/onto the HeaderCtrl and the DialogBar.
Is this at all possible or am I asking the impossible?
All help gratefully received.
|
|
|
|
|
Hi,
I have this major issue, I have data coming into memory 200 times a second, this is filling up the RAM fairly quickly, so what I want to be able to do is read off past data that has already been stored, with out interrupting the writing of the new data from RAM. I was thinking a circular queue would do the trick but I'm not sure how to make sure that I do not lose any of the data being written to memory. The Reading can happen slower then the write, just as long as their is enough memory reserved which there will be.
Can anyone direct me to how I can achieve this. My main goal is to not lose any data but keep the reading going so that there is still enough memory for more frames to be loaded.
Thanks in advance.
|
|
|
|
|
Two threads, a reading thead and a writing thread, and std::queue. The writing thread pushes data onto the queue and the reading thread pops the data off the queue.
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
Hi,
I have been using Visual C++ 6.0 with MFC for a couple of years and have taught myself just enough to be dangerous. because of a new API that I need to use we are upgrading to Visual C++ 2005 (version 8.0). This is different enough to cause lots of confusion. Just looking for a good web site that will ease the transition of this change.
Buck Brown
|
|
|
|
|
|
i am new to multithreading in vc++, could u provide me some sites address where i can find tutorials to learn from basics.
|
|
|
|
|
l_d wrote: could u provide me some sites address where i can find tutorials...
Here is one such site.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
thanks to both of you,they are really helpful.
|
|
|
|
|
I glad they are helpful;)
|
|
|
|
|
Hello,
Does anyone know an easy way to stop the horizontal scrolling of the first (maybe the 2 first) columns in a CListView / CListCtrl. What I want is something that we can do in Excel with Window - Fix (hope, I translated correct). I have some text in the first 2 columns and many values in many other columns - and the text should always be visible.
I tried the whole day to find an article, but I didn't succeed. So any help would be great.
Thank's, Gerhard
|
|
|
|
|
That isn't a feature of the list control, however you can try a grid control like Chris Maunder's control right here on CP.
|
|
|
|
|
Anyone know why the .push_back function for a vector would overwrite the last entry. So for example, if i push 10 items into the vector. When i am done, the vector size shows 10 but the only item in there is the last one. I am totally clueless on this.
I call this function in a dll:
DLL_API int GetDATA(std::vector& pVectorDataInfoRecName, std::string sPath )
Then i process a DataInfoRecName pointer.
_tcscpy( pDataInfoRecName->szDate, TempString.c_str ());
Then i push it into the vector
pVectorDataInfoRecName.push_back(pDataInfoRecName);
|
|
|
|