|
How can i use a dialog from a thread ?
Code below doesn't work.
DWORD WINAPI s(LPVOID params)
{
CDialog d;
d.DoModal(); // ASSERT problem here
}
CreateThread(NULL,0,s,(LPVOID)this,0,&thID)));
|
|
|
|
|
If you are using MFC, then using MFC to create your thread, not WIN32.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
1. What does the ASSERT say?
2. Is the CDialog class really called "CDialog"? It should be a class derived from CDialog, not CDialog itself.
3. Have you thought of using a modeless dialog instead? It simulates a modal dialog box on a separate thread:
static CMyDialog s_dlg;
if (!::IsWindow(s_dlg.m_hWnd))
s_dlg.Create(CMyDialog::IDD);
s_dlg.ShowWindow(SW_SHOWNORMAL);
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
|
|
|
|
|
I've overriden WM_TIMER in my ListView class,and put SetTimer in OnInitUpdate(),but my WM_TIMER called only one time.Any idea?
::SetTimer(NULL,NULL,10000,NULL);
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
give ur timer an id
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
No change.It called only once again.
::SetTimer(GetSafeHwnd(),10000,10000,NULL);
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
I find it out.It called whenever the view is focused. Thanks.
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
I'll make this as concise as possible.
I have an MDI application which performs some mathematical
calculations. The end result is a double. I would like
to have that double value displayed in the client area of the
MDI window, at the location of the mouse pointer, when a user clicks the right mouse button. As it stands right now, when OnRButtonDown() is called, the calculation is done and I use an AfxMessageBox() call to display the double value. I don't particularly like the effect of this, so I would like to display the value using a call something like:
void ShowText(double Value2Show, CDC* pDC)
{
// Do nifty stuff to show number on DC
}
I suppose the biggest problem I have is changing the double
to a form to be displayed on the DC. Is there an easy way of doing this?
Could someone enlighten me as to what the "Do nifty stuff" part should contain?
|
|
|
|
|
The double needs to be converted to a string so that it can be displayed using an appropriate CDC method, such as TextOut.
CString strValue;
strValue.Format(_T("%lf"), Value2Show);
pDC->TextOut(123, 456, strValue);
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
|
|
|
|
|
If you want to display the text at the location of the mouse pointer then put the following in your OnRButtonDown handler
CClientDC dc(this);
OnPrepareDC(&dc);
dc.DPtoLP(&point);
dc.TextOut(point.x, point.y, yourstring);
The DPtoLP function converts the mouse coordinates from device coordinates to logical coordinates
Gary Kirkham
A working Program is one that has only unobserved bugs
I thought I wanted a career, turns out I just wanted paychecks
|
|
|
|
|
How can I get the position of percentage symbol and format a string ?
E.g. 45% or %45
Thanks
Orcun Colak
|
|
|
|
|
char buffer[1024];
int n = 45;
sprintf(buffer, "%%%d", n);
|
|
|
|
|
I was not clear. My mistake sorry.
I wanted to format a percentage according to system settings but I do not know how to get system settings.
For example in US percentage is formatted like 45%
Somewhere else it is %45.
How can I output the correct percentage according to system settings.
Thanks
Orcun Colak
|
|
|
|
|
orcun colak wrote:
For example in US percentage is formatted like 45%
Somewhere else it is %45.
Are you sure about this? Why is there no way to set this in the Control Panel? There's even no mention of a % symbol or position, nothing. The GetLocaleInfo API doesn't mention it either. It seems like the percent sign is universal and I would imagine that so is it's position.
At any rate, if you're sure there's (weird) people out there who prefer to see it on the left, you may have to handle it yourself, which isn't too difficult.
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
|
|
|
|
|
Actually I found this link in msdn
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vjref98/html/java.text.NumberFormat001.asp
Scroll to getPercentInstance() method. Explanation of the method is :
"Returns a percentage format for the current default locale."
Therefore I assumed Number % format is not universal.
Thanks for your help
Orcun Colak
|
|
|
|
|
23, woohoo!
todo....
:: insert inpirational text here ::
|
|
|
|
|
tsk - a non-programming question in the programming forums?
What is the world coming to?
Go to the lounge, and say that again, and I'm sure you'll get a few s
(happy birthday, btw. You now get an entire year of the blink 182 "nobody loves you when you're 23" line bouncing around your head or is that just me?...)
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
I have a binary file and its got stuff in it that looks like:
10 20 10 30 etc.
What I need to do is replace the first two numbers so that the file looks like:
a b 10 30 ....
Can I trouble you for some sample code that does this? The file extension is something weird....not .txt or anything like that...
Appreciate your help,
ns
|
|
|
|
|
two options
1) Open your file as a binary file - seek to the positions you want to change and write new bytes to it then close the file
2) open your file as a binary file, read in the whole lot to a buffer of bytes, modify the bytes you want to change and write it back and close
Have a look at the CFile docs in MSDN (if you're using mfc, that is)
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
A spot of trouble. I dont have a binary file to test it with. But I did this:
void CReadin2View::OnButton1()
{
CFile myFile;
myFile.Open("C:\\abc.dat", CFile::modeReadWrite);
long length = myFile.GetLength();
char * buf[length];
myFile.Read(buf,length);
buf[0] = 'p';
buf[1]= 'k';
myFile.Write(buf,length);
}
Even though I dont have abc.dat yet, it should compile right?
I'm getting errors:
Compiling...
readin2View.cpp
C:\readin2\readin2View.cpp(130) : error C2057: expected constant expression
C:\readin2\readin2View.cpp(130) : error C2466: cannot allocate an array of constant size 0
C:\readin2\readin2View.cpp(130) : error C2133: 'buf' : unknown size
C:\readin2\readin2View.cpp(134) : error C2440: '=' : cannot convert from 'const char' to 'char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
C:\readin2\readin2View.cpp(136) : error C2440: '=' : cannot convert from 'const char' to 'char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
readin2View.obj - 5 error(s), 0 warning(s)
Question 2:To make a binary file,
void CReadin2View::OnButton2()
{
CFile myFile;
myFile("c:\\abc.dat", CFile::modeCreate |CFile::modeWrite );
myFile.Write ( <code>....how to write some binary stuff to this file?</code>..)
}
Appreciate your help,
ns
|
|
|
|
|
ns wrote:
char * buf[length];
That should be:
char * buf;
buf = new char[length] (and remember to delete it afterwards - oh, and a myFile.Close() after you've written wouldn't go amiss, either)
ns wrote:
....how to write some binary stuff to this file?..
Easy - just make a buffer exactly the same way as you do in the OnButton1 member (after my fix, ofc), fill in the values to the buffer array, then write it (again in exactly the same way)
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
Guess my question is this:
If it were text I'd do
buf[0] = 'y';
buf[1] = 'l';
etc etc,
but I want my file to be binary, so how do I write a binary char, and how does my CFile know that I want a binary file not a text file?
The thing looks like:
10 20 30 40 etc when I open it in a binary editor. SO am I suppodsed to do:
buf[0] = '10';
buf[1] = '20'
For sme reaso n I dont think so....
Whats getting me is that you have flags like 'rb' etc in
(!(fpIn = fopen(inputFile,"rb"))
but I want to use MFC
Appreciate your help,
ns
|
|
|
|
|
in order to accomplish that u need to convert ur binary chars to ascii correspondant check out for this purpose CString::Format (keep in mind using (LPCSTR) operator to get back the char* if needed)
The flags are like CFile::typeBinary of nOpenFlag in ur CFile constructor or Open method
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
OOPs! Do I need to create a new file to write to? Because if I write to the same myFIle what will I get? I dont know if it will overwrite? Or will it append?
Appreciate your help,
ns
|
|
|
|
|
Depends how u create the file:
CFile::modeCreate or CFile::modeReadWrite
check CFile::CFile open flags
ull also need CFile::typeBinary so be sure to pipe it
CFile::typeBinary | CFile::modeReadWrite
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|