|
How about do it like that :
COleDateTime ct = COleDateTime( 2003, 12, 31, 23, 59, 59 );
int iNumWeeks = atoi( ct.Format( "%U" ) );
|
|
|
|
|
Hi !
please use the <pre> HTML tags (see Formatting bar under your sig when writing a message) to format your code instead of bold. It is far more readable.
~RaGE();
|
|
|
|
|
I am building a project.I want to write something to registry to save some informatiom.
|
|
|
|
|
Who can give me a sample or a demo?
|
|
|
|
|
Use RegOpenKey, RegQueryValue, RegCloseKey.
You can look for sample code in MSDN, or you can search Google for a whole lot of sample code
You might also find some code on CP
"It was when I found out I could make mistakes that I knew I was on to something."
-Ornette Coleman
|
|
|
|
|
Here are some code snippets, which you may use :
//////////////////////////////////////////////////////
CString GetFromRegistry( CString csRegKeyString, CString csRegKeyField, CString csDefault )
{
CString csResult = csDefault;
CRegKey* pRK = new CRegKey();
LONG lRegOpen = pRK->Open(HKEY_LOCAL_MACHINE, csRegKeyString);
if(lRegOpen == ERROR_SUCCESS)
{
char cValue[1000];
memset( cValue, 0, sizeof( cValue ) );
DWORD dwSize = sizeof( cValue );
LONG lRegQuery = pRK->QueryValue( &(cValue[0]), csRegKeyField, &dwSize );
if(lRegQuery == ERROR_SUCCESS) csResult = cValue;
}
delete pRK;
pRK = NULL;
return( csResult );
}
//////////////////////////////////////////////////////
BOOL SetInRegistry( CString csRegKeyString, CString csRegKeyField, CString csValue )
{
BOOL bResult = FALSE;
CRegKey* pRK = new CRegKey();
LONG lRegSetValue = pRK->SetValue( HKEY_LOCAL_MACHINE, csRegKeyString, csValue, csRegKeyField );
if(lRegSetValue == ERROR_SUCCESS) bResult = TRUE;
delete pRK;
pRK = NULL;
return( bResult );
}
I think there are a lot of complete classes here at codeguru. Use the code above only as an example how you may do it.
Best regards
|
|
|
|
|
|
csc wrote:
I think there are a lot of complete classes here at codeguru.
Codeguru? Don't you mean CodeProject?
|
|
|
|
|
Hi
Anyone can tell me how to lock CD-rom drive
Give some code as eg.
GO ON KIDDING
|
|
|
|
|
In MSDN,KB138434,there's some code to demo this.
|
|
|
|
|
Who can tell me how to change the height of CComBox.
the function CComboBox::Create(..rect.) only modify the size when the
control is dropped down.
gucy
|
|
|
|
|
|
Dave:
First thands a lot,SetItemHeight works very well.
But another question is that how can i change the font size of the ccombobox,i created the control in source file instead of in source view control.i put the control on the toolbar instead of on dialog box.
Can you help me further?
gucy
|
|
|
|
|
Something like:
CFont* pOldFont = m_combo.GetFont();
LOGFONT lf;
memset( &lf, 0, sizeof(LOGFONT) );
pOldFont->GetLogFont( &lf );
CClientDC dc( m_combo );
lf.lfHeight = -MulDiv( PointSize, dc.GetDeviceCaps( LOGPIXELSY ), 72 );
CFont* pNewFont = new CFont();
pNewFont->CreateFontIndirect( &lf );
m_combo->SetFont( pNewFont );
Dave
http://www.cloudsofheaven.org
|
|
|
|
|
Is it Ok (good practice) to include headers within other header files ?
I have a CTimer Class declared in TimerClass.h and implemented within TimerClass.cpp.
I have a CAnimatedSprite class declared in AnimatedSprite.h and implemented within AnimatedSprite.cpp.
Is it alright for the AnimatedSprite.h to #include "TimerClass.h" and for the AnimatedSprite.h to have as a class member CTimer AnimationTimer; ?
Is there a requirement for the CTimer to be a friend of CAnimatedSprite ?
Responses much appreciated,
Wodger
|
|
|
|
|
There is no problem having includes within includes, and they really should be there if the file won't compile without them.
You do not need to make CTimer a friend of CAnimatedSprite just to make it a member variable. You only need a friend class when it needs to access protected/private members of another class.
Dave
http://www.cloudsofheaven.org
|
|
|
|
|
You should always minimize inclusion of headers in other headers, especially on larger projects as you get unnecessary compiles on the slightest change. Read "Large Scale C++ Design" (I think that is the title) for a very informative and in depth discussion of the many problems here.
Try not to make CTimer a member, but instead use CTimer* then you can forward declare CTimer (eg. class CTimer;) and hide its implimentation from the AnimatedSprite.h file. ie. It only needs to be visible in AnimatedSprite.cpp Read about PIMPL and look at Boost Smart Pointers www.boost.org[^]
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Cheers, Thanks and Superb to both of you.
I'm not quite sure what you mean wrt CTimer* (Newbie Alert)
// AnimatedSpriteClass.h
// Doesn't the statement
CTimer* pSpriteTimer;
// require the TimerClass header to create a pointer to one ?
// No: because it is not initialised ?
// AnimatedSpriteClass.cpp
// Then when I define the InitSprite(int x, int y, int CurrentAnimSequence);
// do I initialize the Ctimer pointer to an instance of the CTimer ?
pSpriteTimer = new CTimer;
// will that do the trick ?
// Cheers,
// Wodger
|
|
|
|
|
Anonymous wrote:
Cheers, Thanks and Superb to both of you.
It is a pleasant change to get a thankyou - thanks for that.
Anonymous wrote:
CTimer* pSpriteTimer;
No is correct. You would include:
class CTimer;
in the .h before the class definition. You need to ensure that you don't define any functions in this .h that call CTimer functions, otherwise you are back to needing CTimer.h In other words write this functions in the .cpp. If you need inline functions for speed then put them in a .inl.
Anonymous wrote:
pSpriteTimer = new CTimer;
Yes. But I'd suggest doing this in the AnimatedSpriteClass constructor and the delete pSpriteTimer; in the destructor. Better still using either an STL auto_ptr or Boost scoped_ptr. eg. In the .h
boost::scoped_ptr<CTimer> pSpriteTimer;
and in the constructor:
pSpriteTimer.reset( new CTimer );
Then you don't need to delete pSpriteTimer and can rest assured that it will be cleaned up if an exception occures etc.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Hi,
I'm learning C++ and have the MS Developer Studio C++ V4.2 installed.
Can anybody tell me how to define a project with the demo files I downloaded from this site to produce an executable program? What are the settings/options when I create a project workspace? How to incorporate the downloaded files?
Thanks in advance,
Ulrich
|
|
|
|
|
Have you tried double-clicking on the .dsp file (the project file), which should open devstudio.
It should also ask you if you want to create a workspace for the project.
|
|
|
|
|
double-clicking on the .dsp file opens devstudio and opens the .dsp file in the editor, that's all
|
|
|
|
|
Vc++ is being used for automating winword report generation using ole automation. The reports are based on predefined templates. How can we convert the same report to other languages using ole automation in vc++. Ex: English reports to French.
Thanks in advance.
|
|
|
|
|
Hi, is there anyway to prevent the ALT F4? so my window can't be shutdown like that?
If not, is there anyway to "hide" my window from the list of windows which pops op when won presses ALT-TAB.
Thanks for any help.
|
|
|
|
|
Intercept the WM_CLOSE message and return false. If you are using MFC, goto classwizard and add WM_CLOSE message handler to that particular window and remove the CDialog::OnClose() statement.
Harsha
----------------------------------
http://www.ece.arizona.edu/~hpg
----------------------------------
|
|
|
|