|
Thank you for your help
I'm always feel insufficiency about <locale> library.
Could you share your knowledge about the 'locale'.
It's always big problem of me.
I think the article about 'locale' is very valuable thing.
Thanks!
|
|
|
|
|
I have a C/C++ program (yes, a mix of both) that acquires data from a hardware device and displays it in real time. I want to add some processing on the data as soon as I read it, but I want to make sure it doesn't slow down the data acquisition too much. Is there a utility that will measure how long a function takes or how often it is called?
I already use the Red Gate ANTS profiler for my .NET apps, but it doesn't work with native code. Also, any profilers I've tried tend to slow down the application quite a bit. Is there a way I can measure the execution time without affecting it too?
Or would it be best to use the clock() function from time.h to measure this?
Thanks,
Dybs
|
|
|
|
|
Hi,
I would not use external tools for this. They tend to be rather complex for the task at hand. Instead add a little piece of code.
Have a look at multimedia timers[^]; make sure you first determine their accuracy, it can be worse than 1 msec (up to 16 msec is common).
If that is not good enough, google for code that relies on the RDTSC assembly instruction.
|
|
|
|
|
To add to Luc's answer - I've always used the high-resolution performance counter[^] to time my code. I've got a class that encapsulates the whole process in an RAII fashion - something like:
class CTimer
{
public:
CTimer(std::string const& what) : what_(what) { QueryPerformanceFrequency((LARGE_INTEGER*)&freq_); begin_ = Now(); }
~CTimer() { end_ = Now(); ShowTime(end_ - begin_); }
private:
__int64 Now()
{
__int64 now;
QueryPerformanceCounter((LARGE_INTEGER*)&now);
return the time you calculated;
}
void ShowTime(__int64 deltaTime) { std::cout << "Doing " << what_ << << std::endl; }
__int64 begin_, end_;
__int64 freq_;
const std::string what_;
};
{
CTimer t("some message");
}
I've left out the involved bits (calculating time from QueryPerformanceCounter result and displaying the time nicely) as I don't have access to the code I wrote right at the moment.
Certainly don't use clock() - it's a milli-second timer.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks for the answers. The reason I mentioned clock() is precisely because it's a millisecond timer. I'm not certain exactly how fast the data acquisition is now, but I don't think it's any faster than once a millisecond. When I add my processing code, I'd like to get as accurate as I can on how much it affects the timing, if at all.
I was looking at the link from Luc and saw the reference to QueryPerformanceCounter . I've seen other references to it on CP, but haven't needed to use it yet. Looks like it should do what I need.
Thanks again for the suggestions,
Dybs
|
|
|
|
|
|
I am working with some C++ code (not my code, of course) that has a bunch of huge functions, which I would like to refactor. Does anyone know of a utility that will scan C++ source files and report the number of lines in each function?
Jim Scott
|
|
|
|
|
I think this one[^] will do that
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Tried CCCC on a MFC program and it choked on all the special defines (macros) one is using when dealing with the win32 API.
|
|
|
|
|
You could well be right - I used it on embedded system code, and we didn't have much 'macro magic'.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks. This is a nice tool, and it gives a lot more information than I expected.
|
|
|
|
|
Here is list of SLOC metric tools:
LOC Metrics - Alternative Tools[^]
Source Monitor[^] seems to provide what you need, as it can provide a quick overview of all methods and how many statements they have. Just create a baseline and right-click the baseline and choose "Display Method Metrics...."
Also I would recommend to use Doxygen to see call hierarchies and class diagrams.
|
|
|
|
|
Hi,
im using Wshell.Regwrite to write registry(vb script) through html page...
but it works fine only when the option "Initialize and script ActiveX
controls not marked as safe" under Tools\internet
options/Security/Customlevel/ActiveX controls and plugIns ,is set to prompt or enable .....and if we set to any other option ie(disable) it fails ie it shows error like .. "ActiveX component cannot create object "Wscript.shell"...
So May i know whether is it possible to create my own ActiveX control(signed) with certificate(using c++) and embed in my vb script so that it doesn"t depend on internet options..
if yes pls let me know how to do the same...
pls correct me if im wrong...
|
|
|
|
|
You can make an ActiveX Safe for scripting via the interfaces IObjectSafetyImpl and IObjectSafetySiteLockImpl. Search for the complicated details in the MSDN.
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
I wrote an override for the OnNcPaint. It works fine, but I have a problem.
I want Windows to do the painting in a part of the NC area and let me do the painting for the remaning part.
More precisely, I want windows to draw the menu and let me do the remaining of the painting.
My ideea is to paint what I need then send a WM_NCPAINT message and a handle in wParam to the region where I want Windows to do the painting. The problem is that SendMessage drowns in some ATL code (I'm unfamiliar with ATL).
The error is about accessing an invalid address. I suppose Windows cannot access the definition of the region referred by my region handle. I think I'm supposed to do some sort of marshalling of the HRGN object, but as I said, I'm unfamiliar with ATL. Can somebody help ?
|
|
|
|
|
CString(0xcccccccc) wrote: More precisely, I want windows to draw the menu and let me do the remaining of the painting.
The way to do that is (in your WM_NCPAINT handler) to call DefWndProc, then do your painting. Don't send any extra messages or anything.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Tried this one, unsuccessfully:
::DefWindowProc(m_hWnd, WM_NCPAINT, (WPARAM) pRgn->m_hObject, pMsg->lParam);
|
|
|
|
|
If you're handling the message in a CWindowImpl derivative, you should be able to call the DefWindowProc method with no arguments to do this - here's a fragment of an ATL-based window class showing the message map and handler method:
BEGIN_MSG_MAP(CWtlsdiView)
MESSAGE_HANDLER(WM_NCPAINT, OnNcPaint)
END_MSG_MAP()
LRESULT OnNcPaint(UINT , WPARAM , LPARAM , BOOL& )
{
DefWindowProc();
return 0;
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Allowing Windows to paint the entire NC area, then painting over it will cause flickering. I need to limit the area where Windows paints by passing a region handle with the message.
|
|
|
|
|
I've had some success (I think) with this code for handling OnNcPaint:
CRect GetCaptionRect(CWindow& wnd)
{
DWORD dwStyle = wnd.GetStyle();
CSize szFrame = (dwStyle & WS_THICKFRAME) ?
CSize(GetSystemMetrics(SM_CXSIZEFRAME),
GetSystemMetrics(SM_CYSIZEFRAME)) :
CSize(GetSystemMetrics(SM_CXFIXEDFRAME),
GetSystemMetrics(SM_CYFIXEDFRAME));
int cxIcon = GetSystemMetrics(SM_CXSIZE);
CRect r;
wnd.GetWindowRect(&r);
r -= CPoint(r.left, r.top);
r.left += szFrame.cx;
r.right -= szFrame.cx;
r.top += szFrame.cy;
r.bottom = r.top + GetSystemMetrics(SM_CYCAPTION)
- GetSystemMetrics(SM_CYBORDER);
return r;
}
class MyDialog : public CDialogImpl<MyDialog>
{
public:
BEGIN_MSG_MAP(MyDialog)
MESSAGE_HANDLER(WM_NCPAINT, OnNcPaint)
END_MSG_MAP()
LRESULT OnNcPaint(UINT nMsg, WPARAM hRgn, LPARAM lParam, BOOL& )
{
CRect r = GetCaptionRect(*this);
r.right = r.left + r.Width()/2;
HRGN onlyRedrawIn = ::CreateRectRgn(r.left, r.top, r.right, r.bottom);
::DefWindowProc(m_hWnd, nMsg, (WPARAM)onlyRedrawIn, lParam);
return 0;
}
};
The trouble is (I think) that your handler sometimes gets routed around - have you read this article[^] by Paul DiLascia about custom caption bars? It talks about MFC, but is relevant to ATL and Windows in general.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
It's not the first time I see that article of Paul DiLascia. His ideeas are nice, just one problem they don't work in my implementation. Anyway, there's something wrong with the article, the author wonders about the undocumented wParam = 1 (in WM_NCPAINT), while the MSDN clearly states it stands for "entire NC area needs repainting".
As about your code, first of all thank you for your effort.
Basically you're doing what I'm doing, just my code doesn't work.
Did you test it with VS 2008 ?
I tried to browse the MFC sources, it's a brand new world, there's no more WindowProc with message loop. Lots of ATL code.
My code follows:
void CMainFrame::OnNcPaint()
{
const MSG* pMsg = GetCurrentMessage();
CRgn rgnWnd, rgnCli, rgnMenu;
int iMenuHeight = GetSystemMetrics(SM_CYMENU);
CRect rcWnd, rcCli;
GetWindowRect(&rcWnd);
CPoint ptOffset = - rcWnd.TopLeft();
rcWnd.OffsetRect(ptOffset);
GetClientRect(&rcCli);
ClientToScreen(rcCli);
rcCli.OffsetRect(ptOffset);
rcCli.top -= iMenuHeight;
rgnWnd.CreateRectRgn(rcWnd.left, rcWnd.top ,rcWnd.right ,rcWnd.bottom);
rgnCli.CreateRectRgn(rcCli.left, rcCli.top ,rcCli.right ,rcCli.bottom);
rgnWnd.CombineRgn(&rgnWnd, &rgnCli, RGN_DIFF);
rgnMenu.CreateRectRgn(rcCli.left, rcCli.top, rcCli.right, rcCli.top + iMenuHeight);
if(pMsg->wParam != 1)
{
CRgn r;
r.CreateRectRgn(0,0,0,0);
r.CopyRgn(CRgn::FromHandle((HRGN) pMsg->wParam));
r.OffsetRgn(ptOffset);
rgnWnd.CombineRgn(&rgnWnd, &r, RGN_AND);
rgnMenu.CombineRgn(&rgnMenu, &r, RGN_AND);
}
CWindowDC dc(this);
CBrush brush;
brush.CreateSolidBrush(RGB( 255, 0, 0 ));
dc.FillRgn(&rgnWnd, &brush);
CRect rcBox;
rgnMenu.GetRgnBox(&rcBox);
if(!rcBox.IsRectEmpty())
::DefWindowProc(m_hWnd, WM_NCPAINT, (WPARAM) rgnMenu.m_hObject, 0);
}
|
|
|
|
|
CString(0xcccccccc) wrote: As about your code, first of all thank you for your effort.
Basically you're doing what I'm doing, just my code doesn't work.
Did you test it with VS 2008 ?
It's the only VS I use these days...
CString(0xcccccccc) wrote: Anyway, there's something wrong with the article, the author wonders about the undocumented wParam = 1 (in WM_NCPAINT), while the MSDN clearly states it stands for "entire NC area needs repainting"
I suspect that bit of MSDN's been fixed since then - the article is 12 years old
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I solved the problem. Thank you for your help. Even though there are significant differences because I used it in an MDI application, knowing that somebody else solved the problem was really helpful.
That persuaded me to double check carefully everything. The problem was that I was calling the DefWindowProc with a region in window coordinates instead of screen coordinates. Now it works.
|
|
|
|
|
Hi, I have a custom control that I've made and I want a tooltip hover near the the mouse as move over it, and stay near the mouse, i.e. illustrating positions of the current position within the custom control.
I used the code from MSDN, but I must not be getting it quite right as its not doing anything right now, so I can't start writing code so that it follows my cursor.
So far I've added a OnMouseHover event, so when the cursor enters the area of the custom control I think I should create a tooltip. Here is what I have so far.
HWND hwndTip = CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,
WS_POPUP |TTS_ALWAYSTIP | TTS_BALLOON,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL,
NULL, NULL);
TOOLINFO toolInfo = { 0 };
toolInfo.cbSize = sizeof(toolInfo);
toolInfo.hwnd = m_hWnd;
toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
toolInfo.uId = IDC_LINECHART1;
toolInfo.lpszText = _T("FAIL");
::SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);
I'm not really sure what hDlg and g_hInst is supposed to be, and how to get it,
thanks
soong
|
|
|
|
|
soongez wrote: hDlg and g_hInst
Given that those aren't used in the code you posted, do they matter?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|