|
Ya I am trying to do some drawing in NCPAINT handler ...
But some how I am not able to draw in the full rectangle ..
Just look at the following code and please what is wrong in the code..
CWindowDC cpDC (this);
CRect rcClip;
GetClientRect(&rcClip);
cpDC.FillSolidRect (rcClip,RGB(255,0,0));
the above code does not fill the full rectangle , it still leaves so many margins ..
Also please tell me the differnce between GetWindowRect and GetClientRect ..
Thank you very much
Abhishek Narula
"Learn to appreciate others ... World would appreciate you"
|
|
|
|
|
1 - GetClientRect is the problem
2 - GetWindowRect gets the whole window area, usually in screen coordinates ( i.e. relative to the top left ), and GetClientRect gets the client area only ( the bit you can draw in OnPaint ).
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002
|
|
|
|
|
Thanks a lot you have been a great help.
Abhishek Narula
"Learn to appreciate others ... World would appreciate you"
|
|
|
|
|
I have standart generated by ClassWizard SDI MFC-app. I want that some operation invoked by user that may be performed a while was displayed like dialog with progress bar and "Cancel" button. And while it's displaying, operation should performs, progress bar should displays appropriate value and so on till operation has been completed or user has clicked "Cancel"
What's the easiest way to implement that. After searching through MSDN some implementation approach has appeared but it's so difficult.
Thanks in advance.
|
|
|
|
|
It depends on what the process is. If it's under your control ( i.e. you are working with a set of your own data, using your code ), then a modeless dialog box, with a flag being set by pressing the cancel button, and the flag state checked after each iteration through the process taking place in a loop would be the best way.
If you're formating a hard drive, or some other process not taking place in your code, you'll need a thread.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002
|
|
|
|
|
Thanks but I can't understand how can I implement it in MFC way. Would you mind show me the way My task is first ie I want to operate own data
Thanks in advance
|
|
|
|
|
Morozov Alexey wrote:
My task is first ie I want to operate own data
So you don't have a task, you just want to know how to do it ?
CWaitDialog dialog; // A modeless dialog that creates itself in it's constructor
for (int i=0;i<10000000;++i)
{
// do something
if (dialog.bStopNow)
{
// Any necessary cleanup
break;
}
}
is all I had in mind.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002
|
|
|
|
|
You could create a new worker thread. This worker thread can do the background stuff and keep updating the progress control. Thus the cancel button on your main window will still be receptive and not frozen as you might be experiencing now.
Nish
The lady in red is dancing with me
Cheek to cheek
There's nobody here
It's just you and me
It's where I wanna be
But I hardly know this beauty by my side
I'll never forget the way you look tonight
|
|
|
|
|
This being the obvious solution, I guessed it may be the 'too hard' solution he found in MSDN.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002
|
|
|
|
|
You're about right It's no so hard, but I thought that building new thread, organizing some kind of inter-thread sinchronization is too big to doing such small task. Besides really I have had separate thread that perform that task already. But it's so bulky That why I decided to ask simplier solution.
|
|
|
|
|
Morozov Alexey wrote:
That why I decided to ask simplier solution.
I have always found that the simpler solutions are often the right solutions. The complicated solutions make you feel nice, but often just ends up in a mess.
KISS is actually true [except for the 2nd 'S']
Nish
The lady in red is dancing with me
Cheek to cheek
There's nobody here
It's just you and me
It's where I wanna be
But I hardly know this beauty by my side
I'll never forget the way you look tonight
|
|
|
|
|
Morozov Alexey wrote:
After searching through MSDN some implementation approach has appeared but it's so difficult.
Have you checked Feb'97 issue of MSJ - "Wicked Code" column by Jeff Prosise contains ready-to-use CWaitDialog class. The article may be in MSDN on your harddisk, if it's not there, go to msdn.microsoft.com
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Thanks a lot
I'll be searching more carefully in future. Sh*t, why did I can't find it myself It's really what I need.
|
|
|
|
|
Ok I posted before and some helpful folks advised me that I should use messages to communicate between my Dialog application and my threads connecting to a serial device. Trouble is I'm stuck on what the handles and messages are to send the messages so here's where I'm at:
Added this to .h file:
//}}AFX_MSG
afx_msg LRESULT OnCustomMessage(WPARAM w, LPARAM l);
DECLARE_MESSAGE_MAP()
Added this to .cpp file
const UINT wm_Message = RegisterWindowMessage(_T("A8479983-30B2-11d6-BD06-0010A4FDB6CB"));
//..snip ..//
ON_REGISTERED_MESSAGE(wm_Message, OnCustomMessage)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
And this is in the thread:
CString *ps = new CString("Thread is busy.");
::PostMessage(HWND_BROADCAST, wm_Message, (WPARAM)0, (LPARAM)ps);
So as I understand it, the thread posts the message wm_Message and when the window receives the message it calls the function OnCustomMessage. I'm pretty sure using HWND_BROADCAST is wrong, as it isnt working anyway. What handle do I need to give the post message function?? and the next question is how do I get this handle from the thread??
Hopefully this will be the best way of doing what I want to do? The aim is to have a dialog that connects to the serial device and updates List Box control with records in the device. The record selected is then requested from the device and saved to a file. The whole time I also want a richedit box to be displaying progress messages, and maybe updating a progress bar too! Is sending messages back and forth the way to do this or is there another way of sharing the data between the dialog and the threads?
Sorry for the long message and thanks again for any help
-Mark
|
|
|
|
|
Mark,
Change the HWND_BROADCAST to the window handle of the parent.
ie. PostMessage(hWndParent, wm_Message, (WPARAM)0, (LPARAM)ps);
The hWndParent handle can be passed into the thread during creation or maybe simply via another custom message...
A note of caution. Posting messages with pointers to memory is bad news. Make sure that memory posted from the thread to the parent is not cleaned up/garbled before or during the parent's processing of the message. In your example, your passing a new instance of a CString() which needs to be cleaned up by the parent.
|
|
|
|
|
Thanks for the reply,
This is what I'm calling to start the thread:
HANDLE myConnectThread = AfxBeginThread(ConnectThread, (LPVOID)this);
So how would I change it to pass it the hWndParent? Also how do I get the hWndParent value?? is it this->m_hWnd??? This whole handle thing has got me slightly confused.
Also I know how the parent needs to clean up the CString! A helpful person from here has already brought it to my attention!
Is there any better way of doing all this though?? I mean because these threads are static I obviously cant access the member variables of the dialog class directly. Is there other ways of making threads where I could be able to do this? I see there are other ways of meaking threads ie: CreateThread or _beginThread, whats the difference with the one I'm using and which would be betst?
Thanks
-Mark
|
|
|
|
|
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
|
|
|
|