|
I have a edit control (I am using c/sdk) which i tend to make it as text area to display my program message. the control has properties as:
vertical scroll, auto vscroll, want return.
I was wondering how can i add text in multiple line. for instance, i use
char *buf1 = "hello\r\n";
char *buf2 = "hai\r\n";
SendMessage(GetDlgItem(hDlg, IDC_CON_CON), WM_SETTEXT, 0, (LPARAM) buf1);
SendMessage(GetDlgItem(hDlg, IDC_CON_CON), WM_SETTEXT, 0, (LPARAM) buf2);
it can only display
hai
where i want
hello
hai
Pls help. If possible, do e-mail the solution to my mail box
yccheok@yahoo.com
since i don't have any internet access in this few day and it may take my sometimes to search back my message
thanks
regards
yccheok
|
|
|
|
|
Each SendMessage replaces the text in the control with the text in the LPARAM parameter. Try this instead:
char *buf = "hello\r\nhai\r\n";
SendMessage(GetDlgItem(hDlg, IDC_CON_CON), WM_SETTEXT, 0, (LPARAM)buf);
You'll get this reply mailed automatically from the CP server.
Cheers
Steen.
"To claim that computer games influence children is rediculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
I face some problem in implementing a multithreading dialog based program (C/SDK) which used to simulate dining philosopher problem.
In my program, I create 6 threads using _beginthread() respectively where
the 5 threads is use to keep looping in an infinity loop, update their state and keep sending InvalidateRect() to a display control. It roughly look like this :
void Run( void *pParam)
{
while(ps->bRunnable)
{
Update Philosopher State
InvalidateRect(hwndCtl, NULL, TRUE);
UpdateWindow(hwndCtl); // hwndCtl is handle to subclassing
// control which has his own message
// procedure
}
}
one thread is responsible to keep track one the timing. When the time reach, it will stop the other 5 threads. It roughly look like this :
void RunSimulation(void *pParam)
{
start philosopher thread
while(time(0)-tTimeStart < nSimulation[nIndexSimulation] &&
bSimRunnable)
{
}
bSimRunnable = FALSE;
}
I start both threads with :
_beginthread(Run, 0, (void *)ps)
_beginthread(RunSimulation, 0, (void *)ps)
However, I totally lose my control on the GUI control. My mouse click on
the dialog box would not responde until all the threads finished. I try to clear the message in the queqe before philosopher thread further sending any
message. I place the following code inside Run()
void Run( void *pParam)
{
// clear the message queqe before thread further send any message
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{ ///////////////////////////////////////////////
//BUT THE THREAD NEVER ENTER THIS BLOCK! WHY???
///////////////////////////////////////////////
// seperate dialog box message from null parent window
if( !IsDialogMessage(hDlgMain, &msg) &&
!IsDialogMessage(hDlgCon, &msg) &&
!IsDialogMessage(hDlgGraph, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg); // send to null parent
}
}
while(ps->bRunnable)
{
Update Philosopher State
InvalidateRect(hwndCtl, NULL, TRUE);
UpdateWindow(hwndCtl); // hwndCtl is handle to subclassing
// control which has his own message
// procedure
}
}
----------------------------------------------------------------------------
This won't work and the dialog box still hang up
while the threads is running.
Pls help. If possible, do e-mail the solution to my mail box
yccheok@yahoo.com
since i don't have any internet access in this few day and it may take my sometimes to search back my message
thanks
regards
yccheok
|
|
|
|
|
1) There's no sense in calling PeekMessage or other message-oriented functions in Run. This thread is a 'worker' one, doesn't have message queue. Remember that message queues are created and accessed per-thread. PeekMessage inside Run is guaranted to return FALSE.
2) The main problem with application being not responsive to mouse movements etc. can be related to the frequency of calls to Invalidate/UpdateWindow being made inside Run. If updating philosopher state doesn't take much time, you're sending lots of WM_PAINT messages to hwndCtl. UpdateWindow removes these messages and repaints the control, however, message queue is stressed by 5 threads. Note that calling InvalidateWindow in worker thread posts message in the message queue of main (UI) thread.
You should invalidate the control periodically, not in every pass of the loop. Use GetTickCount to compute time elapsed from last repaint and redraw every second (for example, you may choose different interval). This will reduce flicker and should make your app responsive to user actions.
If possible, do e-mail the solution to my mail box
CodeProject server sends email to you automatically, unless you explicitly de-select this option when posting.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hi just wanna ask how do you manipulate the "Z-order" in visual C++??? How do you put one picture box on top or at the back of another picture box...
Thanks......
|
|
|
|
|
SetWindowPos is generally how you set the Z-order of a window. Given that controls are also a CWnd, I'd try that first.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
hi..
m_s1 and m_s2 are CSTATIC but seems like it's not working...
void CTesting3_bmpView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CFormView::OnLButtonDown(nFlags, point);
if (flip == TRUE)
{
flip = FALSE;
m_s1.SetWindowPos (&wndTop, 1, 1, 100, 100, SWP_NOSIZE | SWP_NOMOVE);
//m_s1.BringWindowToTop ();
}
else
{
m_s2.SetWindowPos (&wndTop, 1, 1, 100, 100, SWP_NOSIZE | SWP_NOMOVE);
//m_s1.BringWindowToTop ();
flip = TRUE;
}
UpdateData(FALSE);
Invalidate();
}
|
|
|
|
|
are you trying to show between two button at the same position to do two different task ?
if so, i sugguest you not to use z-order but just change the object text of the button ( or CStatic ) by CWnd::SetWindowText(LPCTSTR lpszString) and if they are executable, set a flag ( i think you already have, which is "flip".. ) and in OnClick of that object, check the flag and do different task.. but as you said they are just static.. i guess you only wanna display different text SetWindowText can do what you need
|
|
|
|
|
I have an ATL COM DLL for a project I'm working on. It has a progress bar so some of our other COM objects can load and use it for showing progress...
At any rate, the Dialog is based on CAxDialogImpl. This dialog HAS a Cancel button so I don't want to override OnCancel. I tried overriding WM_KEYDOWN which works fine for any OTHER key pressed but for some reason doesn't capture the Escape key.
Anyone have any other ideas? Please help.
Matt Philmon
|
|
|
|
|
GetAsynchKeyState(VK_ESKAPE);
(in your OnCancel(...) to check the state)
|
|
|
|
|
THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU THANK YOU!
Matt Philmon
|
|
|
|
|
I have a CFormView which pops up a dialog box which has a property page. While in the property page, I want to get a value from the CFormView, but I can't, it always returns a wierd number like -814001 or somethign not even close to what I expect.
Can I please, please, email a small demo project to someone/anyone who could look at it and help me to get a value? Please please. My email address is brinasas@yahoo.com
This will probably take 1 line of code, but I am absolutely stumped and frustrated.
Sincerely,
Danielle (an overworked graduate student)
|
|
|
|
|
How are you accessing the CFormView class? Are you passing a pointer into the property page?
Michael
|
|
|
|
|
I am working on an ATL control that has a simple CStatic text label. While I've managed to change the font in both OnInitDialog and OnPaint I cannot change the color. Basically it is a Property Sheet with a CStatic control on it.
In the Constructor m_pArial is defined as:
m_pArial->CreateFont(40, 0, 0, 0, 700, 0, 0, 0, 0, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, FIXED_PITCH, "Arial");
And it is deleted in the destructor.
Here is my code (it sets the font just fine - not the color).
void CPropPage::OnPaint()
{
CPaintDC dc(this); // device context for painting
CPen *pOldPen;
CPen BluePen;
BluePen.CreatePen(PS_SOLID, 1, RGB(0, 0, 255));
CBrush Brush(RGB(0, 0, 255));
CBrush *pOldBrush;
pOldPen = dc.SelectObject(&BluePen);
pOldBrush = dc.SelectObject(&Brush);
m_Static_Title.SetFont(m_pArial);
m_Static_Title.SetWindowText("Test");
dc.SelectObject(pOldPen);
dc.SelectObject(pOldBrush);
}
Thank You
|
|
|
|
|
You need to do it in the WM_CTLCOLORSTATIC message handler
From MSDN on WM_CTLCOLORSTATIC:
"A static control, or an edit control that is read-only or disabled, sends the WM_CTLCOLORSTATIC message to its parent window when the control is about to be drawn. By responding to this message, the parent window can use the specified device context handle to set the text and background colors of the static control."
Cheers,
-Erik
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
My thoughts are my own and reflect on no other.
|
|
|
|
|
Does anybody know how to read and write individual bits of data to a file? I would appreciate any advice that you may have.
Thanks.
|
|
|
|
|
You have a lotof options,
You can use _read() function,
CArhive::Read() function Or CFile::Read() function.
Cheers!!!!
Carlos Antollini.
|
|
|
|
|
You can write ints, BOOLs, doubles, etc.. like that, but not individual bits. Thanks though.
|
|
|
|
|
The minimum unit that can be written is a BYTE. Even the data type BOOL takes up a byte of space. So I think you can use 1 byte for each bit. But, if you want to write bits itself, you have to use the bitwise operators to fit it in the appropriate position in a byte and then write it to the file. A similar process should be done when reading.
- Thomas
modified 29-Aug-18 21:01pm.
|
|
|
|
|
Thank you for your reply, that is what I figured I would have to do, although I really didn't want to.
|
|
|
|
|
Hello,
Does anyone know how to give a dialog box the ability to all ways be on top? eg.. even if some other app not related to yours is open (like your internet browser), I want my dialog app to stay on top..
Rob
|
|
|
|
|
This answer MUST be in the FAQ, but ::SetWindowPos (&wndTopMost, 0,0,0,0,SWP_NOMOVE | SWP_NOSIZE);
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
Thanks Christian.. In the future, I'll do a little more searching before I post.
Thanks again for the fast response.
Rob
|
|
|
|
|
Hi,
I have a MFC test app with 2 edit fields. I want to pass the edit fields handle to an MFC ActiveX control which will just return the contents of these fields.
The problem I am facing is that ActiveX control does not allow to take in HWND as a parameter.
Is there a way to pass HWND in my activeX control.
Thanks in advance
Bobby
|
|
|
|
|
I'm not exactly sure what you're trying to do, but you can add an IUnknown derived interface and create a method that lets you pass the handles. You can also cheat and cast them to a LONG if you're using a dispinterface.
But for most stuff this doesn't seem like a good idea. What exactly are you trying to accomplish?
--CoolDev
|
|
|
|
|