|
Chris Losinger wrote: but it's really handy to people who want to use the function.
especially when you have more than one parameter with the same type (as seen in our code)
void f(int, int, double, double, int, int& );
void f(int a, int b, double aa, double bb, int g, int& r){}
This signature was proudly tested on animals.
|
|
|
|
|
Hello,
EliottA wrote:
& int x;
int & x;
int &x;
The first one is plainly illegal.
The second and third have no difference between them. Ideally, I would prefer the third one to avoid any confusion while declaring multiple variables in the same statement. But while you are declaring such a reference variable, you *must* initialize it properly by specifying which variable is it referring to. Unless which, you won't get it to compile.
If a function takes a parameter in by reference (as opposed to 'by value'), any changes made to the variable passed in will reflect on the original variable passed while making the function call (similar to pointers, but the syntax is much cleaner).
This might help you:
void FuncRef(int &n)
{
n = 0;
}
void FuncNormal(int n)
{
n = 4;
}
void _tmain(int argc, _TCHAR* argv[])
{
int i = 10;
int &Ref = i;
cout<<Ref<<endl;
Ref = 2;
cout<<i<<endl;
FuncRef(i);
cout<<i<<endl;
FuncNormal(i);
cout<<i<<endl;
}
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Hi,
I have two values say "rakesh,gender" parsed into a cstring object(say obj = "rakesh,gender") from a file..(say notepad)..
In my application, they have used Trimright() and Trimleft() functions for this obj;
I changed my notepad file as unicode (before it was ANSI) now..
After passing those two functions (trimright and trimleft), its showing the obj with one square box at the beginning..("(square box)rakesh,gender");
How to remove the square box??
Can anyone guide me how to solve this issue?
Thanks,
Rakesh
|
|
|
|
|
It seems you trimmed using ANSI functions over a UNICODE string or viceversa
If Trimleft and Trimright are from CString , verify your project has been compiled for UNICODE (see the project properties). Also, verify that no ANSI to UNICODE translations are attempred while reading the file by the fucntions.
To have a check, just do a per-step debug and look how the string is represented in meory just after the reading is finished, with a ASCII only text (saved as UNICODE).
It should be "xx 00 xx 00 xx 00 xx ..... " where xx a two hex digits.
If it is "00 xx 00 xx 00 xx" probably you saved also a BOM or you saved with the wrong endianess (it is an option of the format, during "Save As" - something like UTF-16LE or UTF-16BE: 80x86 use LE format).
If it is "xx xx xx xx xx" it has been read as ANSI.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
Hi,
im drawing a char inside Crect variable...and if the Font size of the char is increased then how can i increase the rect size based on the change in Font size of char ...
|
|
|
|
|
kumar sanghvi wrote: ...how can i increase the rect size...
Have you looked at the CRect methods such as InflateRect() ?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
You may use, for instance, GetTextExtentPoint32 [^].
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]
|
|
|
|
|
ya..using GetTextExtentPoint32 ill get the width and height of the char..but how can i inflate the rect proportionally...may be should i inflate by the diff by which the char is changed...
Please correct me if im wrong..
|
|
|
|
|
When you know the geometric dimensions of your string then you may change the rectagle size accordingly (for instance, if your string has dimensions {w,h} then the rectangle maybe {w+b, h+b} where b is a fixed border, or, {w*(100+bp)/100, h*(100+bp)/100} where bp is a proportional border).
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]
|
|
|
|
|
Thanks for ur reply...
but how can i get the fixed border "b" or proportional border "bp"....
|
|
|
|
|
Well, suppose the text width is 120 pixels and the height is 20 pixels, then, a rectangle with a fixed, 5 pixels, border would have width = 120 + 2*5 = 130 pixels and height 20+2*5 = 30 pixels.
If you prefer a proportional border, say 5% , you may set width = 120*(100+5*2)/100 = 132 pixels and height = 20*(100+5*2) = 22 pixels.
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,
I am relatively new to working with Visual Studio/VC++. My requirement is to display an animation (AVI or AGIF) in a dialog control. This works fine. But what I also want is that when the dialog window screen is maximized, this animation (running in the dialog) should also resize/maximize accordingly. When the screen returns to normal position, the animation should also return to its normal size. Is is possible to do this? Right now, I'm only able to maximize the screen and not the animation (The animation is retaining its size). Please help!
|
|
|
|
|
You need to resize the control that play the animation manually; I assume when it resizes, it will resize the movie automagically.
This signature was proudly tested on animals.
|
|
|
|
|
I am able to resize the control. I have used EASYSIZE macro with the control's ID. So, the control is getting resized. But the animation still remains of the same size. (Is this what you mean by resizing manually or are there any other settings/changes?)
|
|
|
|
|
which control using to play AVI/AGIF?
If using CAnimateCtrl then ACS_CENTER is set?
u can use the below mentioned APIs for any control to resize.
use MoveWindow or SetWindowPos
to resize the control according to change in size of parent Window.
http://msdn.microsoft.com/en-us/library/ms633534(VS.85).aspx[^]
Величие не Бога может быть недооценена.
modified on Wednesday, July 29, 2009 9:19 AM
|
|
|
|
|
Yes, I have set ACS_CENTER and I have used SetWindowPos. This helps me resize the control. But the image being displayed on the control does not resize. I am not sure if resizing the 'image' is even possible.
|
|
|
|
|
Hi, I want to draw a Hindi text with a bounding box around. Sample text "मैं हिन्दी नहीं बोल सकता हूँ।".
The problem is the last character with dependent vowel sign, the method misses the bottom part of the text.
0x0939, 0x0942, 0x0901 (devanagari letter ha, vowel sign uu, sign candrabindu)
C# code sample
string text = "मैं हिन्दी नहीं बोल सकता हूँ।";
Font font = new Font("Tahoma", 20.0f, FontStyle.Regular);
SizeF layoutArea = new SizeF(1000, 1000);
StringFormat stringFormat = new StringFormat();
SizeF measure = g.MeasureString(text, font, layoutArea, stringFormat);
g.DrawRectangle(Pens.Red, new Rectangle(50, 50, (int)measure.Width, (int)measure.Height));
g.DrawString(text, font, Brushes.Black, 50, 50);
I have also tried C++ functions GetTextExtentPoint32(), GetTextMetrics() and GetOutlineTextMetrics() to get the correct height but failed.
Any suggestions?
Thanks in advance,
Gywox
|
|
|
|
|
Whats the output with GetTextMetrics API?
what is font height with that?
if is not correct then let me ask u whether u tried this given below:-
Hope u calculate it
height = Internal Leading + ( Point Size * LOGPIXELSY )/72
For more details please refer
http://support.microsoft.com/kb/74299[^]
Величие не Бога может быть недооценена.
modified on Wednesday, July 29, 2009 8:48 AM
|
|
|
|
|
1/ I suppose this is semi legitimate to post in this forum. C# has failed you, so you're coming to ask help from the grown ups?
2/ For a text bounding box, I alway use DrawText (...., DT_CALCRECT).
ie:
CString s = L"मैं हिन्दी नहीं बोल सकता हूँ।";
CRect rc;
DrawText (s, &rc, DT_CALCRECT);
rc should be 0,0,width,height.
see: http://msdn.microsoft.com/en-us/library/ms901121.aspx[^]
Iain.
I have now moved to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need cotract work done, give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|
|
as Iain said,
if it done with DrawText then we cannot find the font height with GettextMetrices.
Величие не Бога может быть недооценена.
|
|
|
|
|
Hi all,
Thanks for the feedback.
I have tried your suggestions but no success.
Here is my code.
Gdiplus::Bitmap *pBitmap = NULL;
Gdiplus::Graphics *pGraphics = NULL;
Gdiplus::Pen penRed(Gdiplus::Color(255, 255, 0, 0));
Gdiplus::Font gdiFont(_T("Tahoma"), 80, 0, Gdiplus::UnitPixel);
CString text = _T("मैं हिन्दी नहीं बोल सकता हूँ।");
LOGFONTW logFontW;
Status status;
CRect rectBondary1(50, 50, 1000, 1000);
CRect rectBondary2(50, 50, 1000, 1000);
pBitmap = new Gdiplus::Bitmap(1024, 1024, PixelFormat32bppARGB);
pBitmap->SetResolution(96.0F, 96.0F);
pGraphics = Graphics::FromImage(pBitmap);
pGraphics->Clear(Gdiplus::Color(255, 0, 0, 0));
status = gdiFont.GetLogFontW(pGraphics, &logFontW);
HFONT hFont = ::CreateFontIndirect((LOGFONTW *)&logFontW);
HDC hDC = pGraphics->GetHDC();
HGDIOBJ hOldObject = SelectObject(hDC, hFont);
int result = DrawText(hDC, text, -1, rectBondary1, DT_CALCRECT);
result = DrawText(hDC, text, -1, rectBondary2, 0);
SelectObject(hDC, hOldObject);
DeleteObject(hFont);
pGraphics->ReleaseHDC(hDC);
pGraphics->DrawRectangle(&penRed, rectBondary1.left, rectBondary1.top, rectBondary1.Width(), rectBondary1.Height());
CLSID pngClsid;
GetEncoderClsid(_T("image/png"), &pngClsid);
pBitmap->Save(_T("test.png"), &pngClsid, NULL);
if (pGraphics)
delete pGraphics;
if (pBitmap)
delete pBitmap;
Help method.
int CTextRenderAnalyzeDialog::GetEncoderClsid(const WCHAR *pFormat, CLSID *pClsid)
{
UINT uiNumber = 0;
UINT uiSize = 0;
ImageCodecInfo *pImageCodecInfo = NULL;
GetImageEncodersSize(&uiNumber, &uiSize);
if(uiSize == 0)
{
return -1;
}
pImageCodecInfo = (ImageCodecInfo *)(malloc(uiSize));
if (pImageCodecInfo == NULL)
{
return -1;
}
GetImageEncoders(uiNumber, uiSize, pImageCodecInfo);
for (UINT uiIndex = 0; uiIndex < uiNumber; ++uiIndex)
{
if (wcscmp(pImageCodecInfo[uiIndex].MimeType, pFormat) == 0)
{
*pClsid = pImageCodecInfo[uiIndex].Clsid;
free(pImageCodecInfo);
return uiIndex;
}
}
free(pImageCodecInfo);
return -1;
}
|
|
|
|
|
Hello
How to GetHandle of Window from Resource ID in ATL COM
Thanks
ABM
|
|
|
|
|
CWnd* pWnd = GetWindow( RESOURCE_ID );
HWND hwnd = pWnd->m_hWnd;
Величие не Бога может быть недооценена.
|
|
|
|
|
In addiont to the other reply, if you have a parent window handle, and a window ID (which may or may not have anything to do with resources, but mostly does):
HWND hChild = ::GetDlgItem (hWndParent, nID);
Class win 32.
Iain.
I have now moved to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), or need cotract work done, give me a job! http://cv.imcsoft.co.uk/[ ^]
|
|
|
|
|
The project:
I wrote a program Ahook that hooks the keyboard and mouse events appear in the system and send them to other target application – the Paint which is not in focus and is in background window (i don't want it to be in focus and want it to be in the background). It means that I can for example move and use the mouse anywhere on the desktop or on any other application, but the Paint program will be operated as like the mouse was moving over it.
How it is done:
The Ahook uses the follow function to hook all keyboard and mouse events:
hHook=SetWindowsHookEx(WH_JOURNALRECORD,journalRecordProc, AhookInstance,0);
In order to send the messages to the Paint, the Ahook uses the follow function:
PostMessage(hPaintWnd, message,0, (iNy<<16) + iNx);
iNx and iNy are normalized mouse location values -means, I change the real location of the mouse to a location that is on the Paint program.
Results and problem:
I used the Spy++ to check the operation of all this and the Paint program receives all events Ahook sends. The location of the mouse as Paint sees is ok, means that paints "thinks" that the mouse is moving on it. But there is problem – the Paint program doesn't react to the events although it receives them. Why???
a) Is it because Paint is not in focus?
b) Is it because the messages found by WH_JOURNALRECORD hooked are not the relevant for sending to the Paint getmessage loop ?
c) Is there any other reason?
Some more information that may lead to conclusion:
a) Looking the Spy++ results for events Paint sees when Ahook sent it, shows very simple events such as WM_MOUSEMOVE and WM_LBUTTONDOWN etc.
b) Looking the Spy++ results for events received when mouse is used on the Paint, shows that the messages are much more complicated than just mouse move and mouse button down/up. It contains WM_NCHITTEST, WM_SETCURSOR, WM_NCMOUSEMOVE (but not WM_MOUSEMOVE) etc, is it says that what Ahook sends is not the relevant information???
Thansk
|
|
|
|
|