|
<homersimpsonvoice> mmmmm....filet-o-fish...</homersimpsonvoice>
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: I'm not sure why my posts got voted 5....I haven't helped any
Sure you've helped (maybe just a little bit by pointing me to the right direction). I generally vote either 1 or 5. I have difficulty deciding in between
The msdn page you referred states that the visual aspect is provided by the new ComCtl32.dll and UxTheme.dll in Windows XP. Can I include these 2 dll's from my XP, then load them in run time if the OS is less than XP?
I'll poke around some more. If I ended up giving up, I'll just check the OS version in the ThemeButton class like you suggested.
Thanks.
|
|
|
|
|
It looks like you are initializing a static variable with the result from GetProcAddress and that's not a recommended practice because the application is not fully initialized. You can find some interesting blog entries about these issues on this page : http://blogs.msdn.com/mgrier/archive/2005/06.aspx[^]
It is best to initialize the function pointer to NULL and make the call to GetProcAddress later during "real" application execution.
|
|
|
|
|
But the code runs fine on XP...
I don't have Win2K box with me right now, so I'll try your idea tomorrow.
Thanks.
|
|
|
|
|
I want to make an application which parses a .h file, and for every enum in it, output a function to print the members (like so
enum { eVal1=1; eVal2=2 } SomeEnum;
would generate the following function:
const char * getSomeEnumString ( SomeEnum e)
{
switch (e)
{
case eVal1: return "eVal1";
case eVal2: return "eVal2";
default" return "Unknown";
}
}
I'm wondering if someone knows an easy way to do this (without having to write my own C-Language parser). Ideally I would like to modify it in the future to dump contents of structures as well.
John
|
|
|
|
|
When you encounter the enum keyword, start parsing from that point. For each { brace encountered, increment a counter. For each } brace encountered, decrement a counter. When the counter is 0 and you find a semicolon, stop parsing.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Further to David's answer, don;t forget that people can do:
enum Fwibble { fwibOne = 9, fwibTwo, fwibThree, fwibFour = 99, fwibFive };
At least you're just looking for stuff between two {}'s, with no further internal {}s like you'll get for structures!
Iain.
|
|
|
|
|
Yeah, I was kind of hoping to avoid having to write my own parser (lazy or efficient -- you choose )
Structures will be a pain because of type names and sub-strucutres, so that one is being put off for a bit. I'll post my code once I have it going.
John
|
|
|
|
|
Do yourself a favor and pick up a book on one of the parser / compiler tools -- lex, yacc, bison, (or something newer as I haven't looked at this sort of stuff in 20 years) and do it the proper way. It's not as hard as you think and you'll be left with a very flexible system. Most of these tools come with basic C parsers as examples so you will have a guide to work / cut & paste from.
I work with a message based system. It uses a tool that parses all header files and creates a database of message formats based on each message's struct. It also retains #define values (that were needed anyway to resolve the structs) to allow constants to be used in flat files.
The tool was written by a new hire that had no prior experience with lex and yacc. Actually, at the time he told me he knew all about it which is why he got assigned the job -- it turned out he ran out that night and bought the lex/yacc animal book and had a crash course. End of story is he had it done in a couple of weeks and was the Hero of the Day. We still use the same program over a decade later.
|
|
|
|
|
i declared a static thread funtion in my CMYDlg class:
static UINT __cdecl Start(LPVOID pParam);
in the cpp file,Start function is defined as following:
UINT __cdecl Start(LPVOID pParam){
do{
//some stuff
Outputdata();
//some other stuff
}while(Run==True)
}
The Outputdata function is defined as:
CMYDlg::Outputdata(){//get the slider position and write into a data array
int i;
for(i=0;i<MAX;i++)
pbydata[i]=m_SliderCtrl[i].GetPos();//having problem with this line
}
so what i'm basically doing is try to create a worker function that continuously output data from my data buffers, by changing the slider position, i can change the data in the array and corresponding output.
the problem i'm having that when i compile, i got error saying m_SliderCtrl[i] is nostatic, and GetPos has to be follow some kind of struct.
could anyone help me fix this problem?
|
|
|
|
|
in static member functions you cannot access instance (i.e. non static) members. If you need to access instance members then pass this as parameter to your static member function.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
i think i did pass " this" to the function
CWinThread* pThread=AfxBeginThread(Start,this);
in the start() function , i modified:
CMyDlg* me=(CMYDlg*)pParam;
//something here
me->Ouputdata();
but it still doesn't work
|
|
|
|
|
alberthyc wrote: but it still doesn't work
What is the error message?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
You're trying to access a class member from within a static function. Static member functions have no concept of an instance of a class, so you can't access a member variable of an instance which doesn't exist... make sense?
So you do need to pass in the 'this' pointer, and you need to use the this pointer to access the variable.
In your case, you call Start (which does not have a class instance), which then calls Outputdata (which is also static, and thus has no class instance). Outputdata, then tries to access m_slider, but, because you have no class instance, you're essentially trying to do NULL->m_slider, which the compiler doesn't like.
So you were on the right track in the above email, but you need to take it a step further:
Try:
CMyDlg* me=(CMYDlg*)pParam
me->Outputdata(me);
Then in outputdata:
...me->m_slider...
John
|
|
|
|
|
hi, this works, but i got new problems,
in function:
Start(LPVOID pParam){
CMy61xxTestDlg* me=(CMy61xxTestDlg*)pParam;
me->param1 = 0;
do{
...
me->Outputdata(me);
me->param1++;
.....}
param1 is declared as long param1; i got error: illegal reference to non-static member 'CMyxxxDlg::param1';
then i make param1 static, it compiled,
i got error like this during linking: xxxDlg.obj error LNK2001: unresolved external symbol "public: static long CMyxxxDlg::param1
what's going on????
|
|
|
|
|
alberthyc wrote: but it still doesn't work
Yes MFC CWnd is not freethreaded. MFC uses thread local storage to contain the map of HWND and CWnd objects, or something like that. There is like a 10 year old technical note on MSDN about it. You need to post messages to the UI thread and have it alter the User Interface.
|
|
|
|
|
What I do in this sort of case:
class CMyClass
{
...
UINT MyThread ();
static UINT __cdecl MyThread (LPVOID pParam)
{
CMyThead *pThis = (CMyThread *) lpParam;
pThis->MyThread ();
}
...
};
CreateThread (blah, ..., (LPARAM)this);
As has been said, you have to be careful about CWnds, as the the HWND -> CWnd mapping is done on a per thread basis. But if (eg) m_SliderCtrl already has been attached to a HWND, then you should be OK.
And if you're monitoring something in your thread, don't forget to Sleep (0) occasionally to be a good thread citizen on your PC!
Good luck,
Iain.
|
|
|
|
|
I am programming a MFC application in which I have to start another independently developed application on click of a button and continue with my application.
I could use _execv() but the control does not return to my application, until the other application is closed. Is there any other way to do this??
|
|
|
|
|
Look for 2 API calls:
CreateProcess is the raw win32 one, or you may be better off with ShellExecute (a bit friendler)
Iain.
|
|
|
|
|
Try to use the standard spawn() family of functions, using
_P_WAIT or _P_NOWAIT
as the 'mode'parameter.
Roberto
|
|
|
|
|
Does ShellExecute helpful?
|
|
|
|
|
Hi
In my vc++ 6.0 i used
THREADFUNCTION(WPARAM &wp,LPARAM &lp)
{
CString t_str;
t_str.format("%s",wp);
AfxmessageBox(t_str);
}
i Received the correct out put, here no problem.
I Compiled my programme in Visual studio 2005(vc 8.0)
It shows compile error , so iremoved all "&".
eg :(THREADFUNCTION(WPARAM wp,LPARAM lp) no compile error.
but there was an error in displaying result(its displaying some symbols)
THREADFUNCTION(WPARAM wp,LPARAM lp)
{
CString t_str;
t_str.format("%s",wp); /**** error ***/
AfxmessageBox(t_str);
}
how to convert WPARAM TO STRING in Visua Studio 2005.
Awaiting for the result.
Regards
shakumar
shakumar
|
|
|
|
|
Is it a UNICODE thing? I read recently that VC2005 defaults to unicode.
So, if you post the message in ASCII, then your thread function is using it as unicode, then you'll get a bunch of gibberish (if you're lucky).
Have you tried doing:
PostThreadMessage (blah, (WPARAM)_T("My String"), blah)
rather than:
PostThreadMessage (blah, (WPARAM)"My String", blah)
?
Iain.
|
|
|
|
|
Thanks for your Reply
I used String pointer
CString t_str="hai";
CString* p_str;
p_str=new CString (t_str);
PostThreadMessage(WM_USER+100,(WPARAM)p_str,0);
so can i use like this
PostThreadMessage(WM_USER+100,(WPARAM)_T(p_str),0);
regards
shakumar
shakumar
|
|
|
|
|
1/ Did you bother trying? If so, you'd have found out the answer which is:
2/ No, and it will hopefully give you an error message when compiling.
What I would do next is to go a bit simpler, and post:
PostThreadMessage (WM_USER + 100, 1234, 5678);
and see if the thread message bit is working properly. If they are, then see what the value of p_str is before you post it, and when it is received. And so on. If that is OK, use the Memory tool of the debugger to see the contents pointed to by p_str.
One thought that occurs to me:
p_str points to a valid bit of memory when you post it. Does it still point to a valid bit later? (ie when the message is received). Is it possible that the CStrings destructor has been called, and the memory is now filled with junk?
Iain.
|
|
|
|