|
Hi,
I think you should consider taking COleDatetime for this. Because you could either use GetCurrentTime or construct a new COleDateTime from your SYSTEMTIME structure.
Afterwards you can use the Format method to assign it to your CString.
example:
CString CLogger::GetCurrentDateTime()
{
COleDateTime dtCurrent = COleDateTime::GetCurrentTime();
return dtCurrent.Format ( _T("%d/%m/%Y %H:%M") );
}
or
CString CLogger::GetCurrentDateTime()
{
SYSTEMTIME stCurrent,stLocal;
GetSystemTime(&stCurrent);
SystemTimeToTzSpecificLocalTime(NULL, &stCurrent, &stLocal);
COleDateTime time ( stLocal );
return time.Format ( _T("%d/%m/%Y %H:%M") );
}
|
|
|
|
|
The GetBuffer method of CString is misused in your code.
you're asking a zero-length buffer to CString and filling it with (a non-zero number of) characters.
You've to ask for a larger buffer (or, and will be better, don't use at all the GetBuffer method).
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.
|
|
|
|
|
Just in case you were still wandering;), the reason you see the Date Time text in every uninitialised CString afterwards is that CString has a peculiar internal static member which represents the empty string. If you've overwritten this as it appears by overrunning the 0 length buffer returned from GetBuffer(0) then all CStrings which get auto initailised to this empty string will appear to contain the Date Time string.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
I have used the CListCtrl example 'LVCustomDraw' to create a list control with colored columns. This works fine until I add an imagelist (BITMAP) to the list control.
My class is derived from the CListCtrl class, and I use two functions 'OnEraseBkgnd' and 'OnCustomDraw' to color the alternate columns.
The list control and imagelist are defined in the dialog class header
...
CListCtrlEx m_ctlList;
CImageList m_cImageListNormal, m_cImageListSmall, m_cImageListState;
...
and the bitmap is add in the dialog class
...
// Create 256 color image lists
HIMAGELIST hList = ImageList_Create(32,32, ILC_COLOR8 |ILC_MASK , 8, 1);
m_cImageListNormal.Attach(hList);
hList = ImageList_Create(16, 16, ILC_COLOR8 | ILC_MASK, 8, 1);
m_cImageListSmall.Attach(hList);
// Load the large icons
CBitmap cBmp;
cBmp.LoadBitmap(IDB_IMAGES_NORMAL);
m_cImageListNormal.Add(&cBmp, RGB(255, 0, 255)); //m_colRow1
cBmp.DeleteObject();
// Load the small icons
cBmp.LoadBitmap(IDB_IMAGES_SMALL);
m_cImageListSmall.Add(&cBmp, RGB(255,0,255));
// Attach them
m_ctlList.SetImageList(&m_cImageListNormal, LVSIL_NORMAL);
m_ctlList.SetImageList(&m_cImageListSmall, LVSIL_SMALL);
...
The columns and items are then added.
I assume the default color of the list control is white, and the image is transparent, but when the background is redrawn, the image is not being 'refreshed', and hence it appears to have a white background.
I have noticed another example on CodeProject that has a similar result when the image is added.
Thank you
Steve
|
|
|
|
|
try calling the CImageList::SetBkColor() and then check whether the background has changed or not.
nave
|
|
|
|
|
I tried setting the background color in the OnInitDialog() function. No change ...
Next I tried
CImageList *img = (CImageList *) CListCtrlEx::GetDlgItem (IDB_IMAGES_SMALL);
ASSERT ( img != NULL );
but the return value of img is NULL.
|
|
|
|
|
Steve144 wrote: CImageList *img = (CImageList *) CListCtrlEx::GetDlgItem (IDB_IMAGES_SMALL);
What are you tryig to do?? To get the image list in a list control there is a function called GetImageList()...
nave
|
|
|
|
|
Oops - not a good bit of code ...
I have inserted the following code in the OnCustomDraw() function, and there is no change in B/G color of the listview image
CImageList *imgS = (CImageList *) CListCtrlEx::GetImageList ( LVSIL_SMALL );
ASSERT ( imgS != NULL );
CImageList *imgN = (CImageList *) CListCtrlEx::GetImageList ( LVSIL_NORMAL );
ASSERT ( imgN != NULL );
.....
case CDDS_SUBITEM | CDDS_PREPAINT | CDDS_ITEM:
{
imgS->SetBkColor ( RGB(225, 225, 225) );
imgN->SetBkColor ( RGB(225, 225, 225) );
|
|
|
|
|
Steve144 wrote: imgS->SetBkColor ( RGB(225, 225, 225) );
I think you want to change the white background of the image. But the above code will set the background of the image as white itself. Try using some other color say.
imgS->SetBkColor ( RGB(255,0,0) );// Red COlOR
nave
|
|
|
|
|
Nave,
The color is grey (225,225,225).
I have changed to red, but no change is B/G color of image
|
|
|
|
|
Is there any bluetooth hardware that has a keyboard and can control the computer remotely? And how can I program on the computer's side to get and interpret the signals from the bluetooth hardware as I need?
It's better if the computer can receive the original ditial voice data stream from the bluetooth hardware.
Thanks very much.
|
|
|
|
|
followait wrote: Is there any bluetooth hardware that has a keyboard and can control the computer remotely?
Have a look at this Bluetooth keyboard[^] from Logitech.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Hi guys,
I would like to ask, what is the event handler for dialog activation? I've tried OnActive but it doesn't seem to work. I just want a handler every time a dialog is activated.
I'd really appreciate any help or input.
Thanks!
Christina
|
|
|
|
|
waxie wrote: dialog activation
What do you mean by this?
Before the dialog window is shown to the user?
Perhaps CDialog::OnInitDialog() is what you're looking for.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Nope. Not on initial load. I was looking for an event handler every time the dialog is activated, or everytime the dialog goes active (may it be by clicking, or by some key strokes).
|
|
|
|
|
waxie wrote: I was looking for an event handler every time the dialog is activated
Ok. then it's the overridable OnActivate() . It will get called when the window is activated or deactivated. Don't forget to put it in the message map as well. If you add it with ClassWizard this will be done automagically for you.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
For clarification reasons, here's how to do it manually:
Add the message handler declaration for OnActivate() in you header file:
afx_msg void OnActivate( UINT nState, CWnd* pwndOther, BOOL bMinimized );
In your .cpp file, add the message handler to the message map...
ON_WM_ACTIVATE()
END_MESSAGE_MAP()
...and add the message handler implementation...
void <YourDialogClass>::OnActivate( UINT nState, CWnd* pwndOther, BOOL bMinimized )
{
TRACE( "OnActivate called.\n" );
}
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Just to be sure,what I did is I went to the dialog resource and looked for the message handlers in its properties and added a message handler for WM_ACTIVATE. Still no good though. The dialog (my dialog) is one of the tabs of a parent dialog. Would it matter?
|
|
|
|
|
Is your dialog a property page? If yes then try CPropertyPage::OnSetActive() .
cheers,
mykel
OMM: "Let us be thankful we have commerce. Buy more. Buy more now. Buy. And be happy."
|
|
|
|
|
Nope, it's not a property page. It's a tab page in a tabcontrol.
|
|
|
|
|
'ait... according to MSDN i recommend the following:
TCN_SELCHANGE Notification
Notifies a tab control's parent window that the currently selected tab has changed.
This message is sent in the form of a WM_NOTIFY message. check MSDN for further details, e.g. the handle to the tab control is passed with the notification. then i guess you can call CTabCtrl::GetCurSel() to get the currently selected tab.
cheers,
mykel
OMM: "Let us be thankful we have commerce. Buy more. Buy more now. Buy. And be happy."
|
|
|
|
|
waxie wrote: The dialog (my dialog) is one of the tabs of a parent dialog. Would it matter?
It depends on what you're trying to do.
My guess is that you want to know when the user selects another tab in the control.
If I guessed correctly and you're using CTabCtrl you have to write a message handler for the WM_NOTIFY message sent from the tab control with the TCN_SELCHANGE control code.
Use ClassWizard to add a message handler for this. Afterwards you message map should have an entry looking something like this:
ON_NOTIFY( TCN_SELCHANGE, IDC_TAB, OnTabChanged ) ...and a message handler looking similar to this:
void <YourDialogClass>::OnTabSelchange( NMHDR* pNMHDR, LRESULT* pResult )
Have a look att the MSDN sample FIRE[^] to see how it's done.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
These are just guesses but maybe it helps: Check WM_NCACTIVATE and also the Frame Window of the dialog (i hope CDialog has one)
CChildFrame::OnNcActivate(...) worked for me with CView based class in a MDI environment.
|
|
|
|
|
I also tried the above suggestions already, still no good.
Thanks for the replies though. I really appreciate them.
|
|
|
|
|
May be you are looking for OnShowWindow(BOOL ) or something like this will be called everytime the window is sabout to be shown or hidden.
|
|
|
|