|
I'm sorry but I can't get it to work :/
When I place LARGE_INTEGER Timer::m_lTime etc inside my .cpp file it begins to talk about redefinition errors.
If I remove LARGE_INTEGER m_lTime etc from my .h file it says 'm_lTime' : is not a member of 'Timer'.
could you write just a simple class with a static member explaining it to me?
|
|
|
|
|
Did you define m_lTicksPerSecond, m_lTime,m_lFirstTime and in your cpp file.
LARGE_INTEGER Timer::m_lTicksPerSecond=0;
LARGE_INTEGER Timer::m_lTime=0;
LARGE_INTEGER Timer::m_lFirstTime=0;
Also have you checked out this:
http://www.naughter.com/cputicker.html[^]
Removing the mfc part only takes a few seconds...
John
|
|
|
|
|
oki, I checked out the cputicker class but still can't figure out what I'm doing wrong, perhaps I'm geting blind to my code.
This is what my 2 files looks like now:
Timer.h
<br />
#ifndef TIMER_H<br />
#define TIMER_H<br />
class Timer<br />
{<br />
protected:<br />
static LARGE_INTEGER m_lTicksPerSecond;<br />
static LARGE_INTEGER m_lTime;<br />
static LARGE_INTEGER m_lFirstTime;<br />
Timer();<br />
public:<br />
static bool Initialize();<br />
static double MsSinceStart();<br />
};<br />
#endif<br />
and this is what Timer.cpp looks like:
<br />
#include "Timer.h"<br />
<br />
LARGE_INTEGER Timer::m_lTicksPerSecond = NULL;<br />
LARGE_INTEGER Timer::m_lFirstTime = NULL;<br />
LARGE_INTEGER Timer::m_lTime = NULL;<br />
<br />
bool Timer::Initialize()<br />
{<br />
if(QueryPerformanceFrequency(&m_lTicksPerSecond) && QueryPerformanceCounter(&m_lFirstTime))<br />
return true;<br />
return false;<br />
}<br />
double Timer::MsSinceStart()<br />
{<br />
QueryPerformanceCounter(&m_lTime);<br />
return ((double)( m_lTime.QuadPart - m_lFirstTime.QuadPart ) / (double) m_lTicksPerSecond.QuadPart ) * 1000.0;<br />
}<br />
and this is the error which seems relevant: error C2039: 'm_lFirstTime' : is not a member of 'Timer' (which it as you see is)
hehe, plz bare with me
|
|
|
|
|
I am not sure what the problem is. Check to make sure that your cpp file is indeed included in your project and it is compiling...
As for the link, since I saw you were trying to do some work with high resolution timers I thought the code there may save you some work...
John
|
|
|
|
|
How is LARGE_INTEGER defined? Aren't there any macros that interfere with your variable names?
The simple example of declaring static members is:
pruba.h:
class A
{
static int b;
};
pruba.cpp:
#include "pruba.h"
int A::b = 1;
Robert-Antonio
"Science is a differerntial equation.
Religion is a boundary condition."
|
|
|
|
|
Hi!
I've been programming C++ for almost 4 years now, but this one is getting me mad
if(!(bMouse4Old == bMouse4 == false))
SendInput(1, &inputMouse4, sizeof(inputMouse4));
both bMouse4Old and bMouse4 are false , but the "SendInput()" is being called nonetheless.
Why?
The statement means: "if bMouse4Old and bMouse4 are the same, namely false, do not call SendInput" (hence the "!")
thanks in advance
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Goodness knows how this will be evaluated, but I doubt it will be the way you hope.
if (bMouse4Old == false && bMouse4 == false)
is the way to go.
or perhaps
if (! (bMouse4Old && bMouse4))
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Christian Graus wrote:
if (bMouse4Old == false && bMouse4 == false)
This is the one I would use. The original code even if it worked is much harder to read and you are not saving anything by this kind of simplification as the compiler would surely optimize this statement.
John
|
|
|
|
|
Yeah, I have a tendency to go crazy on making statements smaller, at the expense of readability. I kind of miss being able to do that in c#, there's no implicit conversion to bool a lot of the time.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
D'oh, thanks a lot.
I was absolutely sure C++ allowes that kind of evaluation I used in my original if-statement, but the results were somewhat unpredictable
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I think it this is happening.
(!(bMouse4Old == (bMouse4 == false)))
with == being processed like = as in
x=y=0;
I hope there isn't a lot of this stuff.
-Andy Brummer
|
|
|
|
|
In the Table "C++ Operator Precedence and Associativity",
= "Assignment" "Right to left"
== "Equality" "Left to right"
(A == B == C)
stands for
((A == B) == C)
X = Y = Z;
stands for
X = (Y = Z);
<b>Maxwell Chen</b>
|
|
|
|
|
Totally offtopic, but I have two more questions:
2) My program uses DirectInput to capture the state of the 4th and 5th mousebutton (DIMOUSESTATE2).
Depending on the state I call SendInput to map the mousebuttons to a key, thus being able to play games with 5 buttons by emulating a keypress. is there an easier way to map a mousebutton to a key? I find the SendInput way quite uncomfortable, though it works.
2) I need to save a single integer into a config file, no more, no less. Hence my program consists only of a single exe-file, I don't want to create a config file just to save the integer. Is there another way to save the integer? (I don't want to save into the registry, because when the user deletes my exe the value would stay in the registry having no function anymore)
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Regarding item 2:
a file or the registry is your only option as far as I can see. I doubt a single digit in the registry is going to make much difference, and that's what uninstall programs are for.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Well, you already got your answer but I will attempt to explain what's happening with your code. At first bMouse4 == false returns "true" since bMouse4 is false. Afterwards, you have bMouse4Old == true. Now the statement becomes:
if( !false )
SendInput(...)
Therefore if bMouse4Old and bMouse4 are both false then SendInput() will be called.
// Afterall, I realized that even my comment lines have bugs
If the sun were to blow up, it would take us 7-8 minutes to realize it.
|
|
|
|
|
1) Ragarding to your if block, it does work well with VC++ 6.0 on my machine. What I tested is as the below:
bool bMouse4Old = false;
bool bMouse4 = false;
if(!(bMouse4Old == bMouse4 == false))
std::cout << "SendInput(...)\n";
2) According to the Table "C++ Operator Precedence and Associativity" in MSDN,
== "Equality" "Left to right"
Thus, your code can be translated as:
a) if(!( (bMouse4Old /*false*/ == bMouse4 /*false*/) == false)) // then
b) if(!(true == false)) // then
c) if(!false) // then
d) if(true)
<b>Maxwell Chen</b>
|
|
|
|
|
I have a CListCtrl in a CFormView that represents objects. In the form view I have controls that represent data of the selected object.
When a new object is selected in the list, I need to:
1. validate the data
2. if the data is not valid, keep the original list item selected, and do not select the new item.
3. if the data is valid, then show the data of the new object.
I have added OnItemchangingX and OnItemchangedX for the list control to my form view class.
void CAddonView::OnItemchangingX(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
BOOL bValidateSuccessful = validate();
if (!bValidateSuccessful) {
--------------------------------------------------
...what do I do here to keep the old item selected
...and keep the new one from getting selected?
--------------------------------------------------
}
}
void CAddonView::OnItemchangedX(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
int iSelItem = m_listAP.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
if (iSelItem != -1 && pNMListView->uNewState & LVIS_SELECTED)
{
...load data of newly selected item...
}
} What do I need to do to keep the old selection if the validation fails?
Thanks.
--
David Hisel
Internet Business Software
|
|
|
|
|
Most likely not the best solution, but I had a similar
problem, and I just used a static variable to keep track
of the previously selected item, and after I processed what
I wanted, I updated it (the variable, that is) with the new
selection.
Sp+
|
|
|
|
|
I have a .dll with "C" functions that I need to call. One of the functions returns a simple struct(2 doubles)
If I try to use DllImport like this:
[ DllImport("somedll.dll]<br />
SomeStruct1 f1(SomeStruct1 *pS);
I get compiler error C3385 "a function that has a DllImport Custom Attribute cannot return an instance of a class"
How can I import a function from a DLL that returns a struct???
Thanks a ton,
Sam
|
|
|
|
|
I have ever thought, that exported functions cannot return a struct or class. Try to pass the return value by pointer: void f1(SomeStruct1 *pS, SomeStruct1 *pReturn);
Robert-Antonio
"Love without sex is like a fish without antlers"
|
|
|
|
|
Is it possible to lock toolbars in place, a bit like what IE is doing when checking the "lock the toolbars" in the view mene, without having to chant incantations and lighting incense to the god of win32 API ?
I think that I need to change the style, and maybe have to remove the gripper.
Any info ?
Thanks ...
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
If this is an MFC application, not calling EnableDocking() and DockControlBar() in the mainframe's OnCreate() method will keep the toolbar from docking (i.e., locked).
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
How do you permit scientific notation to be accepted in an edit box? Currently, I have it set to accept a float, but need it to accept scientific notation. Then I will need to pass this value to a register on a PCI board.
Thanks for any assistance.
Walt
|
|
|
|
|
Walt_S wrote:
How do you permit scientific notation to be accepted in an edit box? Currently, I have it set to accept a float, but need it to accept scientific notation.
By default, an edit box can accept any charcter that can be typed, and most that can be pasted. If you are wanting to limit the input to only scientific characterfs, you'll need a formatted edit control. Check here for ideas.
Walt_S wrote:
Then I will need to pass this value to a register on a PCI board.
What format (e.g., long, double, char) is the register expecting the number in?
A rich person is not the one who has the most, but the one that needs the least.
|
|
|
|
|
The register is expecting a double.
Thank you for the info.
Walt
|
|
|
|