|
How can you talk about portability if you are using Unix's flock()? I doubt this function is in the ANSI standard.
Best regards,
Alexandru Savescu
|
|
|
|
|
oh... good point. sorry, didn't want to say that Unix way good, Windows bad.
Let me ask for a portable way - or - a way to do file access locking on Windows when using fopen()? Thanks in advance.
|
|
|
|
|
You may do this:
#ifdef WIN32
#else
#endif
Best regards,
Alexandru Savescu
|
|
|
|
|
May I ask for an short example how I use CreateFile together with fopen?
|
|
|
|
|
Hi,
I am using Visual C++ version 6.0 and am having an interesting compiler bug. Maybe someone has experienced this before. I also have Service Pack 5.0 (Is it the most recent?) installed, but does not help.
I have declared a variable in CMainFrame. This variable is of the type CMyClass.
When I compile my code, the compiler complains about the variable I have declared. What I do next is to comment out the variable I have declared and re-compile. The compiler then complains about lines of code using the now commented out variables.
The next step is to re-declare the variables previously commented out and re-compile. And voila, the compiler now has no errors. It is then possible to run my application and it works fine.
The problem I now have is that I would like to compile the code in Release Mode. But the above-mentioned trick does not work now.
This is because the compiler compiles all files in Release mode whenever a change is made and not only changed files as in Debug mode.
So, my question now is: Has anyone seen this before and do they have a solution?
Thanks
Regards
Rui
Rui
|
|
|
|
|
Ruca wrote:
So, my question now is: Has anyone seen this before and do they have a solution?
I had it yesterday, and a clear/rebuild all solved the problem, in Release Mode. I´ve already observed that this kind of situation comes up every now and then when using own defined classes object, such as CMyClass MyObject .
A few other tricks to solve extraterrestrial compiler bugs:
- Be careful not to have included files which are not in the file browser (solution: delete the
#include or add the corresponding files with Add Files to Project) - Watch if you are not making changes to a file which as the same name as a file which is in your project, but which is actually in another directory
...
~RaGE();
|
|
|
|
|
I had once a stranger bug. The compiler generated different code depending on some comments placed at different positions (the same comments, not different piece of code commented) and that difference influenced a bug.
Most of the times a rebuild and a restart fixes problem. Also, if the same thing happens when compiled on 2 different machines then there is a problem with your code, if not it's the compiler.
Best regards,
Alexandru Savescu
|
|
|
|
|
Thanks for your comments Alexpro and Rage. You gave me the determination to solve the problem. I definitely thought it was a compiler bug, which I did not care too much about because I could get around it. But when I tried to compile in Release Mode, the workaround did not work anymore.
After reading your comments I started to try new things and found that I had a circular include, i.e. I included file A in B and B in A (although not as simple as that). After sorting this out, the problem was resolved.
Thanks once again
Regards
Rui
|
|
|
|
|
Hi,
I have a property sheet, from one ATL control, when the user presses enter the property sheet is closed ( ), I need to handle the enter key to do other operation ( and of course avoid closing the Property sheet), How can I skip the Enter key for the property sheet? ( in ATL there is no Pretranslatemessage... ).
Thanks in advance, Greetings
Braulio
|
|
|
|
|
Hello, folks,
I got some trouble on sorting items in my CListCtrl. That is, I have a list control (i.e, of type CListCtrl), and this list control has 4 columns.
I want to sort the items on this list control by a given column (i.e, clicking the column header on the GUI of this list control.)Now, I found some sample codes from MSDN but I don't understand. I posted the MSDN sample as follows.
My question is: where and how to pass the 2 parameters (lParam1 and lParam2) to the callback function ?
Because I don't know the sample code has something to do with passing 2 parameters (lparam1 and lparam2) to the callback function (MyCompareProc).
And, this MyCompareProc callback function just compares 2 items ? If my list control has more than 2 items, what is the mechanism about this compare function ? And how can I use this callback function to sort many many items in my list control ?
Thanks for your help ! Any response would be greatly appreciated !
Example
// Sort the item in reverse alphabetical order.
static int CALLBACK
MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
// lParamSort contains a pointer to the list view control.
// The lParam of an item is just its index.
CListCtrl* pListCtrl = (CListCtrl*) lParamSort;
CString strItem1 = pListCtrl->GetItemText(lParam1, 0);
CString strItem2 = pListCtrl->GetItemText(lParam2, 0);
return strcmp(strItem2, strItem1);
}
void snip_CListCtrl_SortItems()
{
// The pointer to my list view control.
extern CListCtrl* pmyListCtrl;
// Sort the list view items using my callback procedure.
pmyListCtrl->SortItems(MyCompareProc, (LPARAM) pmyListCtrl);
}
|
|
|
|
|
Hello,
try this !
::SendMessage(pmyListCtrl->GetSafeHwnd(), LVM_SORTITEMS, (LPARAM)this, (LPARAM)(PFNLVCOMPARE)CRightView1::MyCompareProc);
Marco
|
|
|
|
|
You will never call by youself MyCompareProc().It is called by SortItem which internaly implement some kind of sorting algoritm witch need to have a way to compare 2 elements.
So your list may have any number of elements ...
Bye,
Orbital^
...the night is long ... but not long enought to do some real coding ...
|
|
|
|
|
Hi again,
here a snipit from MSDN:
The comparison function has the following form:
int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2,
LPARAM lParamSort);
The lParam1 parameter is the 32-bit value associated with the first item being compared, and the lParam2 parameter is the value associated with the second item. These are the values that were specified in the lParam member of the items' LVITEM structure when they were inserted into the list. The lParamSort parameter is the same value passed to the LVM_SORTITEMS message.
U have to fill the params associated with the items/subitems first.
For instance, pointer to the DataClass instance. Then u can get/compare
everything from inside the class.
I had implemented today, and this is the fastest and easiest way to do
sorting in a listcontrol.
Marco
|
|
|
|
|
>>U have to fill the params associated with the items/subitems first.
>>For instance, pointer to the DataClass instance. Then u can get/compare
>>everything from inside the class.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Thanks ! I have tried it.
But I still got some problems on this lParam1 and lParam2.
That is, when I implement the Compare Function just like the sample from MSDN,
as follows:
int CALLBACK CSortListCtrl::CompareFunction(LPARAM lParam1, LPARAM lParam2, LPARAM lParamData)
{
CSortListCtrl* pListCtrl = reinterpret_cast<csortlistctrl*>( lParamData );
ASSERT( pListCtrl->IsKindOf( RUNTIME_CLASS( CListCtrl ) ) );
CString strItem1 = pListCtrl->GetItemText( lParam1, pListCtrl->m_iSortColumn );
CString strItem2 = pListCtrl->GetItemText( lParam2, pListCtrl->m_iSortColumn );
return strcmp(strItem2, strItem1);
}
I always got lParam1 and lParam2 the SAME !! That is, the Compare Function is always comparing the same thing ! (The first item always ! And I found the lParam1 and lParam2 are always 0 !!)
The following is how I added items to my list control:
/// m_CtrlEntryList is of type CSortListCtrl, which is also of type CListCtrl
//// add subitem 0 first
m_CtrlEntryList.InsertItem( iItemNo, szString );
LV_ITEM lvitem;
ZeroMemory( &lvitem, sizeof( lvitem ) );
/// then add subitem 1 ~ 3
lvitem.mask = LVIF_TEXT;
lvitem.iItem = iItemNo;
lvitem.pszText = szString;
lvitem.iSubItem = iSubItemNo;
lvitem.lParam = iItemNo; // <------ I DO specify this lParam
m_CtrlEntryList.SetItem( &lvitem );
I used something like above to add items to my list control, and it really worked and displayed fine. I don't know why when I get them compared, the 2 parameters passed to compare function are always 0.
Anything wrong ?
|
|
|
|
|
I found one sample for sorting list control on this web site. The URL is:
http://www.codeproject.com/listctrl/sortlistctrl.asp
And, I have also tried his codes. His codes are fine and I found he did "Add Items" to his list control something like this:
/// CSortListCtrl is derived from CListCtrl
int CSortListCtrl::AddItem( LPCTSTR pszText, ... )
{
//..... skipped
VERIFY( CListCtrl::SetItem( iIndex, iColumn, LVIF_TEXT, pszText, 0, 0, 0, 0 ) );
///... skipped
}
Why not just use something like:
this->SetItem( iIndex, iColumn, LVIF_TEXT, pszText, 0, 0, 0,0 ) ); ???
So, I should use something like CListCtrl::SetItem(.....) to add my items ?
|
|
|
|
|
Hello,
try to use "SetItemData()" instead of "xx.lParam=xx".
Marco
|
|
|
|
|
Thanks ! It really helps. Now the 2 parameters passed in are different.
But, I still got trouble on sorting result. The sorting result is very weird.
I have traced in my compare function and I thought it should get the right result but actually it doesn't.
My Compare function is something like the following:
int CALLBACK CSortListCtrl::CompareFunction(LPARAM lParam1, LPARAM lParam2, LPARAM lParamData)
{
int r = 0;
CSortListCtrl* pListCtrl = reinterpret_cast<csortlistctrl*>( lParamData );
ASSERT( pListCtrl->IsKindOf( RUNTIME_CLASS( CListCtrl ) ) );
CString strItem1 = pListCtrl->GetItemText( lParam1, pListCtrl->m_iSortColumn );
CString strItem2 = pListCtrl->GetItemText( lParam2, pListCtrl->m_iSortColumn );
if ( pListCtrl->m_bSortAscending ) // ascending sort
r = strcmp( strItem1, strItem2 );
else
r = strcmp( strItem2, strItem1 );
return r;
}
I have tested an original sequence of alphabet of a specified column like:
M, H, D, V (4 chars)
If ascending sort on 1st time, it would get right result like: D, H, M, V
but when next time I want to sort descendingly, it is wrong !! (i.e, the sequence is NOT V, M, H, D, but something else instead. )
And another run of ascending sort, it got another weird sequence again !!
(I have modified adding items to something like the following:
/// insert sub-item 0
m_CtrlEntryList.InsertItem( iItemNo, szString );
/// insert sub-items 1~3
m_CtrlEntryList.SetItem( iItemNo, iSubItemNo, LVIF_TEXT, szString, 0, 0, 0, 0 );
/// as you suggested, this lParam should be unique, right ?
m_CtrlEntryList.SetItemData( iItemNo, ( DWORD ) iItemNo );
|
|
|
|
|
What exactly is the difference between a dialog box and a form? Why would one use the one and not the other?
|
|
|
|
|
By a form do you mean Winforms, or an SDI/MDI app ? A dialog does not allow you to have floating toolbars, nor does it support doc/view. A dialog is best for simpler apps, or apps that do not use doc/view.
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
Sorry, stupid of me..
I meant to ask why one would choose to derive a class from CFormView instead of CDialog. My fellow programmer asked me and I realized I have no idea why one would need to use CFormView at all. We are both new at Visual C++ programmers and there are still many holes that need filling.
|
|
|
|
|
No worries - I should have realised. The answer is the same - floating toolbars, doc/view, etc, all useful for a more complex app, but a CFormView allows you to mix that with designing a window full of controls in the resource editor.
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
thank you!
|
|
|
|
|
I want to have a line in 80th column of my view which is derived from CView. This is to be used as an 80th column marker. I will be grateful to you if anybody can help me in solving this problem.
|
|
|
|
|
You're going to have to draw it in the erasebackground call, the issue is figuring out where it is, if you have a non-fixed width font.
Christian
come on all you MS suckups, defend your sugar-daddy now. - Chris Losinger - 11/07/2002
|
|
|
|
|
Sir,
I cannot find anything called erasebackground function anywhere in vc++. Can you suggest me a similar function which i can use with my view which is derived from CView. My exact problem is like this. Suppose, I am drawing a line at 80th column, and if I am increasing the font size, the line comes to some 30th or 35th column and not 80th column. This I want to update on change of the font size. I have a function OnChangeFont() which will be executed when user changes the font.
Thank You and expecting a positive reply.
Krishna Raj.
|
|
|
|
|