|
* Level 0 2^0 = 1 node
/ \
/ \
/ \
* * Level 1 2^1 = 2 nodes
/ \ / \
* * * * Level 2 2^2 = 4 nodes
It is 2<sup>N</sup> for level N .
If you find written 2<sup>N-1</sup> then levels are numbered differently, starting from 1 (instead of 0 ).
|
|
|
|
|
Thanks for your reply I just get confused a little bit as some books state that level start at 0 and others state that level starts at 1. We need a unified solution between those authors 
|
|
|
|
|
You are welcome.
|
|
|
|
|
I have a service I wrote that uses a filewatcher. On create it takes the excel file and truncates table and import it.
It works on my Windows 7 box. When I drag a new file into the folder it imports it. If i drag a newer file it deletes the old data and imports the new data.
On Windows 2012 Server the service works on the first import. on the second drop of a excel file I get
Error durring import of file 20151106.xls
Exception occured in Microsoft JET Database Engine
Exception: The Microsoft Jet database engine cannot open the file. It is already opened exclusively by another user, or you need permission to view its data.
This shouldnt happen as I have
finally
{
if (oraConn.State == ConnectionState.Open)
{
oraConn.Close();
}
if (oleDbConn.State == ConnectionState.Open)
{
oleDbConn.Close();
}
oraConn.Dispose();
oleDbCmd.Dispose();
oleDbConn.Dispose();
}
The service works fine on my windows 7 box and works for the first file on Windows 2012 server. Why is the service leaving the connection oleDbConn open on Windows Enterprise Server 2012? ?
modified 4-Dec-15 19:07pm.
|
|
|
|
|
I have a large legacy application being updated to use newer CMFCRibbonBar. This application is large and the creation of the CMFCRibbonBar involves converting a lot of legacy icons and menu structures so is a bit complicated to extract and post here. I will add further details as people request them.
But the general gist is:
The application works fine and has a valid and working CMFCRibbonBar.
That ribbon bar has 11 categories across the top. With hundreds of panel buttons and menu buttons.
I have also recreated the same structure using CMFCRibbonButton to create a quick old style menu system which has been added to the m_wndRibbonBar via the AddToTabs. This give me a working drop down menu in the top right had corner. I believe there is a general web example which people may be familiar with which create a “window style” dropdown where you to change the MFC window manager style from windows 2000 through to windows7.
My menu is created from scratch at application startup and is not taken from a menu resource as this application predates this structure.
I use commands like the following to construct this menu:
pQuickMenu = new CMFCRibbonButton(ID_MENU++,TEXT("Quick Menu"),-1,-1,0);
…
pQuickButton = new CMFCRibbonButton(ID_MENU++,wMenuCommand,-1,-1,0);
pQuickMenu->AddSubItem(pQuickButton,-1);
…
…
m_wndRibbonBar.AddToTabs(pQuickMenu);
The problem I am having is dynamically adding new buttons to this quick menu at a later date.
When I originally created this quick menu I kept the pointer to this structure that was used to add to the ribbon. Therefore I am able to add to the quickmenu.
pQuickBut = new CMFCRibbonButton(ID_MENU,wMenuCommand,NULL,0,hSmall,0,0);
pQuickMenu->AddSubItem(pQuickBut,ilp);
If I add a new button to the existing stored top level quick menu using the stored pQuickMenu pointer, the button does appear. The text is correct and the button is selectable.
Except that the button is not operated upon when clicked.
If I add the button to the m_wndRibbonBar instead then it works so I know there is a valid command handler.
Down within the MFC code, clicking on my new quick access menu enters a routine called:
CMFCRibbonBaseElement::NotifyCommand(BOOL bWithDelay)
This extracts the command id correctly.
UINT uiID = GetNotifyID();
But it then checks for a valid ribbonbar.
CMFCRibbonBar* pRibbonBar = GetTopLevelRibbonBar();
This fails and returns a null pointer. Thus the command processing structure is exited.
As a test, if I call m_wndRibbonBar.AddToTabs(pQuickMenu) again for a second time adding the same menu to the RibbonBar a second time, then the origial becomes corrupt but the new command does work.
I am therefore assuming (guessing) that when the AddToTabs is called there is a ribbon handle stored with the commands. When I add directly to the existing structure after the original call to AddToTabs, a valid ribbon handle is not happening.
In the old style of things I would detach my quick menu, update it and then reattach. But I do not know how to do this (or even if it is nessesary) in the new CMFC classes.
The command: m_wndRibbonBar.removeallfromtabs(); deletes the whole of my pQuickMenu structure so I can not then add to it.
Is there anyone who can help explain how to dynamicaly add new buttons to an exising menu that has been added to a ribbonbar tab.
Any help appreciated.
Thanks.
Steve.
-- modified 7-Dec-15 4:13am.
|
|
|
|
|
I now have a simple MFC example which demonstrates my issue.
Is it possible for me to upload this somewhere hoping that someone can pinpoint where I’ve gone wrong and help correct it.
Thanks.
Steve.
-- modified 7-Dec-15 5:49am.
|
|
|
|
|
Can anyone help me?
I am still unable to add to a ribbonbar “tab”.
Here is an example bit of code, which when added to a new MFC MDI basing ribbon example generated from the wizard works correctly until I add the bit at the bottom.
Add to MainFrm.h
public:
void CMainFrame::CreateAddtoTabs();
void CMainFrame::AddToExistingTab();
void CMainFrame::DoIWork(UINT ID);
public:
CMFCRibbonButton *pQuickMenu;
CMFCRibbonBar m_wndRibbonBar;
Add to MainFrm.cpp
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWndEx)
ON_COMMAND(2000,&CMainFrame::AddToExistingTab)
ON_COMMAND_RANGE(1000,1001,&CMainFrame::DoIWork)
END_MESSAGE_MAP()
//Replace the existing InitializeRibbon routine.
void CMainFrame::InitializeRibbon()
{
BOOL bNameValid;
CString strTemp;
bNameValid = strTemp.LoadString(IDS_RIBBON_FILE);
ASSERT(bNameValid);
m_PanelImages.SetImageSize(CSize(16, 16));
m_PanelImages.Load(IDB_BUTTONS);
m_MainButton.SetImage(IDB_MAIN);
m_MainButton.SetText(_T("\nf"));
m_MainButton.SetToolTipText(strTemp);
m_wndRibbonBar.SetApplicationButton(&m_MainButton, CSize (45, 45));
CMFCRibbonMainPanel* pMainPanel = m_wndRibbonBar.AddMainCategory(strTemp, IDB_FILESMALL, IDB_FILELARGE);
CreateAddtoTabs();
}
//Include new routines in MainFrm.cpp
void CMainFrame::CreateAddtoTabs()
{
pQuickMenu = new CMFCRibbonButton(1000,TEXT("QuickMenu"),NULL,0,0,0,0);
AddToExistingTab();
m_wndRibbonBar.AddToTabs(pQuickMenu);
}
void CMainFrame::AddToExistingTab()
{
pQuickMenu->AddSubItem(new CMFCRibbonButton(1001,TEXT("Do I work?"),NULL,0,0,0,0),-1);
}
void CMainFrame::DoIWork(UINT ID)
{
MessageBox(TEXT ("Yes I Do!"),TEXT("Do I Work?"), MB_ICONWARNING) ;
}
If I add the above strucutre to a ribbon based MDI MFC application, a new “QuicMenu” tab appears on the menu system. It works. If I click the “Do I work?” menu entry then it pops up a panel saying “yes I do!”
If I now add a button to the ribbonbar at time of initialisation, which when clicked will adds a new button to the “QuickMenu” menu then all is good. The additional button turns up and is selectable.
void CMainFrame::InitializeRibbon()
…
…
…
…
CMFCRibbonCategory *pCat = m_wndRibbonBar.AddCategory(TEXT("Update AddToTabs"),0,0,CSize(16,16),CSize(32,32),-1,0);
CMFCRibbonPanel *pPan = pCat->AddPanel(TEXT("Single Button"),0,0);
pPan->Add(new CMFCRibbonButton(2000,TEXT("Click to add to quickmenu"),0,0,0,0,0));
CreateAddtoTabs();
}
But when I select this new menu entry from the “quickmenu”, the click is registered but in the lower MFC code it fails to recognise a valid ribbonbar handle and exists without processing the message (see my first post for more info).
Can anyone help?
I am realy stuck and may have to scrap the ribbon and revert to basic menus only if I can not dynamicaly add to my quickmenu as rquired.
What am I missing or overlooking when I'm adding to my QuickMenu structure?
Any help would be appreciated.
Thanks.
Steve.
|
|
|
|
|
|
In my project I created object for class using new operator. After use I deleted that object and set that to NULL. But even after deletion, I could able to access and able to run other functions using that (deleted)object.
Please go through example:
CTemp *objTemp = new CTemp;
objTemp->Fun1();
delete objTemp;
objTemp = NULL;
objTemp->Fun2(); // It is illegal still works, why?
Why this is happening?
modified 4-Dec-15 6:09am.
|
|
|
|
|
Because the method is generated for the class, not for the instance of the class (that is you don't delete code).
|
|
|
|
|
In addition to the answer by CPallini:
It will only work when your CTemp::Fun2() function does not access non-static member variables or call other member functions that would do so. Then the implicit this pointer will be used which is NULL generating an access violation.
|
|
|
|
|
Of course. 
|
|
|
|
|
I am in the process of trying to code the transmission of floating point data over an ethernet cable. I decided to send two bytes, the first with the "whole" part and the second with the "fractional" part (but as an unsigned char). The first byte works fine, but the second (trivial) part is giving me a strange (to me) problem which is driving me nuts - I can't see WHAT I'm getting wrong. Here is the test code:-
float flTest = 0.04;
float flResult;
flResult = flTest * 100;
unsigned char ucResult;
ucResult = (unsigned char)flResult;
flResult ends up as 4.00000 which is correct, but ucResult gives 3 !!
If I change flTest to 0.05, ucResult is 4 !!
There is clearly a decrementation involved here, but I can't understand why !
I'm sure that when some kind soul explains it, I shall be kicking myself - HARD !!
Doug
|
|
|
|
|
Hate float, try decimal. every time I have used float, the results are unpredictable for what seems like straight forward math, decimal behaves itself.
|
|
|
|
|
Float (and double) do exactly what they are supposed to do. The problem is that too many users do not understand how to use it.
|
|
|
|
|
Granted. In this case he is not getting the results he is seeking float may be the problem...
|
|
|
|
|
Michael_Davies wrote: float may be the problem. No, the problem is he does not understand how float values are represented in computers.
|
|
|
|
|
There is no decrementation, you just need to understand What Every Computer Scientist Should Know About Floating-Point Arithmetic[^].
What you should do to transfer the data (via serial or internet) is to transfer the exact bytes of the data, rather than trying to convert them to something else. So take the address of the number, cast that to an unsigned char* and send the four bytes thus pointed at. This will ensure that your receiver will get the exact data that you send.
|
|
|
|
|
Still learning how to code wrote: flResult ends up as 4.00000 which is correct That is not correct. The problem occurs when assigning 0.04 because the binary representation of floating point values can be slightly inexact. In your case flTest will be set to the value 0.0399999991. The following multiplication by 100 will not add another error so that flResult becomes 3.99999991.
Because there is no rounding when casting floating point values to integers, the result is 3. To avoid this, you can add 0.5 before casting:
ucResult = (unsigned char)(flResult + 0.5f);
Note that the above is for positive numbers only. With negative numbers, 0.5 must be subtracted.
|
|
|
|
|
First of all, apologies for not replying earlier !
WOW, I didn't think that a few lines of code could provoke so much discussion !!!
The technique that I am trying to employ is between a PC and an Arduino (via Com port - actually USB). I used it a few years ago to transfer floating point numbers, but in the OPPOSITE direction and it worked perfectly.
Anyway, thank you all for your comments - I am amazed that the "error" is actually in the assignment as pointed out by Jochen. In this particular application, the floating point numbers will be quite small, so I think that I'll have to go for the 4 byte transfer method to maintain accuracy - but I'll be doing a lot of testing !! Thank you all once again !
Doug
|
|
|
|
|
If you need to transmit a float value on the net then do transmit it, that is send its binary representation (e.g 4 bytes for a float, 8 for a double).
|
|
|
|
|
That's assuming that you have similar processors at both ends of the connection. While big-endian systems are rare these days, they're not non existent. Furthermore, be careful when going between 32-bit and 64-bit systems. On my x86 linux boxes, a long is 4 bytes, whereas on a x86_64 they're 8 bytes, x86 long-double is 12 bytes and x86_64 its 16.
|
|
|
|
|
|
I am not seeing this issue.
I get 4 for unResult.
Do you have your floating point options set correctly in the compiler?
In visual studio, select properties on your C project. Expand the projects setting out for "c/C++->Code Generation" and set the option for "Floating Point Model" to Precise(/fp:precise).
|
|
|
|
|
I have a combobox in a mfc application. I created it at runtime with following code -
if (!m_sortBox.Create(WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST, rect, this, eSortBox))
return FALSE;
Now the requirements, if user is selecting an item from combobox like , if combo box have focus & user is pressing up/down arrow key, it should NOT update the data.
If user is pressing enter key after selecting a item, it should update data.
So i didn't handled OnSelchange here.
For enter key requirement, I checked enter key event in preTranslateMsg & checking if combo box have focus, it should trigger the function, who will eventually update the data.
if (pMsg->message == WM_CHAR && pMsg->wParam == VK_RETURN)
{
CWnd pActiveWnd = CWnd::FromHandle(GetFocus()->GetSafeHwnd());
CWnd pcbSortBoxWnd = CWnd::FromHandle(m_sortBox.GetSafeHwnd());
//If sort combo box has focus and user press Enter key, it should trigger OnComboSelChange event
//Eventually it will update the data.
if (pcbSortBoxWnd == pActiveWnd)
OnSortChange();
}
I also handled ON_CBN_CLOSEUP(eSortBox, OnSortChange)
So that mouse functionality will work(because with mouse, data should get update)
Now my logic is working but its crashing in some cases.
Like - If I press Alt + Down arrow key, which will expand combobox, I select an item(with help of arrow keys) and press enter.
Sometimes its getting crash.
please help me out.
Regards,
Amrit Agrawal
|
|
|
|
|