troubleshooting Question

CToolBar derived Toolbar repositioning

Avatar of gpol
gpol asked on
System ProgrammingEditors IDEs
6 Comments1 Solution828 ViewsLast Modified:
The problem is to put floating CToolBars in same position than that was saved at program end.
A GetWindowRect is done for each ToolBar and the rectangle is saved to the Registry. These coords should be screen-coords. When running the program, it reads the saved rectangle, and, to use FloatControlBar, it converts the above rectangle to Client coords with ScreenToClient.
But floating ToolBars reposition at a wrong position, as shown in the attached pictures.
Code is the following:
WRITING: (B is the CToolBar derived object pointer)
RECT rcNormalPosition;
B->GetWindowRect(&rcNormalPosition);
CWinApp* pApp = AfxGetApp();
B->GetWindowText(Nome,49); // name of the ToolBar
pApp->WriteProfileInt(Nome,"Left",  rcNormalPosition.left); // position
pApp->WriteProfileInt(Nome,"Top",   rcNormalPosition.top);
 pApp->WriteProfileInt(Nome,"Right", rcNormalPosition.right);
 pApp->WriteProfileInt(Nome,"Bottom",rcNormalPosition.bottom);
pApp->WriteProfileInt(Nome,"State", B->IsFloating());
READING AND POSITIONING: (Again B is the CToolBar object pointer)
RECT r; char Nome[50]; BOOL Floating;
CWinApp* pApp = AfxGetApp();
B->GetWindowText(Nome,49);
r.left=pApp->GetProfileInt(Nome,"Left",0);
r.top=pApp->GetProfileInt(Nome,"Top",0);
r.right=pApp->GetProfileInt(Nome,"Right",0);
r.bottom=pApp->GetProfileInt(Nome,"Bottom",0);
Floating=pApp->GetProfileInt(Nome,"State",0);
  if (Floating)
  {
     CPoint pp;
     pp.x=r.left; pp.y=r.top;
     ScreenToClient(&pp);
     FloatControlBar(B,pp,AFX_IDW_DOCKBAR_TOP); // tried any Docking    
  }
Thanks in advance
Before.JPG
after.JPG
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros