|
You want to add the toolbar (or dialog bar) to the frame insted of the view. You can catch the button messages in the doc, view, or frame. The code below will add a toolbar to the child frame:
int CFrameClass::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIChildWnd::OnCreate(lpCreateStruct) == -1)
return -1;
//Create the toolbar.
{
EnableDocking(CBRS_ALIGN_ANY);
if(!m_wndToolBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP, IDR_TOOLBAR_DEFECTVIEW) ||
!m_wndToolBar.LoadToolBar(IDR_TOOLBAR_DEFECTVIEW))
{
TRACE0("Failed to create toolbar\n");
}
else
{
// TODO: Remove this if you don't want tool tips or a resizeable toolbar
m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
// TODO: Delete these lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar, AFX_IDW_DOCKBAR_RIGHT);
}
return 0;
}
Good luck,
Jonathan Craig
|
|
|
|
|
Thanks!
It worked, but how can I get a pointer to the child from the view?
Thanks again!
Erik
|
|
|
|
|
Look up this document in the MSDN or on Microsoft's web site; "Relationships Among MFC Objects". I keep this one tacked to the wall next to my computer.
The function you want is CWnd::GetParentFrame(). Remember the view is a child of the frame.
Good luck and happy hacking...
Jonathan Craig
|
|
|
|
|
This is very strange problem because my code works perfectly when dynamically linking to MFC.
At some point in my project I use:
HCURSOR hAniCur = (HCURSOR)LoadImage(AfxGetResourceHandle(),
MAKEINTRESOURCE(IDR_HOURGLASS), IMAGE_CURSOR, 0, 0, LR_DEFAULTCOLOR); which gives me a valid handle as long as MFC is in a DLL, but returns NULL when I link static MFC libraries.
There are no differences between Debug or Release builds, both suffer the same problem. I also tried to change the resource ID of the animated cursor and to use a string instead of a number, but without success.
I have reproduced this problem on a little test project if anyone likes the challenge...
Thanks in advance,
Paolo
|
|
|
|
|
Step through AfxGetResourceHandle() and make sure it's returning the correct HINSTANCE. I've seen that function return unexpected results before, which then causes all sorts of resource headaches.
|
|
|
|
|
I tried with AfxGetInstanceHandle(), AfxGetResourceHandle() and GetModuleHandle(NULL). They all return the same value, that is 0x00400000, which is right.
What's more, loading from a file works just fine with the arguments I pass to the function.
It seems like LoadImage can't find the resource, but why?
When I link with static libraries I add some resources to my executable, so I thought something was in conflict with the animated cursor resource. I tried with different IDs, but without any luck.
I imported the animated cursor as a custom resource, naming that type "ANICURSOR". Is this right? Or I should use something else?
I think the correct resource type is RT_ANICURSOR, but how can I add such resources to my project?
However, loading the animated cursor with the type I specified works in Debug version.
Any other ideas?
|
|
|
|
|
Convert the image to one of the closest DIB format, and then use StretchDIBits to display it.
My guess is that each pixel is a 16-bit grayscale level, so the closest DIB format would be 8-bit grayscale image, or a 256-color DIB with a grayscale color table.
Setup a BITMAPINFO structure with a 256-color grayscale color table, convert the image array to a 64x64 BYTE array, and then use StretchDIBits to display it.
|
|
|
|
|
I discovered what was wrong: if there are static cursor resources (RT_CURSOR) both LoadImage() and LoadCursor() don't look for animated cursor resources (RT_ANICURSOR = 21).
Statically linking to MFC involves the inclusion of some MFC resources, among which there are two cursors for context-sensitive help.
I've tried adding the animated cursor as a static cursor, but both VC++ IDE and the resource compiler recognize the internal file format.
So what should I do, if I don't want to load the cursor from file?
Is this a BUG ?? (tested on Win95 and Win2000)
Any suggestion would be appreciated...
|
|
|
|
|
To solve the problem, I thought to load the animated cursor resource and then create the cursor handle with the following code:HRSRC hResInfo = FindResource(NULL, MAKEINTRESOURCE(IDR_HOURGLASS), RT_ANICURSOR);
DWORD dwResSize = SizeofResource(NULL, hResInfo);
HGLOBAL hRes = LoadResource(NULL, hResInfo);
PBYTE pResData = (PBYTE)LockResource(hRes);
HCURSOR hAniCur = CreateIconFromResourceEx(pResData, dwResSize,
FALSE, 0x00030000, 32, 32, LR_DEFAULTCOLOR);
The problem remains
All the instruction are successful with both types of linkage, but the last returns a valid handle only when dynamically linking to MFC. When I specify to use static MFC libraries, CreateIconFromResourceEx() cease to work and returns NULL.
Can anyone tell me why?
I tried to debug USER32 code, but it's a suicide without debug symbols.
Where can I get debug symbols for Windows 2000?
Please help!!
|
|
|
|
|
i'm working on a program that reads an open file and puts a line into a sting buffer until a newline is found, then puts the string into the clipboard. This is done through a windows WH_KEYBOARD hook... is there anyway for the read file's handle to be shared so that all processes can share the same instance of the handle?
Any non-MFC solution would be very much appreciated.
|
|
|
|
|
Can I create a MDI form with child forms WITHOUT USING MFC? If it's possible, could you show me some code to do it?
Thanks a lot in advance!
B
|
|
|
|
|
If you really want to do it without any wraper classes (i.e. MFC), get a few books like, "Windows 2000 Programming from the Ground Up" by Herbert Schildt. Herbert likes to hand crank all his stuff and will have examples on how to handle the messaging and window creation.
If you just want less complicated CWnd objects you can create a MDI application without the Document/View Architecture. This gives you the CView without the attached CDocument.
Unless you want to be able to use different compliers to compile your code, I would use window wraper classes for my development. They do make life easier.
Good Luck,
Jonathan Craig
|
|
|
|
|
Have you looked in the SDK samples? I would be quite surprised if there are not any samples there. Also I think that the Platform SDK documentation that describes MDI programs would at least have peices of a sample.
|
|
|
|
|
YES, you can. It's called WTL (Windows Template Library). It's on the Platform SDK, and it's great. You can create full-featured apps without MFC bloat and no dependencies.
|
|
|
|
|
I tried the WideCharToMultiByte function but it seems that I have no success.
I'm trying to write an XML file.
|
|
|
|
|
Uwe, here's a UTF for Linux FAQ that talks about decoding UTF-8. It should give you a start regarding going the other way.
Here's a Google search that will give you some more stuff to look at.
|
|
|
|
|
Thank you very much, Mike!
I'll post a solution as soon as I figured it out. Maybe it will help others.
|
|
|
|
|
After mailing with Markus Kuhn, the author of www.cl.cam.ac.uk/~mgk25/, he told me the following solution (function 1), which I wrapped a little bit (function 2):
static int Latin1toUTF8(TCHAR *t, const TCHAR *s, int len)
{
const TCHAR *p = s;
TCHAR *q = t;
while (p < s + len) {
if ((*p & 0x80) == 0) {
*q++ = *p++;
} else {
*q++ = 0xC0 | ((*p >> 6) & 0x3);
*q++ = 0x80 | (*p & 0x3F);
p++;
}
}
return q - t;
}
void StringToUTF8( const CString& input, CByteArray& output )
{
output.RemoveAll();
if ( input.IsEmpty() )
return;
output.SetSize(input.GetLength()*6);
const int new_length = Latin1toUTF8( (TCHAR*)output.GetData(), input, input.GetLength() );
ASSERT(new_length<=output.GetLength());
output.SetSize(new_length);
}
Thanks to Markus!
|
|
|
|
|
Anyone know how I can allow the user to enter a string wider than the edit portion of the CComboBoxEx? I've tried LimitText which works if I set it to a low number like 5. However, if I set it to a high number like 1024 or even 50 it doesn't take. I saw the comment in the MSDN about having to set the style to CBS_AUTOHSCROLL and tried that but still haven't gotten any luck.
TIA,
Dave Saulnier
CADKEY Corporation
|
|
|
|
|
Has anyone else noticed new problems with VC++ 6 after moving from NT4 to W2K?
I got a new system with W2K and after installing VC++ 6 the IDE now has a few small but very annoying problems that I don't recall from the NT4 days. I haven't yet applied SP4 because of MS' terrible track record with service packs. I thought I'd wait a few months to see if there wer any problems. Anyway, the problems are:
1. Cut and paste of code doesn't always work. You can select the text then hit CTRL-C but the IDE WILL NOT paste it into the new location no matter how many times I try. Repeatedly re-selecting and re-copying doesn't do anything. However, if I change my copy selection just by one character it works just fine!
2. When trying to save a modified source file, which is part of a loaded project, the IDE will tell me that the file cannot be saved (I forget the exact error). But if I try again, almost immediately, the file saves just fine. It's like there are two threads working with the file but they don't have any cooperation.
3. The IDE will periodically crash when I hit F7 to rebuild. This was so rare under NT4 that I was really surprised when it began happening under W2K.
4. After doing a cut/copy or paste the IDE gets stuck in selection mode. That is, the last location of the carat becomes the start of a text selection and wherever you move the carat to becomes the end of the selection. No amount of ESC, CTRL-C or anything will get it out of this selection mode. I got really pissed and wiped my hands over the entire keyboard several times, like you would a piano keys, and the all went back to normal. That is now how I fix it. It sounds like I'm beating the sh*t out of my keyboard !!!
|
|
|
|
|
I experienced what you say at point 4, but just one time.
I remember that selecting other text saved me from that trouble.
Never experienced the other points, however, maybe point 2 but one or two times.
I can't say why...
Cheers,
Paolo.
|
|
|
|
|
Interesting, I though this was just me...
I am getting 1 very frequently, which is extremly annoying. I usually can't get pasting to work untill I have made a sucessfull paste outside of the IDE. I have absolutely no idea why this is.
I have never experienced 2 or 3, but 4 is also trur for me, though not just after attempting to copy.paste. Sometrimes the selection will just remain untill I reopen the source file.
I alos get another problem though, which is that the IDE VERY frequently stops responding for about 20 - 60 seconds, and then resumes. This is not during compile time, ubut while editing files. I have been told many approaches to solve this, but none have worked. Maybe it is because I have too many include directories set up, and VC++ uses a timer to update intellisense or something?...
Oh yeah, I am also using Windows 2000, the profesional edition, and didn't have these problems with NT4.
|
|
|
|
|
Opps, I have very bad spelling which is obvoius from my last reply.
Sorry.
|
|
|
|
|
I also encounter IDE pauses frequently but they are usually no longer than 2 or 3 seconds.
You didn't say what kind of system you had, buy my system is a 800 MHz P3 it may be fast enough to make the pause less noticible.
You are probably right about the delays being caused by intellisense. I thought about turning it off until it dawned on me how much I use it
|
|
|
|
|
I don't think my system has much to do with it, before the move to Windows 2000, I was using a dual P2 450 with 128 MB RAM (NT4 SP3), but now I have a dual PIII 650 machine, with 512 MB RAM.
I also can't live without intellisense, it would require learning a hell of a lot about MFC that I don't want to, and don't have the time to.
|
|
|
|
|