|
The folowing should do the trick;
cout << (*yourIterator).second << endl;
-Ben
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
So far I've seen two examples using the syntax:
(*iter).second
to look at the content of a map. Is there something
wrong with using the -> operator as in:
iter->second
Thanx
|
|
|
|
|
My STL book ("The C++ Standard Library: A Tutorial and Reference" by Nicolai Josuttis) tells that:In some older environments, operator -> might not work yet for iterators MSVC's STL implementation seems to be an "older environment", using (*iter).member is always safe.
|
|
|
|
|
I have a custom database file (a simple character-delimited text file, if you would like to know) I need to read/write to in a Wizard-made Database program in MSVC++. The project was specified as a single-document database program. I'm having trouble figuring out how to read and write to the file. I assigned a CArchive Serialization function to a button, and when I hit it, I get an Invalid Page Fault. If you feel like laughing, here's the function:
void CDCDBIIView::OnButtonReadFile(CArchive &ar)
{
ar.ReadString(m_FILE); //CArchive object ar created in CDCDBIIDoc::Serialize(CArchive &ar)
UpdateData (FALSE);
}
Something's wrong with my logic in the ar.ReadString line, because that's the only line in the function doing any serious work. (UpdateData just...well, updates the data with the new info.) Right now, I'm not worried about parsing the input I'm getting in the archive, I just have m_FILE assigned to a read-only edit box so I can see if the program is reading from the file at all.
What I need to know is do I need to add a custom function to load/read/write to the open file, or do I add it to one of the many classes the MSVC++ Wizard built? I've read as many tuts as possible on CFile and CArchive, and MSDN isn't helping much. Any help would be greatly appreciated.
-Trying to be as informative as possible while knowing almost nothing at all
|
|
|
|
|
I have done a simial thing. The only difference is that i have used a structured ascii file instead of comma delim. This function uses CFile.
CFile rfile.Open(filename,CFile::modeRead | CFile::shareDenyWrite, &ex);
LogCnt = rfile.GetLength()/sizeof(LOGDATA);//returns how many records in the file
for (int i = 0;i< LogCnt;i++){
rfile.Read(&logdata[i],sizeof(LOGDATA));
///////if you want to use comma delim you would parse your data here
///////////////////////I put a return char on the end if the string in the write function.
rfile.Read(tmp,1);/////////////////used to hold return char
}
|
|
|
|
|
Hi all.
I want to know, for getting data from mscomm i must use of GetInput() or GetOutput() ???
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Does anyone know how to load small (16x16) versions of the built-in icons, like the information ('i' in a bubble), warning ('!' in a triangle) and error ('X' in a circle) icons?
LoadIcon will only load 32x32 images.
LoadImage loads the icons in question as 32x32 even if I request 16x16 and doesn't load them at all if I don't specify LR_SHARED.
I'm trying to avoid putting the icons in my project as a resource. I'd also rather not load the 32x32 versions and scale them myself. There's gotta be a way, Shirley?
|
|
|
|
|
Try,
HICON hSmallIcon = (HICON) ::LoadImage ( AfxGetInstanceHandle (), MAKEINTRESOURCE(IDR_MY_SMALL_ICON), IMAGE_ICON, 16, 16, LR_VGACOLOR );
it always works for me. But, remember that unlike LoadIcon, this one does require a subsequent call to DestroyIcon when your're done with the it.
-Ben
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Thanks for the reply, but I want to load built-in Windows icons and avoid including resources in my project. (Because it's a class I plan on using in several projects.)
For example:
HICON hIcon = (HICON)LoadImage(NULL, IDI_INFORMATION, IMAGE_ICON, 16, 16, LR_SHARED);
This always loads a 32x32 image and fails if LR_SHARED is removed.
BTW, IDI_INFORMATION is the same as MAKEINTRESOURCE(OIC_INFORMATION) but you don't need to #define OEMRESOURCE and can leave out the MAKEINTRESOURCE macro.
|
|
|
|
|
BTW, I know I can load the 32x32 icon and paint it as 16x16 using DrawIconEx but that does an absolutely appalling job of scaling the image. I've seen the OS use 16x16 versions of them that look good, for example in Win2k tray icon bubbles, but I can't work out how to load them...
Maybe I need to load them directly from the DLL which contains them... Gah, nasty and not guaranteed to work in the future, but luckily the code will only be run on NT4 machines so it could be a safe bet.
(The code is to emulate Win2k tray icon bubbles when running on NT4 machines.)
|
|
|
|
|
I'd say, save yourself some greaf and just copy them into your applications resources. This will not only work, but be will garonted to work in the future.
BTW: I found this in MSDN
In LoadImage:
When loading a system icon or cursor, you must use LR_SHARED or the function will fail to load the resource.
Windows 95/98/Me: The function finds the first image with the requested resource name in the cache, regardless of the size requested.
The second part does not seem to apply to you, but it seems you must use LR_SHARED on all Windows flavors.
-Ben
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
Hi all - I hope you can help
I have a multi frame app eg like an MDI but each document is in it own mainframe - however whenever I try printpreview it always uses the first main frame and not the one I am trying to print preview - can anyone help me on this?
Holy Handgrenade of Antioch instructions
|
|
|
|
|
Everything I seem to see on this site is C++ and not C. Can someone please give me a hint as how to implement a static splitter window using just window API instead of MFC.
Thank you in advance,
SAK
|
|
|
|
|
You can create splitter in C. Below I'm assuming that you want simple two-way vertical splitter, you can generalize this solution to horizontals and combined splitters.
1) Registering your main window class use your own cursor looking more or less like this: <-|->
2) create your child windows in WM_CREATE handler. Use WS_EX_CLIENTEDGE style for 3D look.
3) in WM_SIZE handler ensure that height of these windows is equal to the height of main window's client area. Set that widths are set to the value that leaves some small area between two child windows. This area is your splitter bar.
3) your main window will receive mouse-related messages only if cursor is placed in the 'splitter' - the area between child windows. In WM_LBUTTONDOWN handler capture the mouse, resize child windows in subsequent WM_MOUSEMOVEs, and release mouse in WM_LBUTTONUP.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
I have a group of about 30 checkboxes.
I would like to put them into an array so i can easily get and set the values.
What process is required to do this?
Thank You
|
|
|
|
|
Save in the array a reference of each checkbox.
good Luck
Carlos Antollini.
|
|
|
|
|
Previously I asked if there was a way to separate the colors for stdout & stderr when writing to a console. I never got a response. So in the unlikely event someone else was wondering about this, check it:
You need these headers:
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
When you fire up a console (using AllocConsole(), and when you're done call FreeConsole()), get the stdout & stderr handles by doing:
HANDLE hStdOutput;
HANDLE hStdError;
Then you can use the following routine just like fprintf. Now, if your routine is doing a ton of processing and suddenly an error pops up, your machine hangs, then reboots itself, you'll have a shot at seeing what went wrong! (especially when the reboot tends to wipe your logs)
//only goes to stdout or stderr!!!
int myfprintf(FILE *stream, const char *format, ...)
{
DWORD numwritten;
char *str;
va_list args; //variable argument list
va_start(args, format);
str = new char[strlen(format)*10 + 1]; // <- you're screwed if this isn't enough mem
//sprintf(str, "%s", format);
memset(str, '\0', sizeof(char));
vsprintf(str, format, args);
if (stream == stdout)
{
SetConsoleTextAttribute (hStdOutput, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN);
WriteConsole (hStdOutput, str, strlen (str), &numwritten, NULL);
}
else if (stream == stderr)
{
SetConsoleTextAttribute (hStdError, FOREGROUND_GREEN);
WriteConsole (hStdError, str, strlen (str), &numwritten, NULL);
}
delete[] str;
return (numwritten);
}
I've only tried this on NT Workstation 4 & Win98se, lemme know what you think...
--
Peace,
Amit Jain
|
|
|
|
|
This raises a subtle point. I am guilty of not responding to your original post. The reason? I'd answered the same question twice already. Sigh...
This is not to say that you should have read every post to see if there was an answer. (btw lets have a rockin party when the VC forum hits 10000), but you can see where it gets tiresome. I'm not suggesting a search is the best way either - sometimes its difficult to know what to key on (if you knew what you were looking for... )
So - my point? Well, the thought of a FAQ does arise... Is it feasable? How much work would it be to take the wealth of stuff we've got in the forums and make a FAQ? Chris? Anyone?
One thing I have noticed is that people do check the articles - once a relevant article exists, the forum querys on that topic abate.
Anyway, I'm think I'm posting a lounge article in the wrong place here.
BTW you addressed the issue better than I did (hey, they're not all gems! )
Cheers
T
|
|
|
|
|
An open moderated FAQ would probably help... Like interesting questions and good answers, modded by either the community or the mods. You're absolutely right though, I hate searching for the answer to a specific programming question, it's hard to narrow it down properly, and usually my terminology is wrong.
--
Peace,
Amit Jain
|
|
|
|
|
Hi,,
each class can serialize its own data memebers, is that right?
ex:
Class myclass1
{
int x;
}
class myclass2
{
myclass1 item;
}
I like to know if myclass2 can serialize the data member (int x) of myclass1 ??
Thanks
Ehsan Behboudi
|
|
|
|
|
You can serialize another class's data if:
a) if myclass1 has members that give access to its data
b) myclass2 is a friend of myclass1
c) if myclass1 declares its data a public (not a great solution)
-Ben
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
You should have a Serialize() function in myclass1, then myclass2.Serialize() can call item.Serialize().
|
|
|
|
|
Dear all
how to set the IP address during programming ? Generally the IP address is set in the network neighborhood and then restart the PC . I want to set the IP address in my programm and don't restart the machine. Is it possible?
Thanks a lot
|
|
|
|
|
You need to disconnect, then connect again. This is because the server need to evaluate if is valid your ip, and update your ip in the list. Is for this that is better to reboot the PC.
But you have a sample in win95 that permits to change the ip without reboot the PC, with the application winipcfg, with this app you can disconnect and connect again, get a new ip, without reboot.
Cheers!!!
Carlos Antollini.
|
|
|
|
|
Hello, the codegurus around the world.;)
Your question seems to be tough.
Window 95, (98 & ME), NT, and 2000 has the differnt approaches to bind IP address to
NIC.
Windows 2000 has some API to change IP address, and the others seems not to have one.
Check MSDN help like the below.
Platform SDK: Internet Protocol Helper
IP Helper Functions
Rebooting the comp is very important to update the registry each other.
On NT, if we add NIC, and ipconfig command, we doesn't get the right info since
the registry entry mismatches.
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|