|
You are correct. It does automatically. Thanks for pointing that out!
Best wishes,
Navaneeth
|
|
|
|
|
Luc Pattyn wrote: ...it seems to know from the extension (as it should IMO).
It always has for me. I've never changed compiler options when switching between C and CPP files.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
No need to switch settings, see my 2 replies to nananeeth.
|
|
|
|
|
PC17 wrote: What project i must open?
Just start a new project and select either Console or Windows app, VS will create a skeleton project for you to add your own code and will automatically select the correct compiler options. If you do not know how to use Visual Studio then take a look at some of the self study guides on the start page.
It's time for a new signature.
|
|
|
|
|
|
Walkthrough: Compiling a C Program
Like this link works the compiller but so i must write the code with notepad or an editor.
But how can i make a new projekt in VS10 and compile it there, so as with C#.
What i must do? I open a new project then ?
|
|
|
|
|
Choose "Empty project". When adding files, specify extension as C (actually extension doesn't matter). Now on the project properties, choose "Compile as C" option.
Best wishes,
Navaneeth
|
|
|
|
|
Message Closed
modified 2-Apr-21 5:21am.
|
|
|
|
|
"Project" menu -> Properties(last menu) -> C/C++ -> Advanced -> In right side "Compile As" -> "Compile as C Code(/TC)".
--
"Programming is an art that fights back!"
|
|
|
|
|
N a v a n e e t h wrote: actually extension doesn't matter
I don't know for the 2010 version, but for the 2005 version, if your file has a c extension, it will be automatically compiled as C code. So, the extension does make a difference.
|
|
|
|
|
New Project -> Visual C++ -> Empty Project
In Solution Explorer window, right click & select "Source Files" -> "Add" -> "New Item"
On left side of the "Add new item" dialog, select "Code"
In the file name field type "YourFileName.c" and click "Add"
Write some code in the file like below and press "Ctrl + F5", you can see the output:
<br />
#include "stdio.h"<br />
<br />
int main()<br />
{<br />
int nNum = 10;<br />
char cChar = 'a';<br />
printf("%d", nNum);<br />
printf("\n");<br />
printf("%c", cChar);<br />
printf("\n");<br />
<br />
return 0;<br />
}<br />
Regards
--
"Programming is an art that fights back!"
|
|
|
|
|
I'm using a CStatic as a 'draw' window in a dialog. To get the extents of the window I'm using:-
CDC *pDC;
CWnd *wnd;
CRect R;
pDC = AWindow.GetDC();
wnd = pDC->GetWindow();
wnd->GetClientRect(&R);
This works fine in Debug but craps out in Release, at the moment I'm stumped, I've narrowed it down to being wnd=pDC->GetWindow() as the problem, or at least thats where is stops, any ideas?
|
|
|
|
|
Where is that code ?
If it is in the OnPaint method, you need to use CPaintDC .
to get the rect of the static control, can't you simply use this->GetWindowRect(rect) ?
Watched code never compiles.
|
|
|
|
|
Forgot about this->GetWindowRect(), now works
Don't know why GetWindow didn't work though...
But thanks
|
|
|
|
|
I have multiple derived classes and a function that accepts their (abstract) base ptr.
Right now I have a lot of code like this in my function:
void foo(BaseClass* p)
{
if (DerivedClass1 *p1 = dynamic_cast<DerivedClass1 *>(p))
{
...;
}
else if(DerivedClass2 *p2 = dynamic_cast<DerivedClass2 *>(p))
{
...;
}
}
I want to replace it with a switch if possible:
switch (p.type_id)
{
case DerivedClass1.type_id: ...; break;
case DerivedClass2.type_id: ...; break;
}
is that possible to do?
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Derived class ids
#define ID_DER1 01
#define ID_DER2 02
in base class, add a pure virtual function
virtual int GetTypeId() = 0;
its implementation in derived classes
int DerivedClass1::GetTypeId()
{ return ID_DER1; }
int DerivedClass2::GetTypeId()
{ return ID_DER2; }
and the foo function looks like
void foo(BaseClass* p)
{
switch (p->GetTypeID())
{
case ID_DER1: printf("der1");
break;
case ID_DER2: printf("der2");
break;
}
}
|
|
|
|
|
As far as I know, it's not possible.
However, your code doesn't seems very nice: you are really breaking some basic principle of OOP. Why do you need to access the specific types ? Can't you instead use virtual functions and let each type implements the expected behavior as needed ?
|
|
|
|
|
I use this to pass notification messages for progress updates, task finished, etc. from worker threads. I use it instead of callbacks. Some messages need their own userdata (hence derived classes, which contain the userdata). I could use callbacks with void* pParam for the userdata, and an ID to show the type of message (like PostMessage does), but RTTI already gives me the ID. The receiver of the message is not always derived from CWnd (otherwise I would have just used PostMessage instead of this whole thing).
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
I still don't really understand what you need to do differently for the different types . If these are some kind of "typed" messages, can't you just provide a virtual getText method that is overriden by each type ?
I really don't understand your scenario: what are those objects and why do you need to handle them differently based on their types ?
|
|
|
|
|
Quick Question: What does switching on a type mean... especially if you're dynamically casting the result?
Answer: It means you're missing a virtual function!
So don't mess about with switches and casting, add a virtual function to the base class. This will give you three benefits:
- SPEEEEED - a virtual function call will always as fast or faster than a switch on a type_id
- It makes your code a lot easier to read. Your switch/if/then else is replaced by 1 line, yep
- It makes your code a lot easier to extend. If/when you add a new derived class you just have to implement the derived class, you don't have to mess about with the client code.
SO... Just say no to switching on type_id. You know it makes sense.
Cheers,
Ash
|
|
|
|
|
Couldn't agree more
|
|
|
|
|
Hi all,
i m using a button and create its variable from CBitmapButton derived class,
and load bitamps on this button CBitmapButton::LoadBitmaps function.
but when i focus the button and press enter key here the button is not pressed while its working for space key.
please help me for this.
thanks in advance.
|
|
|
|
|
This if I remember correctly is exactly how it should behave. On a Dialog pressing enter will 'click' the dialog's default button, otherwise you will need to handle WM_KEYUP and trap VK_ENTER
|
|
|
|
|
|
Hi all,
I want to add a combobox in a List control
when clicking a column in the list control
How to do this?
|
|
|
|