|
Hi
I wrote a small program to count how many points are clicked using array. My count array doesnt work even though i wrote the declaration before or in the function itself.
For example:
int count=0;<br />
if((nFlags & MK_LBUTTON) == MK_LBUTTON){<br />
count++<br />
}
and
if((nFlags & MK_LBUTTON) == MK_LBUTTON){<br />
int count;<br />
count++;<br />
}
From what I can see is everytime a left mouse is clicked the array reset itself. The code is inside a OnMouseMove(UINT nFlags CPoint point) class.
Thanks
|
|
|
|
|
jw81 wrote:
int count=0;
if((nFlags & MK_LBUTTON) == MK_LBUTTON){
count++
actaully problem is of Scope of variable count .it is local variable in function.
let see what actually happening in your code-> Every time you click on mouse the count variable created in memory and as function ends, count variable scope end and program release it from memory.
now to solve this problem with either declare it in global or make it local to class which handlling you onmousemove function rather declarign it in function.
"I Think this Will Help"
[Vote One Here,.....]
<h5
alok gupta="" <br=""> visit me at http://www.thisisalok.tk
|
|
|
|
|
ThatsAlok wrote:
now to solve this problem with either declare it in global or make it local to class which handlling you onmousemove function rather declarign it in function
Or ... let it where it is now, but declare it as static .
By the "lifetime" point of view, global or static is mostly the same.
Declare it as class member will let every calss instance hace its own.
That is: if yor class is used to handle many windows and you want each one to have its own counter, make it a class member.
If you want a same single counter to count everything in all instances, declare it as static . In the function if only that function use it; In the class if many function class use it; globally if you have to access it from everywhere.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
emilio_grv wrote:
: if yor class is used to handle many windows and you want each one to have its own counter, make it a class member.
i think, it just a beginner problem,so i have given beginner answer.
conecpt of static is little complicated for beginner.
"I Think this Will Help"
[Vote One Here,.....]
<h5
alok="" gupta="" <br=""> visit me at http://www.thisisalok.tk
|
|
|
|
|
I guess Alok answered my question, thanks.
|
|
|
|
|
Hello,
I don't understand your problem exactly, but if this declaration is inside a funktion, well you declare a variable and reset it to zero, then ++ it.
could you please try using 'static int ... ' instead of your currnt statement? does it solve any problem?
|
|
|
|
|
I think you need to declare the count variable outside this function, eg. declare it as global or class member variable. If you declare in this function, every time you click the mouse, the counter is reset to zero.
|
|
|
|
|
how to write into the serial/parallel/USB port
using VC++6?
thx
|
|
|
|
|
|
up.
Before the main frame is created I want to display splashwindow for 3 seconds. how to do it?
|
|
|
|
|
Add A Splash window Control in your project.
you can find Splash window Control here ->
Project->add to Project->Component and Controls
Select Directory ->Visual C++ Components
and scroll to SplashWnd and insert it into your project.
"I Think this Will Help"
[Vote One Here,.....]
<h5
alok gupta="" <br=""> visit me at http://www.thisisalok.tk
|
|
|
|
|
hi!!
You can just create a dialog window... and use "BitBlt" to display any bitmap... add a timer control..and after the timer expires... start the app.. hope you fing this useful - V.G
|
|
|
|
|
But I can't use Timer in PreCreateWindof function.
|
|
|
|
|
you use it during the creation of the Frame window...just make it invisible... after the time expires, make it visible..ok? -V.G
|
|
|
|
|
I think about this:
<br />
BOOL CRightHTMLView::PreCreateWindow(CREATESTRUCT& cs)<br />
{<br />
MSG message;<br />
<br />
int i=0;<br />
m_nTimer = SetTimer(1, 100, NULL);
ASSERT(m_nTimer!=0);<br />
if(i==0)<br />
{<br />
dlg->DoModal();
if(::PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) {<br />
::TranslateMessage(&message);<br />
::DispatchMessage(&message);<br />
}<br />
i = 1;<br />
}<br />
Then
<br />
void CRightHTMLView::OnTimer(UINT nIDEvent)<br />
{<br />
Sleep(3000);<br />
dlg->DestroyWindow();<br />
KillTimer(1);<br />
<br />
CHtmlView::OnTimer(nIDEvent);<br />
}
Did you mean the same?
|
|
|
|
|
Thank you! I did it
|
|
|
|
|
can I use serialize to store and reterive non array data for example lets say that I have a class that has some array variables that I can use serialize to store them, but what if I want to also store some unique variables to the same file after all array data has been stored, is there a way or can I append data to that file ?
thanks in advance
|
|
|
|
|
If you're talking about serializing data in an SDI/MDI application, then it shouldn't be that difficult as long as your Document class knows about it. Serialization isn't resticted to arrays.
The heart of serializion is the CArchive class. Here's the documentation for CArchive::operator <<[^]. CArchive has a ton of overloads for this function (and their opposites CArvhive::operator >> ) to accomodate serializing (and deserializing) most common data types.
Just add the serialization code for your unique values after you've serialized your arrays by using a "cout "-type syntax, if that's where you want them to be.
Assuming you have the CArchive object, you can do something like this with any non-array values:
struct MyUniqueStuff
{
int nUniqueInt;
float fUniqueFloat;
char cUniqueChar;
void Serialize(CArchive & ar);
};
void MyUniqueStuff::Serialize(CArchive & ar)
{
if( ar.IsStoring() )
{
ar << nUniqueInt;
ar << fUniqueFloat;
ar << cUniqueChar;
}
else
{
ar >> nUniqueInt;
ar >> fUniqueFloat;
ar >> cUniqueChar;
}
}
Then, when you want to serialize or deserialize a MyUniqueStuff structure, just call its Serialize method.
Bob Ciora
|
|
|
|
|
|
Hi, I defined a CSplitterWnd variable in my CMainFrame class of a SDI project and want to access it from my CDocument class so I can have a pointer to different views that I have so I can post messages of Update and ... to each view according to cicumstances. I tried to get a pointer to the main frame by AfxGetMainWnd()->GetParentFrame() but the pointer is invalid and causes debug assertion, I think because when I want to access this pointer on OnNewDocument function still there is no main frame. so what is the solution how can I have a pointer to CMainFrame in CDocument so I can update different views from CDocument? or should I change the strategy and update view messages should come from other places. the application receives data from serial port and upon reception of some data views should be updated. thank you
|
|
|
|
|
Use this to get a pointer to the mainframe window from anywhere in your application:
CMainFrame* pMainFrame = (CMainFrame *) AfxGetMainWnd(); /ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Hi,
I am looking for an API that will return the 'group' to which the currently logged in user belongs.
Or is it a way to know if the currently logged in user belongs to a paricular user group?
|
|
|
|
|
Hi there,
Do you mean you want to list the groups of the user running your program?
I think the process is (sorry I don't have any example code):
ImpersonateSelf() - to generate an access token for the current process
OpenThreadToken() - to open the access token
GetTokenInformation() specifying TokenPrimaryGroup or TokenGroup as one of the parameters - to get a data structure with group information
Then walk the structure from this last function, looking for the group SID or SIDs.
Finally, to convert a SID to an actual text group name, use:
LookupAccountSid()
Hope this is a pointer in the right direction !
Thanks,
Neil Humphreys.
|
|
|
|
|
|