|
Ok I've got the function working with this:
HANDLE myConnectThread = AfxBeginThread(ConnectThread, (LPVOID)this->m_hWnd);
And in the thread:
UINT AlstomSerial::ConnectThread(LPVOID pParam)
{
::PostMessage((HWND)pParam, wm_Message, (WPARAM)0, (LPARAM)ps);
}
This feels a bit dodgy to me?? Anyone suggest a better way of doing this??
|
|
|
|
|
That seems about right. You may want to call ::IsWindow((HWND)pParam) first just to make sure the handle is valid. The parent window may have exited/died before the thread gets its hands on it. Stranger things have happened, and when multithreading, playing safe is a must.
|
|
|
|
|
Anybody know any good explanations of the inner workings of double buffering to remove flicker...?
I'm using the CMemDC class right now, but am currently experiencing problems, so i'd like to tackle the problem line by line and just do it manually.
I get the gist of it and even implemented it, but I used a bitmap from resource instead of creating it dynamically using CreateCompatibleBitmap. I'm doing something wrong and would like to see an exmaple of how to do it fom start to finish.
I'm aware of the classes currently on CP, but would like an explanation of double buffering with a small example I can pick apart and figure out what i'm doing wrong.
CreateCompatibleDC
CreateCompatibleBitmap
Select compatible bitmap into compatible DC
LineTo on compatible DC
BitBlt compatible bitmap to original DC
What am I missing here...?
Thanx a bunch!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Looks OK. Just remember to call CreateCompatibleBitmap for original DC, not the compatible, in-memory one.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
ok this is vexing me
i have a string like this:
blahblahblahblah$blahblahblahblah$
notice is contains $ characters.
i want to SPLIT this string using the $ as a delimiter.
The string is stored in a CString (i'm using MFC).
Can someone show me how I can tokenize this string. A SIMPLE example please!!!
ARGH, thanks!!
|
|
|
|
|
CString buff("This is$my string");
for(int x=0; x<<buff.GetLength(); x++)
{
if(buff.Find('$', x)){
CString strSplitLeft = buff.Left(x-1);
CString strSplitRight= buff.Right(x+1);
}
}
Notice this only splits a string in half nothing more. It find the first $ character and copies anything left of it to a buffer and anything right of it to another buffer.
It would reauire a littel tweaking to split a string multiple times.
Cheers!
p.s-Ignore the << it should only be one...but I don't know the excape code in HTML for single angle brackets. Sorry!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
|
omg thanks been looking for a simple way like that!!!!
|
|
|
|
|
Cool...that is easy!
Thanx Mike!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
I wish we could rate these posts like you can at CodeGuru - what a helpful post!
|
|
|
|
|
Please help, whats wrong with this code?
"if statment"
char r;
gets(r);
if (r == "ok")
{
cout << ("good job");
}
What wrong with that? how can i make it work?
Thanks!
~SilverShalkin
ps... im new to this forum, so if you see another thread like this one, im sorry
didnt mean to.
Programming is an art, dont spoil it with work.
|
|
|
|
|
Uh, a lot. First of all, "char" is a single character, not a whole string. You need to do an char array for a complete string, or use a CString from MFC. Second, you can't compare char arrays with the "==" symbol, you need to use "strcmp" ("==" does work for CStrings however).
So, correct code would look something like this:
char r[256]; //note that if user inputs more than 255 characters, program might crash
gets(r);
if(strcmp(r,"ok")==0)
{
cout << ("good job");
}
Cya (c:
|
|
|
|
|
Lofote wrote:
or use a CString from MFC.
Or in this case, use std::string seeing as MFC is not being used anywhere else in the code.
Lofote wrote:
Second, you can't compare char arrays with the "==" symbol,
Really ?
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
|
|
|
|
|
you cant compare char arrays with "==", then how do you do it?
Thanks
~SilverShalkin
What little life a rose may give, its the buety that will last forever.
|
|
|
|
|
With the strcmp() function.
Jon Sagara
What about ?
Sonork ID: 100.9999 jonsagara
|
|
|
|
|
Jon Sagara wrote:
With the strcmp() function.
or even lstrcmp(), if you want to use the Win32 api to do it.
impuzible
|
|
|
|
|
or _tcscmp().
Jon Sagara
What about ?
Sonork ID: 100.9999 jonsagara
|
|
|
|
|
I always liked being nice the the user...
_tcsicmp
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Bah - let 'em suffer, I say!
Jon Sagara
What about ?
Sonork ID: 100.9999 jonsagara
|
|
|
|
|
Ultimately, char arrays are ugly C, and also not safe, as has been noted. You'll end up using CString or std:string just like everyone else, but for some reason the books all take a low to high approach which shows you the std library AFTER you've learned things the unnecessarily hard way.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
|
|
|
|
|
People should still learn how to use C strings. They are very powerful and VERY safe when used properly.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Tim Smith wrote:
People should still learn how to use C strings.
Absolutely - I just dispute the idea they should learn it first...
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
|
|
|
|
|
Woops, my fault then. I misunderstood you.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Lofote wrote:
char r[256]; //note that if user inputs more than 255 characters, program might crash
gets(r);
if(strcmp(r,"ok")==0)
{
cout << ("good job");
}
Thanks man, although i did change the character memory amount to 255. The if statment worked!
This is awesome, thank you allot. Ill let the help files help me with how it works, and i may see you all later.
~SilverShalkin
The perfect puzzle, Programming.
|
|
|
|
|
Why did you change the buffer size to 255?
Is it really likely that your user will enter exactly 254 charcters but no more?
(remember, with char arrays for strings, you always need one more byte than the number of characters you plan to store. convention is to terminate strings with a 0 (aka NULL). All the LIBC functions (strcat,strcmp,strlen etc etc) depend on that.)
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|