|
Have you tried not opening the file until you write to it ?
Crivo
Automated Credit Assessment
|
|
|
|
|
Thanks.
You made a good point. The way I designed program have it open the output file first. I feel it is more elegant relative to the *user* if I leave the program in its current structure.
I implemented the seekp() and tellg() functions determine whether the program made any changes to the output file.
Kuphryn
|
|
|
|
|
Hi.
I have a series of
char* XX[2] = {"Hi", "Hi there"};
....
These are meant to hold txt so that I can change them as a SET by changing the index.
I have a header file to hold these. My question is that I include this file in all my other classes and such that it can use this. Do I have to use extern on all these declarations in those files or another header file? I would only want to change the text in one place and not have this file and another one identical to this except with extern in front of everything. Is this right? I am not too familiar with externs but is this the only way?
If I am not correct, can someone correct me on how to use an index or some way to choose the text but to set it globally I guess so that I can use it in ANY FILE.
Thanks in advance.
|
|
|
|
|
extern tells the compiler "this is what the variable looks like".
use it like this:
code.h
------
extern int myInt; // this just tells other code that "myInt" is an int, not where it lives (ie. it's address)
code1.cpp
------
int myInt; // this allocates the variable
code2.cpp
------
#include "code.h"
myInt = 5; // use it
-c
Smaller Animals Software, Inc.
|
|
|
|
|
For
char* Text[2] = {"hi","hi there"};
THe extern statement would be
extern char* Text[2];
Is this correct?
|
|
|
|
|
|
I like to keep these kinds of things all in one file. Here is a couple of macros that help with doing this.
// in YourHeader.h
#ifdef MAIN
#define Global
#else
#define Global extern
#endif
// if not initializing
Global char *XX[2];
// if you are going to initialize it do this :
#ifdef MAIN
char *YY[2] = { "String 1", "String 2" };
#else
extern char *YY[2];
#endif
// in your source code files
// do this one and only one time
#define MAIN
#include "YourHeader.h"
// no other source files may contain the MAIN definition
|
|
|
|
|
Somewhat of an aside, but globals are of the devil, if you must use them, you should put them into a namespace.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
Ewww, I bet you think gotos are the spawn of Satan.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
But of course.
NumberOfTimesIHaveUsedGotoInC = 0;
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
As a very "general" rule, you should try to avoid declaring variables in a header file, simply because every source file that includes them will re-create that variable's declaration. If you really want a global variable, you should declare it in a source file, and then when another source file needs to access or update it, declare it again in that source file using extern. Extern says "There is a variable (with memory allocated) somewhere else in the program and it looks like this." Separating your global variables like this helps to keep track of them, because you declare them in the source file where they are "owned," and then use extern for everywhere else where they are "used."
While various macros have been developed for use in header files to optionally compile or not compile the extern for variables, this is really just a confusing trick to get the compiler to do what I have described. It's only confusing to you and other programmers, because you still have to find when the original file is to find if the macro #define is made in order to get the original variable declaration.
Dave
"You can say that again." -- Department of Redundancy Department
|
|
|
|
|
I am trying to write a program that has an SDI interface, but has three tabs within that. Does anyone know where i can get the code for this, i have checked out the samples on this site and www.codeguru.com, but none of them use a tabbed interface.
==================================================
When Your Mind Wonders...Where Does It Go???
|
|
|
|
|
Hello,
How to write a WinNT service by VC, I read MSDN, it seems use ATL,
but I can't understand clearly, have some kindly give me an example ??
please email to vistac@ms10.hinet.net
Thanks.....
Vistac Wu
|
|
|
|
|
did you try looking on this site first? there are many articles on services here. http://www.codeproject.com/system/
-c
Smaller Animals Software, Inc.
|
|
|
|
|
Hi All,
I’m doing some processing in method of view(CView) and wanted to display result in my document(CDocument). Its my first application for Doc/View Architecture. I’ve created MFC SDI Application from Project Wizard of VC++ 6.0.
Please guide me for that. Also I’d like to mention that all my document would be ASCII text ya, kind of notepad application but the content would have to be displayed from background process in code of View. I’d like if someone give me direction for implementing Copy data area from that view. No need to cut and paste.
Does this SDI provide me scrolling also when the area will exceed? IS there any change need to be done to introduce scrolling?
Thanks a lot for lot of answers
-- Sumit
Please make a CC of reply at sumit@elitecore.com
|
|
|
|
|
Hi,
You must use the method CView::GetDocument() , that get pointer to the CDocument.
Best regards,
Eugene Pustovoyt
Sonork ID 100.10002:Yaumen
|
|
|
|
|
Hey Eugene,
Thanks for your answer, But I'm not aware of how to flow. What methods are used for display? Can you provide me a summery of doing this?
Say I have some thread running on my CView::OnNew(). Now this thread returns some result. And I wanted to Display this text output, in multiple lines. I wanted to provide support to copy that text also.
Thanks for all help and appritiate lot to smart piece of code for steps and overview.
-- Sumit
|
|
|
|
|
It would be better to proccess the information in the document class, then you will have to create a pointer to the document class, extract your information in a function on the view class. Then obtain a dc to the window you would like to display your text in and use DC functions for displaying it. you will be able to create support for copying, as the information is stored in the document.
remember if u start a thread from the document class u will have to pass the thread the cview HWND handle if u want to send any windows messages from your thread, also it's not always possible to pass a thread a pointer such as ur Document class pointer, but it sometimes is!
Hope this helps in someway.
|
|
|
|
|
Hi,
It helps me, but very little. I knew that what I's doing was a little wrong way. But still I'm fix with how to achieve this. See I tell you what I wana achieve. I wanted at "OnOk" of Dialog-Box, I contact to server, get data from there and now i need to display that data. Please Help me. I've simply created and MFC EXE application and changed base class of my view to CEditView. Now in MyView::OnFileNew()I'm Calling DoModal of my dialog-box, I get server IP from there and then do processing and get data which has to be displayed.
Please suggest me some programming steps to go further. I'd be happy if someone suggest over some of my previous wrong methods also.
Thanks in advance.
-- Sumit
|
|
|
|
|
Hi,
How can i get a bitmap buffer from a .dib file?
Neha
|
|
|
|
|
Look in the code of the IconPro sample from Platform SDK. There is a file that is working with DIBs (dib.c)
Also look here in this article: DibSection
And, you can find a lot of info in "Bitmaps and Palettes" section here, on CodeProject
Philip Patrick
"Two beer or not two beer?" (Shakesbeer)
Web-site: www.saintopatrick.com
|
|
|
|
|
Thanks for the reply.
But i feel .dib &.bmp are same in windows.
If i write
HANDLE hImage = ::LoadImage (AfxGetInstanceHandle(), "d:\\winnt\\prescan3.BMP", IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE );
I will hImage as NULL.
Why is it so?
|
|
|
|
|
Try to put NULL instead of AfxGetInstanceHandle()
This should help, cause when you are loading from file you do not need the Instance handle
Philip Patrick
"Two beer or not two beer?" (Shakesbeer)
Web-site: www.saintopatrick.com
|
|
|
|
|
It works with all other bmp file.But it doesn't work with the file which i renamed from .dib to .bmp.
Any idea?
|
|
|
|
|
Did you try to open the file with other utilities? Such an IrfanView, or simple Word?
And if you can, can you send me that .dib file, so I'll play with it?
Philip Patrick
"Two beer or not two beer?" (Shakesbeer)
Web-site: www.saintopatrick.com
|
|
|
|