|
You Don't seem to understand what 'Scope'Means. Maybe you just migrated from QBasic or so...
I'll explain this basic stuff just this once! You Start at File Scope. That's where you declare and define Golbal Variables, and Global Statics. NO ACTION CAN TAKE PLACE THERE! (except assigning Fixed Values to Variables).
Action can only take Place in a Function. Any Statement, (that is things where Action takes Place, susch as c=a+b; if(Something)doSomething(), has to take place inside a Function. A function is a Named Global Variable to which a list of Actions is attached. it is declared and may also defined in the standard way, but it is distinguished as a function because it is followed by (...)
For instance:
int A; declares a Variable of type integer, named 'A'
int A=10; does the same, but also gives it the value 10, (defines it)
int A(); declares a Function Variable Named 'A'
int A(){.....} does the same, but also defines what the function does, by the code included by the brackets. That Code is at Scope Level1 (File Scope being Level 0). This is the plase where the If, When and Whatever Code goes. (As you have in your File). The Scope level can be further increased, by nesting more {...} pairs inside it, but That's a prety advanced subject from where you are now, Save to say, You're NOT allowed to write another function inside the body of a function. (That is Different in languages susch as say Pascal). Try itin C or CPP, and you get plenty of error messages,the compiler will choke.
Functions can only be called from Other functions, and you cannot start a Function in File Scope. So, the phylosophical question arrives, 'How does it all Start'Afteral, in QBasic, it starts with the first line of Code.
That's where a Special function comes in. (Mostly) every C Program starts with a function called 'main()' Some programs start with differently named programs, and in some cases the definition of the main() program is more involved, but again, those are pretty advanced subjects from where you are now.
But, if you want to write a basic program, include all your first actions inside a function called main().
If you try this with the above snippet (I did not try it, I must admit), it will almost certainly NOT work.
The Service 'InternetGetConnectedState'requires a complicated environment around it. This again, is a very advanced subject from where you are now.
Instead of this, why don't you replace it with 'printf("Hello World");'and then build up to more difficult (and more Usefull Cases).
Unfortunately, we in the Code project cannot 'Donate'Knowledge. You have to gain it yourself, and I hope I pointed you in the right direction.
Bram van Kampen
|
|
|
|
|
Hello, first let me tell you of my basic information.
OS: Windows xp, IDE: Codeblocks 8.02, Compiler: GNU GCC Mingw32.
Let me start by saying that I've had no problem linking SDL or OpenGL by themselves, just together. The following code is at the top of the main.c file:
#include <vector>
#include <SDL/SDL.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glext.h>
the result is linker errors regarding opengl:
C:\Program Files\CodeBlocks\Source Files\simple2\main1.cpp|44|undefined reference to `_glEnable@4'|
etc., for all opengl functions. If someone can suggest how to fix it up, I'd be obliged. Thanks for your time.modified on Thursday, March 18, 2010 2:54 PM
|
|
|
|
|
bala_48225 wrote: Let me start by saying that I've had no problem linking SDL or OpenGL by themselves, just together.
In your linker settings try opengl32.lib glu32.lib before SDL libraries.
Hope it helps, I am just a guessing here.
|
|
|
|
|
that did the trick, just adding those two to the linker
|
|
|
|
|
Hi,
I have a dialog, a main dialog(MainDlg) that on press of a button creates another 12 dialogs, hidden.
All 12 dialogs hava about 20-25 controls on them and when i all Create for each of them the maindlg freezes for 1-3 seconds. I am thinking of creating a thread that creates all 12 dialogs when MainDlg begins to initialize.
So what I am doing now and it's not working. I have created a new class derived from CWinThread.
OnInitialise I have put: create(FirstDialog:IDD,g_thisParent)...g_thisParent is CWnd * pointing to 'this'. I made a function, Setup(CWnd *, Cdialog **dialogs); this is the pointer sent from OnInit of the maindlg functio.
On mainDlg ->Oninit, i have created CDialog *dialogs[12];
all dialogs are NULL and then dialogs[1]->new....(this);
anyhow: i start the thread with AfxBeginThread suspended, i call for Setup, and then I resume the thread.
I get assertion faild when I try to create using this as parent, but not when i use (CWnd*)this->GetParent wich is 0 . I don't want my dialogs to be the child of desktop window, I want them to inherit maidlg....what shall i do?
Is this a corect approach of the problem?
|
|
|
|
|
Do not create UI stuff (dialogs, controls, ...) from you secondary thread.
In you thread, you need to notify (for example using PostMessage) your main dialog to create the child dialogs.
read : http://www.flounder.com/workerthreads.htm[^]
excerpt :
"That's right. A worker thread must not touch a GUI object. This means that you should not query the state of a control, add something to a list box, set the state of a control, etc."Watched code never compiles.
|
|
|
|
|
But the problem is that I must create the dialogs at sometime.
I have a menu
Backup
Restore
shedule
whatever
backup has 12 dialogs........ if i click on backup button i must wait.
I cannot avoid the creation of those dialogs. when clicking on backup they must be created, and when i create them, each oninit function in the dialog starts from 1 to 12.
In thread everything is ok....i win a lot of time(3 seconds) and when I click on backup......i seems it instantly loads. The only problem I get is that i can't set the parent right...
|
|
|
|
|
Why do you need to create ALL your dialogs when the main dialog starts ?
Me think it's bad design to do so, only create dialogs when you need them.
Anyway, unless you are doing some weird things, creating a dialog should not take that much time.Watched code never compiles.
|
|
|
|
|
Yes indeed the design is bad, and the problem problem started from weird things. There were some variables uninitialized entering in a loop from 0 to a few milions;)) so i was suggested to use a thread to create dialogs so i got stuck on this ideea:P
the problem is, that i can jump from a dialog to another.
|
|
|
|
|
I don't think this will work as you are creating them as part of the second (temporary?) thread when you want them to be part of the main GUI thread.
Instead, since these dialogs start out hidden, why not defer their creation. Set up a wrapper to create them on first display. This distributes the work so that you don't take the full hit all at once and it should be less noticeable.
You could also set up something to create them one at a time in CWinApp::OnIdle(), though you will need to make sure they are not used until created. You could combine this with the create on first demand scheme if you want.Please do not read this signature.
|
|
|
|
|
Good point, but using UI thread it's ok, my question is why i cannot set the parrent right, I think it has something to do with sending 'this' as param in Setup function....should I sent a handle to the window instead....the problem is I don't know how, I'm new in MFC GUI;))
|
|
|
|
|
In your thread, just post a message to your main dialog with (no data) and in that message handler in your main dialog you should be able to create your dialogs without problems. Watched code never compiles.
|
|
|
|
|
After doing a little checking, evidently you can do it with child windows on a 2nd UI thread. You do have to be careful about communications between the threads since there is a possibility of creating a deadlock between the threads. I would still tend to favor using OnIdle() instead of a 2nd thread to try and deal with your performance issue.
Apart from some quibbling over precise wording, I don't see the problem with what you are doing. As far as my quibbling goes, in the parent window code you call a setup function passing "this" as a parameter so that the thread class can save its value in a member variable called g_thisParent. g_thisParent is not a pointer to "this", it is a CWnd * to the parent window object. Also, in the second thread, you never, ever use "this" in an attempt to refer to the parent window, you use the variable you have named g_thisParent.
Other than that, my only thought would be some sort of synchronization issue - but I don't see what it would be.
Please do not read this signature.
|
|
|
|
|
bu7ch3r wrote: ...that on press of a button creates another 12 dialogs...
...the maindlg freezes for 1-3 seconds.
...what shall i do?
Do not press any button to create them,
just create them all in CMainDlg::OnInitDialog() virtual void BeHappy() = 0;
|
|
|
|
|
yes, but that makes the gui start slow .
|
|
|
|
|
Place a good splash window in another thread for your start virtual void BeHappy() = 0;
|
|
|
|
|
=))))) i am creating a serious application for my university degree:P I's a good ideea anyhow
|
|
|
|
|
How Could I Use a define macro identifier in an other define macro replacement list?
for example in the following example:
#define APP_TEST1 L"Test1"
#define APP_TEST2 L"Test2"
#define APP_TEST L"Test1 With Test2"
I want to represent the third define macro with 2 first macro?
|
|
|
|
|
#define APP_TEST APP_TEST1 " With " APP_TEST2
|
|
|
|
|
|
be really careful with macros, because it is hard to debug and in can lead to really bogouis errors.
=>
//const LPTCSTR APP_TEST1 = L"Test1";
const LPCTSTR APP_TEST1 = L"Test1";
...
Code quality is also an important issue
Press F1 for help or google it.
Greetings from Germany
modified on Friday, March 19, 2010 3:30 AM
|
|
|
|
|
KarstenK wrote: const LPTCSTR APP_TEST1 = L"Test1";
It should be LPCTSTR .
|
|
|
|
|
Good catch
|
|
|
|
|
Hi;
I am working on a project involving a PC onboard a robotic vehicle transceiving (say using Wifi 802.11 connection) sensors' info to another PC housed in another moving vehicle. There are data exhchanges in both directions in real-time. I am totally new to networking/comm between PCs. Please point me to sample code/tutorial on this topic.
Thanks.
Fun Wey
|
|
|
|
|
|