|
~Khatri Mitesh~ wrote: I am new to Win-32 C++
I see, then you want to become familiar with this[^]
|
|
|
|
|
To further clarify what Cedric said, you first get a device context, select the font you be using into it and then all GetTextExtent(). (This may sound obvious to experienced developers, but the failure to select the font is a common mistake.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Hi everyone
I'm stuck with the code which renders a preview of a Camera using VFW.
The thing is that i want to do TextOut on this image within FrameCallback,
but the textout comes some kind of a bottom-up ?
The idea is to store avi sequence with a text drawn inside (generally a date).
Here is the code:
I enumerate available devices, and connect to the one i choose.
Then i do
BOOL SetVideoFormatRGB()<br />
{<br />
DWORD size = capGetVideoFormatSize(ghWndCap);<br />
<br />
if ( size <= 0 )<br />
{<br />
<br />
return FALSE;<br />
}<br />
<br />
void* pBuffer = new BYTE[size];<br />
BITMAPINFO* pBitmapInfo = (BITMAPINFO*) pBuffer;<br />
<br />
if ( capGetVideoFormat(ghWndCap, pBuffer, size) <= 0 )<br />
{<br />
<br />
return FALSE;<br />
}<br />
<br />
pBitmapInfo->bmiHeader.biBitCount = 24;<br />
pBitmapInfo->bmiHeader.biCompression = 0;<br />
pBitmapInfo->bmiHeader.biSizeImage = pBitmapInfo->bmiHeader.biWidth * pBitmapInfo->bmiHeader.biHeight * 3;<br />
<br />
<br />
if ( ! capSetVideoFormat(ghWndCap, pBitmapInfo, size) )<br />
{<br />
<br />
return FALSE;<br />
}<br />
<br />
<br />
g_nBitCount = pBitmapInfo->bmiHeader.biBitCount;<br />
g_nBitsPerPixel = pBitmapInfo->bmiHeader.biBitCount;<br />
<br />
<br />
return TRUE;<br />
}
Next thing - i create a Callback for VFW:
capSetCallbackOnFrame(ghWndCap, (FARPROC)FrameCallbackProc);
And process each frame :
<br />
LRESULT PASCAL FrameCallbackProc(HWND hWnd, LPVIDEOHDR lpVHdr)<br />
{ <br />
<br />
if ( g_nBitCount != 24 )
return 0;<br />
<br />
<br />
if ( ! g_hFrameBitmap )
return 0;<br />
<br />
BeginPaint(hWnd,&ps);<br />
<br />
<br />
<br />
SetBitmapBits(g_hFrameBitmap, g_nImageWidth*g_nImageHeight*3, lpVHdr->lpData);<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
SetBkMode(g_hFrameDC,TRANSPARENT);<br />
SelectObject(g_hFrameDC, FONTmain);<br />
SetTextColor(g_hFrameDC,RGB(0,0,0));<br />
hPen = CreatePen(0, 1, RGB(210,210,210));<br />
SelectObject(g_hFrameDC, hPen);<br />
Rectangle(g_hFrameDC, 0,0, 320,100);<br />
TextOut(g_hFrameDC,2,2,"AAAAAAAAAAA",10);<br />
<br />
GetBitmapBits(g_hFrameBitmap, g_nImageWidth*g_nImageHeight*3, lpVHdr->lpData);<br />
<br />
<br />
<br />
EndPaint(hWnd,&ps); <br />
return (LRESULT)true;<br />
}
This code does the trick but all i draw on g_hFrameBitmap is bottom-up, so point:
0,0 is on the bottom left side of whole image. The string "AAAAA..." also comes
bottom up.
g_hFrameBitmap is created as:
<br />
void CreateGraphicObjects(HWND hWnd)<br />
{<br />
<br />
g_hFrameDC = CreateCompatibleDC(GetDC(hWnd));<br />
<br />
<br />
<br />
<br />
memset(&lpbi, 0, sizeof(lpbi));<br />
lpbi = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER) + (256 * sizeof(RGBQUAD))];<br />
lpbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);<br />
lpbi->bmiHeader.biWidth = g_nImageWidth;<br />
lpbi->bmiHeader.biHeight = -240;<br />
lpbi->bmiHeader.biPlanes = 1;<br />
lpbi->bmiHeader.biBitCount = 24;<br />
lpbi->bmiHeader.biCompression = BI_RGB;<br />
lpbi->bmiHeader.biSizeImage = WIDTHBYTES((DWORD)g_nImageWidth * 8) * g_nImageHeight;<br />
lpbi->bmiHeader.biXPelsPerMeter = 0;<br />
lpbi->bmiHeader.biYPelsPerMeter = 0;<br />
lpbi->bmiHeader.biClrUsed = 0;<br />
lpbi->bmiHeader.biClrImportant = 0;<br />
<br />
<br />
<br />
g_hFrameBitmap= CreateDIBSection( <br />
NULL,
lpbi,
DIB_RGB_COLORS,
(void **)&pBits,
NULL, <br />
0 ); <br />
<br />
<br />
delete[] lpbi;<br />
SelectObject(g_hFrameDC, (HBITMAP)g_hFrameBitmap);<br />
<br />
<br />
}<br />
Any chance to get this resolved? I've tried to pass negative values to bitmap header - no luck.
Best reagards!
|
|
|
|
|
Hi,
The line: lpbi->bmiHeader.biHeight = -240; indicates, by the used of a negative value, that this is a top-down bitmap. That is 0,0 is at the top-left corner. You say you'd tried to "pass negative values to bitmap header", did you mean by altering the sign of this? If this is the case when you then say "no luck" do you mean the video did'nt change from top-down to bottom-up or the text stayed displayed as: "some kind of bottom-up?
I have come across 'fixes' to get bitmaps/video displayed 'the right way up' in the past. These only tend to come to light when further work is done. Are yuu sure there is'nt such a fix somewhere you are not looking?
|
|
|
|
|
Hi again,
On browsing through some of my code I came across:
int OldMode = ::SetMapMode(hCrossesDC, MM_TEXT); Could this be what you need?
|
|
|
|
|
Jonathan,
yes i have altered the
lpbi->bmiHeader.biHeight = -240;
to +240 and -240 - but this does not make any change.
The TextOut 0,0 position is at bottom left side of the video preview and the letters
are drawn bottom-up.
I will look at your above code later on to see if this sorts this out.
Many thanks for your reply!
|
|
|
|
|
Damn still nothing.
Have a look at this screen below:
http://www.fileden.com/files/2009/3/19/2370332/image.jpg
After applying SetMapMode(g_hFrameDC, MM_TEXT); - still the same issue.
Look at the TEXTOUT - it is rendered as:
TextOut(g_hFrameDC,2,2,"AAAAAAAAAAA",10);
And comes bottom-up in the wrong coordinates... ://
|
|
|
|
|
Still noone?
So how do they do that in other capture video programs?
It is just a matter of adding a Label to the video stream and it is such a pain?
Damn ;/
|
|
|
|
|
Ok,
below is the screenshot of my application. You can see the camera stream on the left side of the window and the TextOut results.
http://www.fileden.com/files/2009/3/19/2370332/aaa.jpg
And the code below:
BeginPaint(hWnd,&ps);
SetBitmapBits(g_hFrameBitmap, g_nImageWidth*g_nImageHeight*3, lpVHdr->lpData);
SetBkMode(g_hFrameDC,TRANSPARENT);
SelectObject(g_hFrameDC, FONTmain);
SetTextColor(g_hFrameDC,RGB(0,0,0));
hPen = CreatePen(0, 1, RGB(210,210,210));
SelectObject(g_hFrameDC, hPen);
Rectangle(g_hFrameDC, 0,0, 320,20);
TextOut(g_hFrameDC,2,2,"AAAAAAAAAAA",10);
GetBitmapBits(g_hFrameBitmap,320*240*3,lpVHdr->lpData);
EndPaint(hWnd,&ps);
|
|
|
|
|
Hi All
Suppose I've a class
Class Parent
{
public:
virtual void V();
};
Class Child: public Parent
{
public:
void V();
}
main()
{
Child obj;
obj.V();
}
Q:-If we create a derive class object and call the function V(), is is runtime polymerphisim?
Regards
Phillip
|
|
|
|
|
No. That would be only compile time binding that happens.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Nope.
The following code use polymorphism:
void main(void)
{
Parent * p = new Child();
p->V();
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
thank you very much. I faced this question in an interview and replied same answer. But i was confused wheather my ans is correct or not.
Regards
Phillip
|
|
|
|
|
Cool_Phillip wrote: I faced this question in an interview and replied same answer.
Well, now we're two: on statistical grounds, it should be an almost conclusive proof...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi all,
i want to assign a hyperperlink for send mail with use of static control.
i want when i move mouse on the static control hand cursor displayed.
when i clicked over it than mail window open and here mail address in To field and some subject in subject field,and some body text display in body of mail.
please tell me how can i do this.
thanks in advance.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
|
when i clicked over it and than close the mail window and again clicked over it than its gives error and becomes not responding and close tha application.
and this comes when i run my application on VISTA
please help me for this.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
modified on Monday, March 23, 2009 7:05 AM
|
|
|
|
|
Download the source and single step through the code.
I'm sure you will find what the problem is.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
I m downlad the code and check it but i m not find error please help me.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
Hi there.
Lets say I have created a file as below...
#include <stdio.h>
int main ()
{
FILE * pFile;
int n;
char name [100];
pFile = fopen ("myfile.txt","w");
for (n=0 ; n<3 ; n++)
{
puts ("please, enter a name: ");
gets (name);
fprintf (pFile, "Name %d [%-10.10s]\n",n,name);
}
fclose (pFile);
return 0;
}
Now, my requirement is, each and every time I write a name into the file, i want to delete the previous name.
So, at a time I want to have just one name in the file.
Please suggest.
Thanks & Regards
PanB
|
|
|
|
|
It seems you are doing it the right way. Opening a file using fopen with "w" as the parameter creates an empty file for writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file.
but since you are writing in the for loop the contents are written such that the file contains all the three names or names equal to the number of iterations
You need to google first, if you have "It's urgent please" mentioned in your question.
_AnShUmAn_
|
|
|
|
|
What i want to do is, at one point I just want to have one entry in the file. If you run attached program, you will find three entries in the same.
|
|
|
|
|
Instead of opening the file once at the begining, you could simply open it in your loop. Thus, each time you open it, the previous contents are deleted. Don't forget to close it afterwards.
|
|
|
|
|
Why do you want the loop, if you want only 1 name in the file.
And if you really want the loop, put the fopen and fclose inside the loop.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
The code was just a sample code... I want to update some information lets say for more than 1000 times, so dont you think that will an overhead? I think better option will be deleting contents amd updating the same with the updated information. Please suggest.
|
|
|
|
|