|
Hi, I wrote snippet code to test.
first, I put a Static text in the dialog box, from the resource file:
IDD_ECHOBUTTONEVENT_DIALOG DIALOGEX 0, 0, 320, 200
...
BEGIN
...
LTEXT "Static",IDC_STATIC_TXT1,89,59,98,26
...
END
In Ontimer():
CRect outRect;
CStatic* pTxt1Static;
pTxt1Static = (CStatic*)GetDlgItem(IDC_STATIC_TXT1);
pTxt1Static->GetWindowRect(&outRect);
ScreenToClient(&outRect);
InvalidateRect(&outRect);
UpdateData(FALSE);
In OnPaint():
if (IsIconic()) {
...
}
else
{
CRect outRect;
CStatic* pTxt1Static;
pTxt1Static = (CStatic*)GetDlgItem(IDC_STATIC_TXT1);
pTxt1Static->GetWindowRect(&outRect);
ScreenToClient(&outRect);
CPaintDC dc(pTxt1Static);
dc.SetTextColor(RGB(255,0,0));
dc.SetBkMode(TRANSPARENT);
dc.DrawText(_T("My Test"),&outRect,DT_CENTER|DT_VCENTER);
CDialogEx::OnPaint();
}
But, the string "My Test" 's position is not at same position of Static text(IDC_STATIC_TXT1).
offset I guess is about 50 to 100 pixel.
And if I change CPaintDC dc(pTxt1Static) to CPaintDC dc(this), I got nothing, even I stretch the dialog
box to double, triple size.
If I don't use ScreenToClient(&outRect) in OnTimer(), and OnPaint(), I can see "My Test" string, but, need to stretch the dialog;
I set break point, pTxt1Static->GetWindowRect(&outRect); give :
tagRECT = {top=309 bottom=351 left=577 right=724}
run to ScreenToClient(&outRect); give:
tagRECT = {top=96 bottom=138 left=134 right=281}
Could you please help me to see what is the reason?
|
|
|
|
|
econy wrote: But, the string "My Test" 's position is not at same position of Static text(IDC_STATIC_TXT1).
offset I guess is about 50 to 100 pixel.
could that be due to the DT_CENTER|DT_VCENTER flags?
econy wrote:
And if I change CPaintDC dc(pTxt1Static) to CPaintDC dc(this),
it should be CPaintDC dc(this). you're painting the dialog, after all, not the static control.
also, try making your static control a 'frame' type, not a static text. something like:
CONTROL "",IDC_DRAWING_FRAME,"Static",SS_ETCHEDFRAME,12,199,169,66
that gives you a rectangle with no text in it.
|
|
|
|
|
also, it is not essential that you use a static control at all. i use them because having an actual control i can move around in the resource dialog editor makes it easy to do the layout of all the other controls.
but, if you just want to draw at an arbitrary rectangle and skip the GetWindowRect/ScreenToClient/etc. stuff , you can certainly do that, too.
|
|
|
|
|
|
Hi, I want to change a control's color, for example, static text.
logic like:
if test == 0 then
static text color = Red
else
static text color = Green
endif
first I try to do it in OnCtlColor() function, in timer function,
I declared a global variable.
<pre lang="text">
BOOL test = 0;
OnTimer() {
test ^= 1;
}
OnCtlColor() {
if (test == 0 ) {
pDC->SetTextColor(RGB(0,100,0));
}
else {
pDC->SetTextColor(RGB(255,0,0));
}
}
But, the color always be green, not swap.
I knew OnCtlColor need to be trigger with invalidate().
but I don't know how to invalidate a control, not affect it's parent window.
modified 17-Mar-14 7:59am.
|
|
|
|
|
You could try to call CStatic 's Invalidate and UpdateWindow methods.
Veni, vidi, vici.
|
|
|
|
|
|
You are welcome.
Veni, vidi, vici.
|
|
|
|
|
I would like to have a common header file in a simple DLL I am building.
I would like to have common headers, classes forward declarations and their headers in it.
How do I make sure my common header is compiled first?
It seems that the complier works on the classes in a sequence they were added to the DLL.
Any pointers will be as always appreciated.
Cheers
Vaclav
After several attempts to build DirectShow filter using sample code I found here and in SDK I am totally lost how to build simple DLL with more than one class. It appears that having identical include header files in each cpp file compiles / links OK. I even tryied #pragma once and it did not stop this behavior. This leads me to believe that having common file in simple DLL is not possible.
I guess I need some pointers on how this works and why.
The answer:
The sequence of compilation is given in the project DSP file ( VC6.0 )
-- modified 18-Mar-14 11:39am.
|
|
|
|
|
I'm not sure what you are asking here. Header files are used to compile source into object code, they have nothing to do with the final product being a DLL or anything else. In terms of compilation sequence, C/C++ tends to work on a single pass forward direction compilation. That is to say any reference that it comes upon in the source code must have a definition provided earlier in the source. This would be in the current .CPP file or in one of the headers that have been previously included.
|
|
|
|
|
In standard MFC wizard build application there is an option to have precompiled header - StdAfx.h
I put all my forward class declarations and all of my headers ( in proper order ) there.
I would like to do same in simple ( empty ) DLL and build a common header. I suppose I could put this common header in #ifndef / #define / #endif in each header file to avoid multiple definitions.
That way the sequence of compilation would not matter.
|
|
|
|
|
Off-course you should always use header-guards in .h-files:
<br />
<small>#ifndef _FOO_H<br />
#define FOO_H<br />
...<br />
#endif<br />
</small><br />
But what has this to do with making DLLs?
Maybe you have a problem with export & import of the classes+data in those headers? You didn't say, be specific.
-- Gisle V.
|
|
|
|
|
Vaclav_Sal wrote: I would like to do same in simple ( empty ) DLL As I said before, header files have nothing to do with DLLs. The reason for using StdAfx.h in a project is merely to speed up the compilation phase since all the preprocessing of the header files is done once and then saved in internal format that the compiler can quickly read. You can use exactly the same thing in a project that is to create a DLL.
And the sequence of headers does matter, for the reasons I stated earlier, in that all references must have some form of definition before the compiler sees them. It does not matter what type of program (executable, COM component, DLL or static library) you are building, the rules are exactly the same for the language compilation phase.
|
|
|
|
|
OK, this is a no code , <b>empty</b>, no MFC, no export / import etc. DLL.
It is, or hopefully will be, a DirectShow filter. There are tons of DirectShow resources on how to build a graph and how to build a filter. I have not found a single source which actually explains HOW such DLL works / interacts with application , even GraphEdit.
When I get it to compile (!) I will analyze it.
My problem now is that #ifndef / #define / #endif DOES NOT work building this simple DLL.
I am using same setup in all my MFC applications without a hitch.
It theory it should work, but it does not. I suppose I could put all the code in one cpp / header and complile it that way.
The block of common includes gets compiled multiple times. In each header file.I use #pragma message to track the compilation, and than the linker goes crazy.
Either my VC6.0 finallly broke or I am missing something in setup / configuration of this DLL.
At present I cannot risk, again, to use newer VS, last time I did that it messed up big time rebuilding my old MFC code without asking.
|
|
|
|
|
Vaclav_Sal wrote: My problem now is that #ifndef / #define / #endif DOES NOT work building this simple DLL. Because (I'm sorry to belabour this point) those directives have nothing to do with the program being a DLL. They are used by the compiler to include or exclude some sections of source code, in a compilation module.
Vaclav_Sal wrote: I use #pragma message to track the compilation, and than the linker goes crazy. That hardly tells us anything useful. You really need to show us some of the source code (and please use <pre> tags around it) and indicate what errors occur and where.
|
|
|
|
|
I met a weird DrawText() blinking problem. in a loop, interval is 2 seconds, I want to show some messages on a dialog screen.
i.e. 0-2 sec, message1; 2-4 sec,message2; 4-6, message3 ...
but, now the message shows like:
flash message1; 0 sec
black screen;
flash message2; 2 sec
black screen;
flash message3; 6 sec.
black screen;
what I want is :
message1; 0-2 sec
message2; 2-4 sec
message3; 4-6 sec
void CTestDlg::DrawMsg(LPCTSTR iMsgStr)
{
CDC* pDC;
CRect rect;
CString MsgStr;
HDC hDC;
LOGFONT lf;
HFONT FontNew, FontOld;
pDC = GetDC();
hDC = pDC->GetSafeHdc();
memset(&lf, 0, sizeof(LOGFONT));
lf.lfHeight = -14 * GetDeviceCaps(hDC,LOGPIXELSY)/72;
lf.lfWeight = 0;
FontNew = CreateFontIndirect(&lf);
FontOld = (HFONT)SelectObject(hDC,FontNew);
rect.SetRect(CPoint(274,442), CPoint(514,514));
SetBkMode(hDC,TRANSPARENT);
DrawText(hDC,dtcMsgStr,-1,rect,DT_WORDBREAK|DT_LEFT);
InvalidateRect(rect,FALSE);
SelectObject(hDC,FontOld);
DeleteObject(FontNew);
ReleaseDC(pDC);
}
|
|
|
|
|
It goes blank because you call InvalidateRect after you call DrawText, switch them around.
Within you lies the power for good - Use it!
|
|
|
|
|
InvalidateRect(rect,FALSE);
DrawText(hDC,dtcMsgStr,-1,rect,DT_WORDBREAK|DT_LEFT);
I tried the above way, same phenomenon
|
|
|
|
|
You should not be calling InvalidateRect in the same place as you are drawing to the screen. That call is to tell windows that your window needs to be updated, but you are already inside the code where the update is happening. You could simplify this by using one of the standard window controls[^].
|
|
|
|
|
In fact, I try to use a CEdit first, like:
LTEXT "N/A" IDC_TEST_MSG 88,189,128,24 CEdit* pEdit1 = GetDlgItem(IDC_TEST_MSG);
CDC* pEdit1DC = pEdit1.GetDC();
pEdit1DC->DrawText()
But, I got same phenomenon.
|
|
|
|
|
If you are using MFC classes then you should override the OnPaint [^] member function of the class.
|
|
|
|
|
then if I want to implement the display effect, what should I do?
I want to show:
message1 0-2 sec,
message2 2-4 sec,
message3 4-6 sec,
...
I hope it like (calendar time) static text, or text box control in many demo program.
that is:
2014/3/15 12:51; 2014/3/15 12:52; 2014/3/15 12:53;
update time smoothly.
|
|
|
|
|
Use something like a progress dialog.
|
|
|
|
|
No such thing, it is an embedded Win CE platform
|
|
|
|
|
Pity you did not mention that at the beginning.
|
|
|
|
|