|
I'm not in disagreement, but I do not know what it would be. If you find out, it would make for a good CP article.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
|
I have an issue where I have a function that takes an HDC and draws to it. Instead of just displaying the data in a window, I want to write it to a bitmap file. I don't want to show the window at all, so I'm hoping that I can do this with a hidden window some how. I've tried calling GetCurrentBitmap() on the CDC object and that did not give me a valid bitmap. I also tried the following:
hDC = GetDC(hDCWnd);
hBmp = CreateCompatibleBitmap(hDC, 500, 500);
SelectObject(hDC, hBmp);
MyFuncToDraw(hDC);
CBitmap* bitmap = CBitmap::FromHandle(hBmp);
but that only gave me a blank bitmap. Does anyone have any idea how I can get a valid CBitmap so I can save it to a file? Is this even possible??
-- Rocky Dean Pulley
-- DreamSys Software
-- http://www.dreamsyssoft.com
|
|
|
|
|
You need to create a memory dc
hDC = GetDC(hDCWnd);
// create the memory dc
HDC hdcMem = ::CreateCompatibleDC(hDC);
hBmp = ::CreateCompatibleBitmap(hDC, 500, 500);
// select the bitmap into the memory device context instead
HBITMAP hbmpOld = (HBITMAP)::SelectObject(hdcMem, hBmp);
// pass the memory dc handle instead
MyFuncToDraw(hdcMem);
CBitmap* bitmap = CBitmap::FromHandle(hBmp);
... after done
::SelectObject(hdcMem, hbmpOld);
::DeleteDC(hdcMem);
|
|
|
|
|
Ok, here's what I'm trying, it's just giving me a blank (black) 500x500 bitmap:
CDC memDC;
memDC.CreateCompatibleDC(GetDC());
CBitmap *bmp = new CBitmap();
bmp->CreateCompatibleBitmap(&memDC, 500, 500);
CBitmap *old = memDC.SelectObject(bmp);
CRect rc(0, 0, 500, 500);
memDC.FillRect(rc, new CBrush(RGB(0, 255, 255)));
memDC.TextOut(50, 50, "BLAH");
//This stuff writes the bitmap and I know that it works.
HANDLE hDib = DDBToDIB(*bmp, BI_RGB, NULL);
WriteDIB("c:\\test\\testbmp.bmp", hDib);
memDC.SelectObject(old);
I have also tried to put the "memDC.SelectObject(old);" line before the bitmap writes and it gives the same problem. I know that the bitmap writing code works, I've used it before on CBitmaps just fine, so I'm sure that the problem exists in this drawing code somewhere. This code is being run from a CDialog, so that's where the GetDC() comes from.
-- Rocky Dean Pulley
-- DreamSys Software
-- http://www.dreamsyssoft.com
|
|
|
|
|
|
How can i change the circle to a diamond in radio button?
I use MFC.
When I chose the owner draw style and painted the radio button to diamond style one, I don't get the button be checked in the normal default way!
What can I do?
|
|
|
|
|
Besides BS_OWNERDRAW , what other style(s) does the button have?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Hi all,
HFONT CreateFont(
int nHeight, // height of font
int nWidth, // average character width
int nEscapement, // angle of escapement
int nOrientation, // base-line orientation angle
int fnWeight, // font weight
DWORD fdwItalic, // italic attribute option
.. .
..
)
I have an option in UI for the user to select Font Size 8 to 72 as in winword. I would like to know how to give this value to create font's height and width parameter.
Ex: suppose user selects a font size of 12, what is the corresponding nHeight and nWidth value..Is there any conversion required ??
Can somebody throw more light on this..
Thanks,
Shiva P
|
|
|
|
|
Set height as follows...
nHeight = -MulDiv(PointSize,
GetDeviceCaps(hDC, LOGPIXELSY), 72);
nWidth = 0;
- NS -
|
|
|
|
|
we r working on file transferring in vc++(without using MFC).when we send small size of file(approx 250- 350 kb).there is no problen in sending.but when we send large file through our program there is some problem to geting in server side.means that there is some additonal bytes added by server program and some time it will hang.
if we debug this program there is no problem it sends successfully big file too.
here another problem that is
we are reading /writing a structure using fread/fwrite. it convert it into binary file. so when we reading the file fread function doesnot read specified bytes or sometimes unable to read.
we have more problem to read / write Structure using fread/fwrite is there any alternate of these fun in c/C++.
plz send us solution or suggession soon.
|
|
|
|
|
Hello.
It's a possibility that your problem depends on that you are using text mode in your fopen()-calls.
Make sure you use fopen("anyFile", "rb"); and fopen("anyfile2", "wb");
The 'b' is the key here. (The default mode usually is text mode, which seens unusable in your application).
Regards
kakan
|
|
|
|
|
manishgandhi wrote:
when we send large file through our program there is some problem to geting in server side.means that there is some additonal bytes added by server program and some time it will hang.
if we debug this program there is no problem it sends successfully big file too.
How are you sending file from client to server? i.e. in Small packet or whole file at a time!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
I need information on ADPCM sound format. Microsoft seems not to love it any more.
I need:
- file header format
- code samples
- links to documentation
We are trying to use it in a project written in C++ (mixed-mode, both managed and unmanaged code
Any ideas?
harrykouk
|
|
|
|
|
http://www.wotsit.org/ has specs on RIFF, which is related to ADPCM. Would that help?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Respected All
I am engaged with filereading problem since long time, i readed the file but still problems are coming.
the dat file is in the following form.
-----------------------------------------
;sfad
;sdlfgs
;sdfjsd
;X Y Index
12 12 1233
34 45 1244
66 44 2435
45 23 3455
;fgksdghkdfhgdf
;dflghfd
23 67 6788
23 45 2334
-------------------------------------
now in the above file format i has to read only the lines that's starting without SEMICOLON and all the lines starting eith SEMICOLON has to skipp.and also while reading each line of the file I has to put the X,Y and Index value in seperate Array and the same process will be repeated each time for X,Y and Index value.
my code script is following
---------------------------------------
int val1,val2,val3;
int row=0;
char str4[50];
pfile=fopen("filename.dat",r)
do
{
fgets(str4,sizeof(str4),pfile);
if(str4[0]!=';')
{
fscanf(pfile,"%d",val1)
arr1[row]=val1;
fscanf(pfile,"%d",val2)
arr2[row]=val2;
fsacnf(pfile,"%d",val3)
arr3[row]=val3;
row++
}
while(!feof(pfile))
fclose(pfile);
-----------------------------
its reads all the data correctly but when there is a SEMICOLON in the start of the line then its skipp the next one line(immediate lines) and reads after it.
in the above case it skipp the line
12 12 1233
and
23 67 6788
because before these two lines there was a SEMICOLON line and due to it skipp the immediate lines.
and except these 2 lines it reads all the lines accordingly,
I dont know why this problem is coming,, pls guide me that what is the best method in this case while i am reading the above file format.
waiting for + response.
david
|
|
|
|
|
Hi,
There shdnt be any problem with this ....
But u can use the other way ....
#include <"fstream.h">
void main(void)
{
char *str4 = new char[50];
ifstream Inputfile("filename.dat",ios::in);
Inputfile.getline(str4, '\n');
....
....
....
Inputfile.close();
delete str4;
}
i hope the problem will be solved
|
|
|
|
|
Mukhan wrote:
char *str4 = new char[50];
Why allocate memory from the heap unnecessarily?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
a_david123 wrote:
fgets(str4,sizeof(str4),pfile);
if(str4[0]!=';')
{
fscanf(pfile,"%d",val1)
You are reading a line from the file into str4, but then you don't actually use it. Instead, you keep reading from the file using fscanf... That's why your program skips lines. Use sscanf instead of fscanf, with a format like "%d %d %d".
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
This has been shown to you many times in the past.
int row=0;
char str4[50];
pfile=fopen("filename.dat", "r");
do
{
fgets(str4, sizeof(str4), pfile);
if (str4[0] != ';')
{
sscanf(str4, "%d %d %d", arr1[row], arr2[row], arr3[row]);
row++;
}
} while(! feof(pfile));
fclose(pfile);
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
i am trying to find an instance of a small bitmap in a screen grab of a window.
so far i have managed to load both bitmaps into two BYTE arrays. I found some code which searches through the bitmaps and uses memcmp to see if the smaller one is present in the larger. the trouble is, i am having trouble with the memcmp function:
memcmp(ScreenBmp[i][tmpY],CardBmp[x], card_line_length )
What should ScreenBmp and CardBmp represent. I have the two bitmaps in BYTE buffer arrays, so how can i get them into the format above. The code i used to get them into these arrays is below:
HANDLE hBitMap = LoadImage(0, "img.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
BITMAP bitmap;
GetObject(hBitMap,sizeof(BITMAP),&bitmap);
int size = bitmap.bmHeight*bitmap.bmWidth*bitmap.bmBitsPixel/8;
/// cout << bitmap.bmHeight << endl;
BYTE *lpBits = new BYTE[ size ];
GetBitmapBits((HBITMAP)hBitMap,size,lpBits );
//delete []lpBits;
HANDLE hBitMap2 = LoadImage(0, "img2.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
BITMAP bitmap2;
GetObject(hBitMap2,sizeof(BITMAP),&bitmap2);
int size2 = bitmap2.bmHeight*bitmap2.bmWidth*bitmap2.bmBitsPixel/8;
/// cout << bitmap.bmHeight << endl;
BYTE *lpBits2 = new BYTE[ size2 ];
GetBitmapBits((HBITMAP)hBitMap2,size2,lpBits2 );
cheers!
|
|
|
|
|
cmon bitches help the guy out
|
|
|
|
|
Hello All
I am using "CXListCtrl" in my application. I want to hide and show columns depending on the user selection, with some data (5 rows of data) present in the list control.
I am using "DeleteColumn" and "InsertColumn" to remove and add column
When I do "InsertColumn" a new column is added in the Header Control, in the location what i specify. When I tried to update the data for newly inserted column, progress bar is displayed and not my data.
If I try to insert 2 new columns, Columns are getting added in Header Control but in the Column values "Progress Bar" and "Check Box" are shown.
When I debugged I see the code where I update the data to corresponding new columns are getting executed correctly. After this code the following fucntion is getting called
CXListCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
inside the function "(pXLCD && (pXLCD[nSubItem].bShowProgress))" is true so the following portion of the code gets executed, so Progress control is displayed!
if (pXLCD && (pXLCD[nSubItem].bShowProgress))<br />
{<br />
DrawProgress(nItem, nSubItem, pDC, crText, crBkgnd, rect, pXLCD);<br />
*pResult = CDRF_SKIPDEFAULT;
}<br />
Any Idea what is the problem?
Thanks in advance
- Ravi
|
|
|
|
|
I have an application that allows the user to bookmark different locations in a video. It saves the video images at the bookmarks. There is a listbox that shows all the bookmarks. Double-click on the listbox will bring the video to the selected bookmark position. But I'm unable to bring out the save image and display onto a picture control. I tried using CBitmap and CStatic but still unable to get the images out. I have already recode this portion dozens of times.
main problem: Getting the picture to be display. (I'm able to get the full path to the selected picture)
Can someone offer me advice on how to solve this?
Thanks
|
|
|
|
|
What format are the saved images in?
If they are BMP,JPEG,GIF you can use the OLE picture support to render them, and you could derive from CStatic to make your own picture box, or use something like the one from MSDN done by Paul DiLascia (spelling?)
Steve S
Developer for hire!
|
|
|
|
|