|
hi all,
following is a code snippet of my program having vc6 mfc sdi and formview as basic characteristics.
void CScada_thrdsView::dsp_cnt()
{
while (!exit_thrd)
{while(!nw_cnt) ;
sprintf(cstring,"%d",count);
m_val.InsertString((count-1),cstring);
UpdateData(FALSE);
` nw_cnt = 0;
}
}
i am getting an error
debug assertion failed;file wincore.cpp;line no 883
from debugging i gather that this error is being caused due to the updatedata statement.
the function dsp_cnt is in form view but is being called from the worker thread.
i request for help in sorting out this error.
thnx
ashwani
|
|
|
|
|
You cannot manipulate UI elements from a non UI thread. I suggest you read this excellent article[^]. It's a bit long but it is really worth reading it, because you will learn a lot of very useful things.
|
|
|
|
|
|
I would guess it is 1 of 2 problems.
1. Most likely that they belong to a different thread (the main thread). To my knowledge, UpdateData must be called from the thread that owns the controls.
2. The controls haven't been created yet, if it is in initialisation code.
The best way I would suggest for fixing problem 1 would be to register a custom message WM_USER + 1 and have the handler call UpdateData like this:
header file:
#define CM_UPDATEDATA WM_USER + 1
class CScada_thrdsView : public BaseClass {
protected:
afx_msg LRESULT OnUpdateData(WPARAM wParam, LPARAM lParam);
}
source file:
BEGIN_MESSAGE_MAP(CScada_thrdsView, BaseClass)
ON_MESSAGE(CM_UPDATEDATA , OnUpdateData)
END_MESSAGE_MAP()
LRESULT CScada_thrdsView::OnUpdateData(WPARAM wParam, LPARAM lParam) {
UpdateData((BOOL)wParam);
return 0;
}
in the thread:
void CScada_thrdsView::dsp_cnt() {
while (!exit_thrd) {
while(!nw_cnt);
sprintf(cstring,"%d",count);
m_val.InsertString((count-1),cstring);
PostMessage(CM_UPDATEDATA, FALSE);
nw_cnt = 0;
}
}
|
|
|
|
|
thnx andrew.xtremely detailed help.
thnx
|
|
|
|
|
hi andrew,
i did as directed,and it worked. thnx.one small point though,in this code UpdateData((BOOL)wParam); probably should'nt it be lParam instead of wParam.
thnx
ashwani
|
|
|
|
|
No, wParam is correct.
The function I used to send the message was CWnd::PostMessage(UINT Msg, WPARAM wParam = 0, LPARAM lParam = 0);
Using the Msg as CM_UPDATEDATA and wParam as FALSE (or TRUE if you want to update the variables instead), and lParam as its default unused value of 0
Hence the wParam variable in the CScada_thrdsView::OnUpdateData function is the 1 that holds the bSaveAndValidate parameter to UpdateData.
You can change it to use the lParam by using PostMessage(CM_UPDATEDATA, 0, FALSE); to send the message if you prefer
|
|
|
|
|
|
Is there a way to measure richedit height? I should put CRichedit into fixed width window, but I should avoid vertical scroll. So, I should calculate the CRichEdit(with text) height for a specified width. Is it possible?
Pavel Sokolov
|
|
|
|
|
You could use GetWindowPlacement[^] to determine the height; the rcNormalPosition member of the WINDOWPLACEMENT structure has the info you're after.
Then SetWindowPlacement[^] to adjust it if needed.
modified 13-Sep-18 21:01pm.
|
|
|
|
|
I need it before creation of actual control.
Pavel Sokolov
|
|
|
|
|
Okay so instead of measuring it, it should be calculated.
What is known to base the calculation on? The number of lines that are going to be in the control?
If so, you should multiply the number of lines with the height of a line, depending on the font, and add an offset of a few pixels for the border.
modified 13-Sep-18 21:01pm.
|
|
|
|
|
Nothing. I have only width of the control. The lines can have different styles and fonts and even with pictures.
Pavel Sokolov
|
|
|
|
|
So what exactly decides then how high you want it to be?
modified 13-Sep-18 21:01pm.
|
|
|
|
|
The text in the control. I want to fit richedit into item of another control without vertical scrollbar.
The main idea is to build messages archive (history for IM). There can be a lot of messages and they are in rtf. Currently I'm trying to insert RichEdit into ListBoxItem and I need width and height for MeasureItem().
Pavel Sokolov
|
|
|
|
|
|
Pavel Sokolov wrote: Is there a way to measure richedit height?
You mean something like GetWindowRect() ?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Actually I want to display richedit inside the other control item. So, I know width, but I should set the height too. I deen something like: int m_Height = m_RichEditControl.CalculateControlHeightForThisWidth( m_intWidth )
Pavel Sokolov
|
|
|
|
|
На самом деле, варианта у тебя два:
- действительно создать скрытый рич-едит, вызывать у него RequestResize и ловить EN_REQUESTRESIZE. Вариант вполне нормальный.
- если делать совсем все правильно, то в твоем случае не надо встраивать рич-едиты в лист-контрол. Тебе надо копать в сторону windowless-ричедита, внимательно изучив ITextHost/ITextServices.
ЗЫ: Как жизнь вообще? Чем занимаешься? Твой логотип SWR оказался очень живуч )
Regards,
Nikolay
|
|
|
|
|
Мама дорогая, какие люди! Да ничего, всё тем же и занимаюсь. Ты то как? Я вас пытался найти как-то по соцсетям - да так и не нашёл.
А что мне даст безоконный ричедит? На самом деле у всех подобные контроллы есть (да почти во все месенджерах история сообщений), а тут такие сложности... Может вообще одним ограничиться и догружать нужное по кликам на скроллбарах, так наверняка будет мелькать противно.
Pavel Sokolov
|
|
|
|
|
Ну, смотря какой функционал тебе от этого списка нужен. Если просто "мертвый" список, то я бы ограничился первым вариантом. Т.е. создал бы невидимый ричедит, через него бы вычислял высоту каждого айтема в списке, через него же рендерил в битмап в памяти сам текст айтема. Потом при отрисовке айтема просто выводил бы уже готовый битмап.
Если же требуется какая-то интерактивность от списка, например, если ты хочешь, чтобы можно было бы кликнуть на линки, которые могуть быть в тексте, менять курсор, когда мышка поверх таких линков и т.п., то тут уже без безоконного ричедита обойтись будет трудно.
ЗЫ: я есть тут: http://vkontakte.ru/id1216693[^] или тут http://ru-ru.facebook.com/profile.php?id=1610591135[^]
Regards,
Nikolay
|
|
|
|
|
hello guys... I am actually recording a wave file. I have hardcoded the file path but the file name is provided by the user. Now I want to wave file to be stored at this combination of these two which in im successful. Here is what im trying
LPCSTR filePath = "d:\\Audios\\";
LPCSTR fileNamePath = strcat(filePath, strcat(fileName, ".wav"));
This is not successful, how can I do that?? thnx
|
|
|
|
|
overloaded Name wrote: This is not successful
Please be specific when asking a question. What doesn't work exactly ?
In your case, I would guess it is because you are using constant strings (LPCSTR, the C is for constant). Try using LPSTR instead, it should work. Don't forget that strcat will modify the destination string (check the documentation).
BTW, it is far more easier to use std::string instead of using raw char pointers.
|
|
|
|
|
strcat needs a writeable destination buffer.
where is all this text going to be stored? you need a buffer large enough to hold it, I see it nowhere.
Here is one way of doing it (C code):
char* result=malloc(1000);
strcpy(result, filePath);
strcat(result, fileName);
strcat(result, ".wav");
This is far from optimal, as the size is overestimated, and the string operations are unsafe, they could overrun the destination buffer. It would also fail if filePath doesn't end on a backslash, or fileName already has an extension.
But it would work.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
You are using strcat() incorrectly so this code wll not work. However, you would also be better using the more secure versions[^] of these functions.
I must get a clever new signature for 2011.
|
|
|
|