This is to have a minimal tool bar thingy working. But it doesnt even show up. What am I missing? Whatever method this is in, I am calling it on OnPaint().
2) I am using (once I get it working) "CBRS_BOTTOM" this to display the tool bar at the bottom. I want it on (vertical) left too. How do I manage that?
This is creating a tool bar object and not through class wizard. That's why I am probably confused.
1. OnPaint is a wrong place for creating/displaying any control. It is a paint handler as the name specifies and it is a handler which has to be used only for that purpose. Note that it is called several times and whenever windows needs to paint any part of the window due to uncovering, moving or whatsoever. There is no gaurantee that it will be called in a particular order.
2. So, first off , you need it to move it from OnPaint handler to someother place. The best place would be some handler related to Creation or initialization. I'm not sure what kind of project u r using. Is it a dialog, or is it a SDi/MDI app ? If it is an SDI / MDI app, you could create a sample app with all defaults and will be able to see the toolbar creation in OnCreate method of mainframe.
Note: Since you are using CToolBar toolbar on the stack in OnPaint handler, when the OnPaint handler exits, the CToolbar object is destroyed ( in turn calling DestroyWindow on the toolbar window ). That is the reason why it doesn't show because by the time it is created, it is destroyed too. So, since you want it to be persistent, you have to make it a member of a window which will have this toolbar as child window.
I did that. It shows the tool bar as it is in OnInitDialog(). But it doesnt repaint it. So if the window is repainted, its not possible to get the tool bar back.
To avoid this I tried to put it in OnPaint(), where it hangs on execution.
If I had not added the member variable, then it would not seem like an OnPaint() issue. It wouldnt compile at all. Right? So I dont think its that. But it could be that I am not adding something else that I am supposed to, no idea what though. Thats my problem.
// if there is a top level routing frame then let it handle the message
if (GetRoutingFrame() != NULL) return FALSE;
// to be thorough we will need to handle UNICODE versions of the message also !!
TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
TCHAR szFullText[512];
CString strTipText;
UINT nID = pNMHDR->idFrom;
if (pNMHDR->code == TTN_NEEDTEXTA && (pTTTA->uFlags & TTF_IDISHWND) ||
pNMHDR->code == TTN_NEEDTEXTW && (pTTTW->uFlags & TTF_IDISHWND))
{
// idFrom is actually the HWND of the tool
nID = ::GetDlgCtrlID((HWND)nID);
}
if (nID != 0) // will be zero on a separator
{
// AfxLoadString(nID, szFullText);
strTipText=szFullText;
This is what I did:
1. Created a sample MFC app of dialog based type
2. Added a toolbar resource with ID set to IDS_SCALE
3. Added CToolbar cToolBar object to the dialog .h file
4. Added the code for OnInitDialog that you have pasted and everything seems to be fine. I don't have any problems whatsoever with painting.
Note: I did not do that tooltip stuff simply becuase I think you don't need it, right ?
Try the above steps yourself and see if there is a problem.
I am working in someone else's application, which is JUST HUGE. I can't figure out what sort of application it is. But the file I am working in is a dialog file.
Is that sufficient info for me to develop on it?
So I cant do this:
1. Created a sample MFC app of dialog based type
So I dont really know wat you mean by this:
2. Added a toolbar resource with ID set to IDS_SCALE
But I have added IDS_SCALE in string discardable in the resource file.
I have done the following:
3. Added CToolbar cToolBar object to the dialog .h file
4. Added the code for OnInitDialog that you have pasted and everything seems to be fine. I don't have any problems whatsoever with painting.
So as far as #2 is concerned, what xactly do I have to add in the resouce file, keeping in minf I am not using classwizard?
Originally posted by tarangkaushal
So I dont really know wat you mean by this:
2. Added a toolbar resource with ID set to IDS_SCALE
I guess that is the problem then. Probably the toolbar is not even initialized because you are passing a string resource when it expects a toolbar resource.
So, step 1 is to create this.
1. Go to resource view in your project
2. On toolbar resources, right click and select Insert...
3. Select toolbar from the options & click New
4. You will be presented with a box for drawing the toolbar button. Draw a sample button. Once you are done drawing, another button is added if you look at the top pane. Select that and draw another button. So, for a test, that is enough. You have a toolbar with 2 buttons.
5. Note the ID for this in the toolbar resources..( default IDR_TOOLBARn )
6. In your OnInitDialog replace IDS_SCALE with this ID.
Bookmarks