|
Most of the C++ string classes will include a member function that will return a pointer to a simple character buffer of a specified length. You pass that to the function, and then release the buffer afterward.
I use the MFC CString class myself, which has member functions GetBufferSetLength() and ReleaseBuffer() for this purpose.
I would imagine the STL string class has something like this.
Software Zen: delete this;
|
|
|
|
|
I have a button with BS_CHECKBOX style and text.
I want to center the checkbox with my dialog so
I need to get the "real" width of the control
(Checkbox + gap + text = full width).
I know how to get the width of the text part
but how do I get the width and height of the
checkbox itself?
I looked at GetSystemMetrics and SystemParametersInfo
but didn't find any. Any ideas where to look at?
The width of the gap between is also needed.
I need a plain WinAPI solution that works on all versions
of Windows (not XP only).
Thanks in advance, Sebastian
-------------------------------------------
My website: http://www.hartwork.org
-- modified at 1:03 Sunday 5th March, 2006
|
|
|
|
|
More searching taught me that SM_CXMENUCHECK and
SM_CXMENUSIZE seem to be what I was looking for.
So my new problem is how do I tellGetTextExtentPoint32
to work with the new font and not the default one.
Here's my code:
const TCHAR * const szNeverAgain = TEXT( "Do not ask again" );
SendMessage( hNeverAgain, WM_SETFONT, ( WPARAM )GetStockObject( DEFAULT_GUI_FONT ), ( LPARAM )TRUE );
const HDC hdc = GetDC( hNeverAgain );
SIZE size;
GetTextExtentPoint32( hdc, szNeverAgain, _tcslen( szNeverAgain ), &size );
ReleaseDC( hNeverAgain, hdc );
size.cx is always the width for the old font.
I need the new one - any ideas?
-------------------------------------------
My website: http://www.hartwork.org
|
|
|
|
|
Select a font into the DC before calling GetTextExtentPoint32 . e.g.
const TCHAR * const szNeverAgain = TEXT( "Do not ask again" );
SendMessage( hNeverAgain, WM_SETFONT, ( WPARAM )GetStockObject( DEFAULT_GUI_FONT ), ( LPARAM )TRUE );
HDC hdc = GetDC( hNeverAgain );
HFONT hOldFont = (HFONT)SelectObject(hdc, hYourFont);
SIZE size;
GetTextExtentPoint32( hdc, szNeverAgain, _tcslen( szNeverAgain ), &size );
SelectObject(hdc, hOldFont);
ReleaseDC( hNeverAgain, hdc );
Steve
|
|
|
|
|
This is it! It works!
I'm so happy - Thank you very much!
Best regards, Sebastian
-------------------------------------------
My website: http://www.hartwork.org
|
|
|
|
|
Btw in case you are the author of SpeedLoad - good work!
-------------------------------------------
My website: http://www.hartwork.org
|
|
|
|
|
Yeah I'm to blame for SpeedLoad. Thanks for your kind words.
Steve
|
|
|
|
|
Create a variable for the check box.
And call GetWindowRect
Mythili
|
|
|
|
|
No. The problem is the width can be much more than
the text in it actually needs. If I want to center
the checkbox I need the width of what the user sees,
not the width of the window rect.
Best regards, Sebastian
-------------------------------------------
My website: http://www.hartwork.org
|
|
|
|
|
What is modal loop?
Thanks in advance.
|
|
|
|
|
Running a message pump means a loop something like the following:
MSG m;
while ( GetMessage(&m, NULL, 0, 0) )
{
DispatchMessage(&m);
}
There are many variations but the code above captures the essence of every message pump.
A modal window is window that has to be dismissed before any other windows in the app can be used. This is normally done by creating a top level owned window, disabling the owner and then running a message loop. This is what people mean when they talk about a modal loop. Note the message pump need not be explicit. For example the DialogBox family of functions run a message pump. It is important to remember that, taking the DialogBox as an example, while the modal dialog is displayed we're inside the DialogBox function and when it returns the modal box has been destroyed.
Steve
|
|
|
|
|
You must be an expert on computer science. I very appreciate your help, thanks a lot.
I'm a beginner
|
|
|
|
|
I'm studying MSDN.net 2003 and see some words below.
"Subclassing the window does not work for messages set between processes."
These words occurred at the section "About Hooks" whereas I can't understand it.
Does it mean if we subclass a window and do something in the associated wndproc with many messages which would also be processed in the hook procedure will make the subclassing work un-regular?
Can you explain it for me?Thanks in advance.
////////////////////////////////////////
hello guys!
|
|
|
|
|
It means you can't subclass a windows from another process (a guess).
Steve
|
|
|
|
|
When you subclass a window, it means you are replacing that window's window procedure (the function that Windows calls when it has a message for the window) with a function of your own. Subclassing is used to modify the normal behavior of a message.
Hook procedures can be used to do the same kind of thing. In the hook procedure you can alter the message to change the behavior. Unfortunately, if a Windows message involves a pointer of any kind (for example, to a string), the pointer (an address in memory) only has meaning inside the process from which it originates.
Software Zen: delete this;
|
|
|
|
|
Hey,
So I'm throwing together a little program that will append another file with just one line of text. Everything seems to run smoothly, except that the program which I want to access the file (Firefox), doesn't recognize the changes.
If I open up notepad, the line has been added, and only once I save the file from inside notepad does Firefox regognize the change.
To write to the file, I'm just using a simple fopen, fwrite combonation. My code is as follows:
FILE *host;<br />
host = fopen("file", "a");<br />
fwrite(ipAdd, ipAdd.GetLength(), 1, host);<br />
fclose(host);
Like I said, everything executes properly, and I can that the line has been appended to the file, it's just that Firefox doesn't regognize it. (Even after restarting Firefox.)
Any suggestions would be greatly appreciated.
Nicky
|
|
|
|
|
|
Still doesn't regognize the change. I may be wrong, but I'm pretty confident Firefox isn't the problem.
Any other suggestions?
Thanks,
Nicky
|
|
|
|
|
I know nothing about Firefox, but if it is accessing the same file then the problem is with Firefox. Normaly I would shut down the program and restart it, to see if it reloads the new version, if that does not work, then I shut down my computer and see what happens when I try again. If it still does not recognise the chages, then you are acessing to different files.
INTP
Every thing is relative...
|
|
|
|
|
Like I said in my first post, even after restarting Firefox (closing and reopening), the file still isn't recognized. I haven't tried restarting the my computer, but that really wouldn't be practical, even if it worked.
I think the most important thing is that if I open the file in notepad, and simply save it again (not making any changes), the changes are regognized. Any thoughts on why this would be?
Nicky
|
|
|
|
|
hey,
i have a ulong and i need to convert it to uint. how can i do this? i'm guessing this is pretty simple. i've searched google but i just get a ton pages showing how to do conversions in c# and vb.
thanks in advance,
sam kline
-- modified at 19:21 Saturday 4th March, 2006
|
|
|
|
|
unsigend long x = 100;
unsigned int y = (unsigned int)x;
this will do. But why do you want to convert long to int. long is 64bits and int is 32 so it will get truncated.
|
|
|
|
|
Acutaly it depends on the compiler, in VC6 they are both 32bits. An int is supposed to be the size of a register word, but in reality it is up to the creators of the compiler.
INTP
Every thing is relative...
|
|
|
|
|
yea long is 32-bit in vc. I must have been sleeping when replying
|
|
|
|
|
I'd do it like this:
static_cast<uint>(your_ulong)
C style casts (a type in brackets) are a major haste and should be avoided - This is the reason C++ added the const_cast , dynamic_cast , static_cast and reinterpret_cast keywords.
I'm sure there will be people who disagree but I would wager they haven't had to spend weeks hunting down some obscure bug caused by a bad cast which is almost invisible in the source code.
Steve
|
|
|
|