|
kuleen wrote: how to convert afl to c
What is "afl"?
Australian Football League?
|
|
|
|
|
Probably be rewriting it.
|
|
|
|
|
I'm setting a CTreeCtrl item item font to Italic by handling the NM_CUSTOMDRAW message and setting the font with SelectObject.
This is working.
void MyTree::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
{
NMTVCUSTOMDRAW *itemToDraw = reinterpret_cast<NMTVCUSTOMDRAW*>>(pNMHDR);
switch (itemToDraw->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
*pResult = CDRF_NOTIFYITEMDRAW;
return;
case CDDS_ITEMPREPAINT:
{
HTREEITEM item = reinterpret_cast<HTREEITEM>(itemToDraw->nmcd.dwItemSpec);
if (!m_IsItalicFontCreated) {
CFont* currentFont = GetFont();
LOGFONT logfont;
currentFont->GetLogFont(&logfont);
logfont.lfItalic = TRUE;
m_ItalicFont.CreateFontIndirect(&logfont);
m_IsItalicFontCreated = true;
}
if (m_IsItalicFontCreated)
{
::SelectObject(itemToDraw->nmcd.hdc, m_ItalicFont);
*pResult = CDRF_NEWFONT;
}
}
return;
}
*pResult = 0;
}
But at some point I need to check an item current font; to see if a tree item is in italic.
The CTreeCtrl's item data (CTreeCtrl::SetItemData) is already used to hold data for each item.
Is it possible to do it ? I can't see in the documentation anything I can use.
There is a lItemlParam in the NMCUSTOMDRAW struct, I'm not certain if I could use this to some some simple data ? or even if it is persistent.
Any suggestions ?
Thanks.
I'd rather be phishing!
|
|
|
|
|
You could implement the method in your MyTree class that would return true if italic font was created.
Something like
bool MyTree::IsItalicFontCreated()
{
return m_IsItalicFontCreated;
}
|
|
|
|
|
That only tells me the font is created, but not if it was set to one particular tree item.
I'd rather be phishing!
|
|
|
|
|
Maximilien wrote: The CTreeCtrl's item data (CTreeCtrl::SetItemData) is already used to hold data for each item.
You could extend your data adding the font type (create a struct containing all the necessary data and set the pointer to the struct instance as an ItemData)
|
|
|
|
|
Yes, I'm looking into that.
Thanks.
I'd rather be phishing!
|
|
|
|
|
Fighting to solve old plan C errors, I met another issue: error C2143: syntax error
I have the following code:
typedef struct test test_t;
struct test
{
const char* name;
const char* name_option;
...
...
};
and
test_t test_123 = {
.name = "Bibi", .name_option = "Bibi_One",
};
How can I get rig of this error ?
|
|
|
|
|
This form of initialization is valid in GNU C, and is valid in other compilers only if they support C99 or later. I don't remember off-hand whether this is supported in C++.
You can make this compatible with C89 by adding the missing initializers, e.g.:
test_t test123 = { "Bibi", "Bibi_one", foo, bar };
Where foo and bar are the values for missing members in the struct.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
Get rid of the member names in the initalization, it's not valid in C++. You can only pass values, and these will be used to initialize the members of the struct in the order of their definition. You don't need to provide values for all members - if you don't, the rest will use default values:
test_t test_123 = { "Bibi", "Bibi_One" }; Special case: if you try to initialize a C array in this manner with less values than it's size, the remainder of the array will be initialized with the last value of your initializer list. This code will initialize your entire array with 1s:
int my_array[9] = {1}; You can read up on this topic in many articles on the web, just use the correct search term: initializer list.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Thank you all of you, it works.
|
|
|
|
|
I have a legacy C code:
char* file_name[0];
which generate a warning: warning C4200: nonstandard extension used : zero-sized array in struct/union
it is correct to write:
char* file_name[_MAX_PATH];
? I don't know the impact of this modify...
|
|
|
|
|
_Flaviu wrote: it is correct to write:
char* file_name[_MAX_PATH];
Yes, it is correct presuming you are going to define the array of pointers
|
|
|
|
|
Or
char* file_name[1];
? anyway, is more than 0
|
|
|
|
|
Well, it all depends upon what you are going to achieve...
|
|
|
|
|
_Flaviu wrote: Or
char* file_name[1];
Yes.
The only reason someone would declare zero-length is to dynamic allocate the array. You should change the array length to [1]. If you change it to _MAX_PATH (260) then you will be wasting 1036 bytes on a 32 bit machine and wasting 2072 bytes on a 64 bit machine.
Wasting bytes is punishable by death.
Best Wishes,
-David Delaune
modified 6-Aug-19 5:37am.
|
|
|
|
|
Quote: You should change the array length to [1]
Quote: Wasting bytes is punishable by death
Take your own conclusions.
|
|
|
|
|
Hmmm,
The law states that wasting bytes less or equal to 1 * sizeof(pointer) is allowed but only in the month of August.
I guess he could remove the array qualifier but then that would probably break his compile.
Best Wishes,
-David Delaune
|
|
|
|
|
Disabling the warning is an option.
|
|
|
|
|
|
Thank you !
|
|
|
|
|
Quote: _MAX_PATH (260) then you will be wasting 236 bytes on a 32 bit machine and wasting 472 bytes on a 64 bit machine Hey David, the math there is not clear to me. Do I need more caffeine this morning?
|
|
|
|
|
CPallini wrote: Do I need more caffeine this morning?
No, but I do...
Best Wishes,
-David Delaune
|
|
|
|
|
If you are on C11 ... C11 6.7.9/14 allows the option
char file_name[];
It was addedd for exactly that reason
In vino veritas
|
|
|
|
|