|
Bernhard wrote:
* "thinking in c++" said that you should use static const - var's instead of enums, is this really better ?
I hate blanket statements like that... Enums should be used for what they are meant for -- enumerations. That is, they should be used when you need to represent a set of values, but don't really care what the values are:
enum ACTION
{
PRINT,
PREVIEW,
EXPORT
};
void DoOutput(const char* OutputDataString, ACTION action)
{
switch (action)
{
case PRINT:
...
break;
case PREVIEW:
...
break;
case EXPORT:
...
break;
}
}
In the example above, it doesn't matter what the values of PRINT, PREVIEW, and EXPORT are, only that they are different. As the other post mentioned, the compiler will perform type checking on this to ensure that only valid values are passed into the function (of course you could use a cast, but you'd never do that right?).
In cases where the value of a constant is actually important, you should use a static const -- not only does this let you be consistent about your constants, since enums are only good for ints anyway, it is also safer, since if the value is important, sooner or later you'll need to convert it from something else, and assigning an int to an enum variable is (i think) undefined (though it usually works). If you need some extra type checking in this case, you're better off using a typedef or even a wrapper class.
Just my $.02
|
|
|
|
|
Bernhard wrote:
what is the difference between named and unnamed enums
A named enum creates a type name along with the enumerator values. Just as writing "struct x {};" creates a type called "x".
Bernhard wrote:
do i HAVE to call them qualified ? (num1::value)
No, the symbol "value1" is at the same scope as the enum itself. An enum does not create a nested scope like a namespace does.
--Mike--
http://home.inreach.com/mdunn/
Help! Help! I'm being repressed!!
your with and
Sonork - 100.10414 AcidHelm
|
|
|
|
|
Where can one fine proper documentation for the interfaces that one needs in creating AddIns for Visual C++ 6 e.g. IDebug, IDocument. I have looked at the MSDN library but when one compares it to the header files the are many functions that aren't found in the descriptions?
Thank you
Franz Klein
|
|
|
|
|
Hello,
I have a dll created in VC++. When I run the program which uses that dll then it displays error. On debugging, it indicates that in calling any resource related function from dll, it gives error. e.g. when I call the function AfxGetResourceHandle() from dll, it displays the error dialog box of 'Abort, retry, ignore'.
The resource file for dll looks to be OK. there no error or warning on the compilation.
Can anyone please tell me why it might happens.
All suggestions are welcome,
It is urgent,
Thanx,
Vikram.
|
|
|
|
|
Hi,
I want to store some user settings, but not in the registry. I want to have a .INI file in my apps folder. I've seen that the MFC provides methods to read and write from WIN.INI . Is there anything similar so that I can write in my own app.INI file or do I have to do it 'by hand' ?
Thank you for your help !
Jerome
|
|
|
|
|
Look at WritePrivateProfileString in MSDN.
Michael
|
|
|
|
|
1. Take a look at CWinApp::m_pszProfileName. Use that to set the name of the INI file.
2. Use CWinApp::GetProfileString, CWinApp::GetProfileInt, CWinApp::WriteProfileInt, or CWinApp::WriteProfileString to read/write to the file.
Regards,
Alvaro
|
|
|
|
|
Hi,
I have one problem in my application.In my application i am using two threads.The program is working fine.But the problem is when i am running the application is taking 100% of cpu utilization.So,In the previous time there is no second thread.The first thread it self is taking 100% cpu utilization.After creating the second thread the same application is taking 100% cpu utilization.I observed that this is because of first thread.I placed Sleep(1) in that first thread the cpu utilization is reducing but the problem is it is working very slow.So,i want medium of those,ie application executing is intermediate and cpu utilization is 50%.But i am not able to reach the concept.Can anybody give some solution how i can solve my problem.;)
it is a company which deals with AI and different
types of web based applications
|
|
|
|
|
Yo guys,
I got a lit' problem here with the text drawin', hope y'all can help me out.
I've made myself a bitmap class, it can load bitmaps, it can manipulate bitmaps, and things like that, without touchin' HDC. Alright? So I'll be touchin' HDC only at the final stage, that's when I draw out the bitmap to the screen.
So the problem now is, I can't draw text onto my bitmap class, before it goes out to the HDC. That means, I have a bitmap, I draw it out to the HDC, THEN only I'm able to draw text with HDC. This causes the text to flicker EVERYTIME when I refresh the bitmap.
Just wonderin', if there's any ways to draw those texts, onto the bitmap (without touchin' HDC) before output to the screen (HDC)? I believe there is, like in Flash, I think they use their own bitmap manipulation classes, and draw text on those bitmaps, and FINALLY output the result to the HDC.
Hey, thanks dude for your time, hope y'all can help me out
Zee ya!!
Me,
Baling.
|
|
|
|
|
There are two main things which could cause flickering :
1.) Not using a memory HDC/CDC when updating the bitmap or text.
2.) Not overriding OnEraseBkgnd in your View class.
The problem is probably caused by no.1 since otherwise your whole bitmap would flicker upon refresh too. What I think maybe happening is your program is drawing the bitmap directly to the screen, quickly followed by the text. This leaves a very very short period in which you see just the bitmap, thus a flickering effect is caused. What I recommend you do is create a new CDC called SrcDC, and use CreateCompatibleDC(NULL), and select the bitmap into it. I would then create another dc called DestDC (in same way), and BitBlt the SrcDC to the DestDC. I would then draw the text onto the DestDC (this has the effect of drawing onto the class) using DestDC's TextOut() function, before *finally* BitBlt'ing the DestDC to the screens *pDC that is found in your OnDraw routine. Basically *only* the final image should be drawn to the screen in 1 BitBlt, there shouldn`t be any other routines which draw to the same *pDC after this or else flickering may occur. Hope this helped,
Alan.
"When I left you I was but the learner, now I am the Master" - Darth Vader
|
|
|
|
|
Alan, thanks for the solution. So it goes like this:
SrcDC --> DestDC --> DestDC.DrawText() --> pDC->BitBlt(DestDC)
But usin' this approach, the final stage will involve the transferin' of the whole DestDC to pDC, right?
pDC->BitBlt(..., &DestDC, ..., SRCCOPY);
This will be heavy, because the interface redraws itself quite frequently (i.e. mouse movements makes the button change background, and stuff like that). I know InvalidateRect, but my bitmap class doesn't handle that, it will still draw the whole background all over again.
And I'm takin' over the whole dialog's paintin'. That means the background will even go up to the screen size, which might be 1024x768! (The whole window will repain, when resized, even InvalidateRect won't help in this case.)
I've tried that approach, but seems slow, maybe I should use InvalidateRect whenever possible. Thanks again for your solution man
Me,
Baling.
|
|
|
|
|
Dear Friends
In my project i am changing the font size but as it is increasing it is going beyond the limit of display size.How to control the dispaly according to the size of font.
Kindly help me in getting the solution.
Thanking you in advance.
Binnu
|
|
|
|
|
How can i get Dynamic IP address of my pc.
is there any API in vc++ for retreiving dynamic ip address of my pc?
please help me?
|
|
|
|
|
Check IP Helper functions: MSDN->Platform SDK->Networking and Directory services->Web Network Services->Internet Protocol Helper.
It seems that you need GetIpAddrTable.
Regards,
Gennady
|
|
|
|
|
Hello.
I began my journey to learn and practice programming using C++ four nearly four months ago and everything has been full speed thus far. I have little problem learning C++ because I practice and practice. I made up my own projects. I have one of them done, which I believe it quite impressive. I am working on the second project, which is going well especially because of all the insight from members throughout the web.
Sometimes I see students programming with Java. C++ is the first programming language I enjoy and made use of with in terms of practicality via projects. Frankly, I love C++! I would like to know how does C++ compare to Java in terms of extensiveness and future? Does C++ have the tools for anything if the programmer chooses to use them?
I know Java is a server based language. However, I am seeing more and more people programming with Java. Is it easier to learn? Not that I have any big problem with C++. I wonder why people sometimes move from C++ to Java.
Lastly, what is the future of C++ once Microsoft releases .NET? Already I am hearing people boast C#. Is it true C# is relatively Jave-clone? If yes, then that could make Java one step ahead of C++ if it infact has something that Microsoft has implemented in C#.
Frankly, I do not see any limitation with C++. Maybe that is just because of my inexperience. What do you think?
Kuphryn
P.S. Is it better to know one language really, really well? Or is it better to know many languages?
|
|
|
|
|
I cant find a decent C resource similiar to the code project. Can someone please direct me to a good site that deals with windows programming in C.
Most appreciated,
SAK
|
|
|
|
|
- CodeProject.com is the only one you need! -
If you want to learn C, buy a book! They are very helpful if you are serious to programming and want to have a job or bla bla, so my advice is: Buy a book!
If you don't have cash, see programmersheaven.com then
------------------------------
©0d3 ©®4©k3® - That's me!
------------------------------
|
|
|
|
|
If anyone has had experience in writing and HTTP server I could use your advice.
I have been pulled into a project which involves modifyng existing HTTP server code to make the file down load work correctly. Where can I find the full spec on this. At present, unless the complete file is assembled in a buffer the server hangs. In the embedded environment we have serious memory constraints and can not prepare the data as a single large file and must send it in bits. The client end must however think it's a single file.
Any ideas on the structure of each packet would be welcome.
Happy programming!!
|
|
|
|
|
You're giving very little context to allow for an useful answer, but anyway...
The client should cope with the whole file as long as the server returns the contents of the file as the response to the HTTP request (i.e, thru the socket created in response to the HTTP request). It is not a matter of wheter you send it in chunks or all at once, what you have to investigate is the means of having the little chunks sent thru the same response socket. If this is already clear to you, then I guess little more can be said without knowing more about your environment.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I'm sorry, at this stage I don't much more about it myself. The source code is still on it's way (long story to do with international projects), but what I can work out is that when this server is sending out the chunks it omits something important in the chunk's header. That is why I'm trying to find a spec that will tell what the header in each chunk must have. Perhaps it's even the header of the first chunk is missing vital information.
I'm once I see the specification it won't be too hard to fix.
Happy programming!!
|
|
|
|
|
The HTTP spec is RFC 2616. Chunked transfers are described in section 3.6.1:
3.6.1 Chunked Transfer Coding
The chunked encoding modifies the body of a message in order to
transfer it as a series of chunks, each with its own size indicator,
followed by an OPTIONAL trailer containing entity-header fields. This
allows dynamically produced content to be transferred along with the
information necessary for the recipient to verify that it has
received the full message.
Chunked-Body = *chunk
last-chunk
trailer
CRLF
chunk = chunk-size [ chunk-extension ] CRLF
chunk-data CRLF
chunk-size = 1*HEX
last-chunk = 1*("0") [ chunk-extension ] CRLF
chunk-extension= *( ";" chunk-ext-name [ "=" chunk-ext-val ] )
chunk-ext-name = token
chunk-ext-val = token | quoted-string
chunk-data = chunk-size(OCTET)
trailer = *(entity-header CRLF)
The chunk-size field is a string of hex digits indicating the size of
the chunk. The chunked encoding is ended by any chunk whose size is
zero, followed by the trailer, which is terminated by an empty line.
The trailer allows the sender to include additional HTTP header
fields at the end of the message. The Trailer header field can be
used to indicate which header fields are included in a trailer (see
section 14.40).
|
|
|
|
|
Thank you heaps
THis is what I am looking for. I have found that not all of this is being put into the 'chunk' by the present server code.
Happy programming!!
|
|
|
|
|
|
Last month I posted a problem about my dialog buttons not responsive. Thanks to reply posted by Christian, that's solved by using a worker thread.
I'm now having a couple of problems after solving the above. Hope someone can advise.
The worker thread is started when the user clicks on the CONVERT button. I then change the Cancel to be the default button, so that a simple Enter
would abort the very lengthy conversion.
void CConvert::OnConvert()
{
// start the worker thread
AfxBeginThread(MyThreadProc,this);
// change the buttons
m_convert.SetButtonStyle(BS_PUSHBUTTON);
m_convert.EnableWindow(FALSE);
m_ok.EnableWindow(FALSE);
m_cancel.SetButtonStyle(BS_DEFPUSHBUTTON);
m_cancel.SetFocus();
}
// my worker thread
UINT MyThreadProc (LPVOID pParam)
{
CConvert * pObject = (CConvert*)pParam;
pObject->DoConvert();
return 0;
}
// my original code to do all the conversion
BOOL CConvert::DoConvert(void)
{
// lots of code up here not shown
//
if (AbortFlag)
{
// conversion was cancelled. Dialog box is gone.
return FALSE;
}
else
{ // normal completion. Dialog box still visible.
// make the OK button default
m_convert.SetButtonStyle(BS_PUSHBUTTON);
m_convert.EnableWindow(TRUE);
m_cancel.SetButtonStyle(BS_PUSHBUTTON);
m_ok.SetButtonStyle(BS_DEFPUSHBUTTON);
m_ok.EnableWindow(TRUE);
m_ok.SetFocus();
// UpdateData(FALSE); // Cause Assertion Fail. Why?
}
return TRUE;
}
1/ After sucessful conversion the OK button is shown as the Default button, but when I hit Enter, conversion starts again. Seems like the focus is still on the Convert button. How come?
2/ I tried UpdateData(FALSE) but it caused an Assertation Fail. Why?
3/ I think I'm wrong to put all these button manipulations in the worker thread. Maybe I should be using a timer in the Dialog to periodically check on the status of the worker thread and then do these manipulations after the thread is done. Your advise please.
|
|
|
|
|
Hello, the codegurus around the world.;)
I have the same experience about UpdateData (FALSE).
Even though I didn't do this, try to use SendMessage (or PostMessage)
to update Button stuffs by the user defined message.
I think that Timer is the good option.
BTW, why do you use UpdateData (FALSE)?
UpdateData(FALSE) updates the string by the memeber value in the class wizard
because you only use the control value in the class wizard.
Please, don't send me your email about your questions directly.
Have a nice day!
Sonork - 100.10571:vcdeveloper
-Masaaki Onishi-
|
|
|
|
|