|
Quote: One thing it is not good using malloc in C++ apps is because the class ctor is not called.
well I`m not really chasing the perfect solution, to be honest I haven`t even got to use the feature that much until now, my projects were simple enough to go about without using new/malloc
Again huge thanks for helping me sort this out.
modified 18-Mar-22 16:36pm.
|
|
|
|
|
I have an update. This is a function for inserting nodes in the middle of the list. Is this a good approach? I did a quick test and it looks like it`s doing what it should.
void InsertTo(SomeNode ** FrontTip, int NewNodeData, int InsertInFrontOfNodeCount, int TotalNodeCount)
{
SomeNode * Temp;
SomeNode * NewNode;
SomeNode * Previous;
NewNode = (SomeNode*)malloc(sizeof(SomeNode));
NewNode->data = NewNodeData;
bool firstrun = true;
for(int i =0; i < TotalNodeCount;i++)
{
if(i == InsertInFrontOfNodeCount)
{
NewNode->next = Temp;
Previous->next = NewNode;
}
else
{
if(firstrun)
{
Temp = (*FrontTip)->next;
firstrun = false;
}
else
{
Previous = Temp;
Temp = Temp->next;
}
}
}
}
|
|
|
|
|
Just a few more things on top of what Victor said:
1. Typically the chaining structure comes before the payload (the data part). That allows you to have different sizes of objects in your list without having to modify the list management code.
2. Again in the typical case, the function that creates or extends the list (BuildList function in your example) receives a structure containing the list head and tail. That way you can easily add new elements at either end and this is the most common operation.
3. In general you should be very, very, very sure that you need to use a linked list. Linked lists perform poorly because they don't make good use of cache. For a longer discussion about this see Bjarne Stroustrup: Why you should avoid Linked Lists - YouTube[^] and also Are lists evil? -- Bjarne Stroustrup : Standard C++[^].
Mircea
|
|
|
|
|
CalinNegru wrote: Could someone confirm I`m doing it the way I`m supposed to. Maybe you meant to phrase it differently, but what is the "supposed to" way to which you refer? There are multiple ways to code a linked list, and only you know what goal(s) you are trying to meet.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
It`s just a first time linked list implementation experience, I want to know if I`m not doing foolish things.
Quote: There are multiple ways to code
I knew there is more than one approach when writing a linked list, but is there `that` many ways to do it?
|
|
|
|
|
hi
Below is the code I have for Drawing a Pie give a percentage thing is it looks nice and I traced a percent of 10.000 however calculation of x & y are negative and it ends up (the pie) being on the left side of the circle
Wondering if I am doing anything wrong after getting to 2 CPoints and I do a CDC:Pie
CPie::CPie(double percentage, PieWnd *pieptr)
{
piecalc(pieptr->currpercent, &piepointstart, pieptr);
piecalc(percentage, &piepointend, pieptr);
pieptr->currpercent = percentage;
}
CPoint *CPie::piecalc(double percent, CPoint *firstpt, PieWnd *pieptr)
{
double PI = 3.1415926535897931;
double angle = percent / 100;
angle = angle * 360;
CRect pierect;
double radius = pieptr->ellipserect.Height() / 2;
double offx = (radius * sin(angle));
double offy = (radius * cos(angle));
double origx = (pieptr->ellipserect.right + pieptr->ellipserect.left) / 2;
double origy = (pieptr->ellipserect.top + pieptr->ellipserect.bottom) / 2;
firstpt->x = origx + offx;
firstpt->y = origy + offx;
return firstp
|
|
|
|
|
Try this:
angle = percent / 50 * PI
Mircea
|
|
|
|
|
or I think I can divide the radius rect.right - rect.lef2 / 2 thank it worked
|
|
|
|
|
How to compress IPv6 address using VC++
|
|
|
|
|
|
Hi
I have few questions about the above two items first for the EDITWORDBREAKPROCA if my edit control is part of CRicheditCtrl does the callback proc have to be a member of the Cricheditctrl
or can it be like my STEAMIN function
if the callback is a class member how would you code the sendmessage when I code CrichEditctrl->Sendmessage(EM_SETWORDBREAKPROC,0,(LPARAM) &CStroage::editworbreak) I get complier messages saying invalid type conversion
Next do I need a message map entry for EM_EDITWORDPBREAKPROC such as ON_MESSAGE(EM_EDITWORDBREAKPROC,&CStroage::editwordbreak) if so there is a problem with this because the ON_MESSAGE takes a LRESULT MEMBERX (wparam, lparam) not the paraamter of the call back
in the Call back if I want to line break 0n 0x0a0d
then the code would be the following the doc is not that stright forward thanks in advance for anyone who helps me clarify
switch (code)
{
case WB_ISDELIMITER:
if (lpszEditText[ichCurrent] == 0x0a0d)
return TRUE;
else
return FALSE;
break;
|
|
|
|
|
This "header" to you're lengthy on-going (no sarcasm here ... I too use MS VS) battle with AFX/MFC uses Rich Edit 2.0? And that is why there's no EditWordBreakProcEx and you're usg EditWordBreakProc "in support of passing UNICODE" (from the docs)?
|
|
|
|
|
quite honestly dont know what you are saying
|
|
|
|
|
"from the docs" ... the help files. See the Main Menu help button? F1 (on an unknown method/function/etc has always been my friend when it came to the docs).
modified 10-Mar-22 16:01pm.
|
|
|
|
|
1. No, the callback method is a function in your application, and nothing to do with the control. Information between the two is passed via the system.
2. As far as I can see there is no such message as EM_EDITWORDPBREAKPROC so no, you do not add it to the message map. And if you think about it, that would not make sense. Once you register your callback with the system the edit control will call it automatically whenever the specific conditions trigger the event.
3. Callback methods need their address to be computed at build time. So if it is a class member it needs to be a static method.
4. In the line
if (lpszEditText[ichCurrent] == 0x0a0d)
you are looking for the two characters, but that may not be correct. You should use the debugger to check exactly what character(s) are being pointed at.
And finally, yes the documentation is not always completely clear, but it is always worth reading in its entirety: EDITWORDBREAKPROCA (winuser.h) - Win32 apps | Microsoft Docs[^].
|
|
|
|
|
Richard
thank you for responding
This is my code
storagepointer->SendMessage(EM_SETWORDBREAKPROC, 0, (LPARAM)(EDITWORDBREAKPROC)EditWordBreakProc);
long numstream = storagepointer->StreamIn(SF_TEXT,STORAGESTREAM);
this is the callback
int CALLBACK EditWordBreakProc(LPTSTR lpszEditText, int ichCurrent, int cchEditText, int code)
{
char FAR* lpCurrentChar;
int nIndex;
int nLastAction;
switch (code)
{
I have the call back declared all the way at the begining of my .cpp file I made a breakpoint at entry of the call back and it never got control
I tried the SendMessage with a &EditWordBreakProc and also tried the sendmessage after the streamin
Thankx
int CALLBACK EditWordBreakProc(LPTSTR lpszEditText, int ichCurrent, int cchEditText, int code);
|
|
|
|
|
What does storagepointer point to; it should be the RichEditCtrl?
|
|
|
|
|
yep
this is at the start of my OninitDialog before Calling the CDailog::OnInitDialog
storagepointer = new CRichEditCtrl;
|
|
|
|
|
I have created a similar test (although not MFC), and it appears to work. Remember that the callback will not get called until the edit control is trying to reformat some text to fit in the window. I tested mine just by dragging the right hand edge to make the window narrower. As soon as a word needed to be broken, the callback got actioned.
|
|
|
|
|
Richard thanks for the help
let me explain my problem I am trying to dump data from my z/os machine on a editctrl the data has 0x0a ns 0x0d and 0x0c causing a break where I dont want to
I do have a 0x0a 0ad to break a line.
need to think If I can use the wordbreak to resolve this issue
thanks
|
|
|
|
|
I do not think that is what you need. The EDITWORDBREAKPROC function is only called at the point where the control needs to decide whether to split a word or not. Searching for line break characters is a different issue and will depend on exactly how you are trying to reformat it.
|
|
|
|
|
Richard
I have to think if there is a way to drive the callback proc before I display the data let me explain the data is in the following format
2E000 XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX * * from the 2E000 till the first * is hex data in printable format so O know for sure there is no any 0x0a x0d or x0c line feed between the two * there might be
I am just trying to think if there is a way of drving the callback as from what I understand it gives the user the ability to decide when to line break need to think about it
thanks
|
|
|
|
|
But as I mentioned above, the callback is only actioned when the control is trying to update the display, and a word cannot fit in the existing space. If you do not register a callback then the control will use spaces between words and existing line break sequences.
Your issue quite different as far as I understand it, but it is not clear what you are trying to achieve in your text display.
|
|
|
|
|
I am trying to display storage from my Z/os Server in the following format a 32 bit address in printable format which is 8 bytes then 16 bytes of storage in printable format 4 groups 4 bytes separated by spaces then within * * the raw hex data at this point i would like to line break
I have to look at the streamin says
The control calls the callback function repeatedly, transferring a portion of the data with each call. just wondering if each call would be a line
need to think
|
|
|
|
|