|
csrss wrote: so i can use it in some static methods
If you want to use static member functions or access static variables in your class, you do not have to use a static pointer or instance of that class!
When a member function is static, it means that it does not access any data members of the class or its base class(es), and also it does not use any member function that isn't also static. Therefore you do not need an instance of the class at all!
Here is an example:
class CMyClass {
private:
static int myMagicNumber;
public:
static void magic() {
std::cout << "My magic number is: " << myMagicNumber << std::endl;
}
};
CMyClass::myMagicNumber = 111;
int main() {
CMyClass::magic();
}
As you can see I never created an instance anywhere; it isn't needed.
|
|
|
|
|
How about such example:
DWORD __stdcall xxx::Monitor(LPVOID lParam)
{
HINSTANCE hExe = ::GetModuleHandle(NULL);
if (!hExe) hExe = ::LoadLibrary((LPCSTR)lParam);
if (!hExe) ::ExitThread(-1);
m_pThis->m_hMonitorHook =
::SetWindowsHookEx (WH_MOUSE_LL, MsgMonitorStatic, hExe, 0);
if(m_pThis->m_hMonitorHook == NULL)
{
::ExitThread(-1);
}
m_pThis->MonitorMessagePump();
UnhookWindowsHookEx(m_pThis->m_hMonitorHook);
return 0;
}
....
m_hMonitorThread = ::CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Monitor, whatever,
CREATE_SUSPENDED, &m_dwMonitorThreadId);
MsgMonitorStatic also uses m_pThis to access class members and functions, modify them, call them, check them? Here i gave small example, in my project there are hundreds of lines of a code of methods which call another methods.
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
I can see no purpose the variable m_pThis serves, and I do not know why it is considered neccessary here. Nor do I see anything that's actually static. In fact, since you said that stuff is being modified, the member functions cannot be static. So I don't know why you think this is in any way relevant to your problem.
The question is what do you want to achieve? As long as we don't know that we cannot advise you how best to implement it.
P.S.: This is just a guess, but it's possible that in the code you've posted the pointer m_pThis is meant as a means to implement the 'Singleton' design pattern. If so, then this has nothing to do with the usage of static methods or static variables: static members require no instance at all, like in the code example I gave above, whereas a singleton requires exactly one instance.
Also I am under the impression that such a construct isn't well suited to implement a singleton. But that is just an IMHO, and only a guess, since there is too little code to really get the picture.
modified on Monday, May 16, 2011 12:25 PM
|
|
|
|
|
Hey guys. First things first, i am using MFC.
Ok, the question is, what is the best way to create a new window so this new window will not receive a focus?
Its like this: i got a simple dialog box app and a button on it. When i click a button, it creates a new window, without any caption, just a popup window (WS_POPUP). But this little popup wnd gets focus and i dont want this. I want it be created but the focus should stay on Dialog box window. Besides, if i move a mouse or click on this popup window - it should not receive a focus, it should be kinda "focusless" - no matter what you do - it should not receive any focus ever. How this can be done?
Edit: Maybe i should rephrase a little bit: this popup sets itself as foreground window, dialog box window should stay as foreground, not popup window
Thanks
011011010110000101100011011010000110100101101110
0110010101110011
modified on Sunday, May 15, 2011 8:33 AM
|
|
|
|
|
isn't that what enabled/disabled is for? Not sure how to do it in MFC, but that is what I would have a look at.
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.
|
|
|
|
|
Nope.
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
Hi,
Your popup should handle WM_ACTIVATE with:
if (wParam != WA_INACTIVE)
::SetActiveWindow(::GetParent(GetSafeHwnd()));
cheers,
AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
Thank you!
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
Hi all,
I have created one application,where i am incrmenting and decrementing values using CSpinControl.
It is incrementing and decrmenting.
Now i want to increment and decement the same using keyboard up and event press using keyboard.
void CTestDlg::OnDeltaposSpinTest(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
if (pNMUpDown->iDelta == 1)
{
m_strvalue--;
UpdateData(FALSE);
}
else
{
m_strvalue++;
UpdateData(FALSE);
}
*pResult = 0;
}
void CTestDlg::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
m_strvalue--;
UpdateData(FALSE);
CDialog::OnKeyUp(nChar, nRepCnt, nFlags);
}
void CTestDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
m_strvalue++;
UpdateData(FALSE);
CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}
but it is not doing it.
can anyone help me.
Hi,,
I am sharan.Working as a software Engineer in Indo-Fuji Software Company located in BTM Layout.Bangalore.India.
I have Completed my B.E(COmputers)in 2006.ANd I am having 2 years of Exp in VC++.
thanking you
sharan
|
|
|
|
|
You do not need to write a single line of code.
Just set the Arrow Keys property of the spin control to True .
|
|
|
|
|
...and it is probably not working because the dialog doesn't have keyboard focus....a control on the dialog probably does.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
How to edit text in CListCtrl?
I am using InsertItem() but every time its adding new item in list control.I need to modify existing item.
I am using report style.
|
|
|
|
|
Maybe CListCtrl::SetItemText()?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
john5632 wrote: How to edit text in CListCtrl?
The answer is here[^].
cheers,
AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
Hi All,
I am trying to create a application,where,
when i click the button and hold the mouse the value should be incrementing until i release the mouse button.
How can i do it.
I am tying with below code:
void CTestDlg::OnButtonUp()
{
UpdateData(TRUE);
m_strvalue++;
UpdateData(FALSE);
}
void CTestDlg::OnTimer(UINT nIDEvent)
{
if(flag_value==1)
{
m_strvalue++;
UpdateData(FALSE);
}
}
void CTestDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
flag_value=0;
CDialog::OnLButtonUp(nFlags, point);
}
void CTestDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
flag_value=1;
CDialog::OnLButtonDown(nFlags, point);
}
I am calling this OnLButtonUp event,but it is for whole dialog.i.e wherever i click and hold mouse on dialog the value is incrementing.
I want the same action on OnButtonUp(i.e when i click and hold the Button)
Thanks in advance
Sharan
Hi,,
I am sharan.Working as a software Engineer in Indo-Fuji Software Company located in BTM Layout.Bangalore.India.
I have Completed my B.E(COmputers)in 2006.ANd I am having 2 years of Exp in VC++.
thanking you
sharan
|
|
|
|
|
The usual way to do a repeating button is by writing a custom button control. For example, see here: http://www.codeproject.com/script/Articles/ListVersions.aspx?aid=1104[^]
You can approximate the action of an auto-repeat button by using a timer: when the timer event occurs, check if the left mouse button is down; if it is, and if the mouse is in the button rect, then increment your counter. Note that you will also have to check if the mouse leaves the button, at which point you should kill the timer.
|
|
|
|
|
How to add sub item in menu?
|
|
|
|
|
MFC? Win32?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Start by searching in MSDN[^].
The best things in life are not things.
|
|
|
|
|
john5632 wrote: How to add sub item in menu?
The answer is here[^].
cheers,
AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
Hello,
I am C,C++/VC++ developer. I wanted to know, as in every C/C++ program there is startup function main(), who calls this function. I know OS, but I want some in detail answer. Also I wanted to know how my program actually starts, means how it is loaded in memory, who loads it and etc..
Thanks in advance.
Regards
|
|
|
|
|
This question can only be answered by looking at a specific OS. In general the OS starts the respective runtime which in turn calls into main after doing some initialization work. If you want to know the exact call stack for YOUR system, just hold on in the properly configured debugger at some point of the program and trace back to the roots... Use breakpoints on visible global objects with non-trivial constructors to see what's happening before the program enters main . At least on Windows you will be able to trace back the runtime-code as well.
Cheers,
Paul
|
|
|
|
|
The operating system takes care of loading an executable file into memory, and then starts executing it at a specific point in the code, known as the "entry point". It has a special field in the EXE file format, which obviously gets filled by the linker from the information it got from the compiler. The entry point's name may vary, in C it normally is called main, and sometimes WinMain. In other languages it may be called differently, it is basically a convention between the programmer and the compiler.
For Windows, you can get the EXE file format specification here[^]. That will keep you busy for a while!
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.
|
|
|
|
|
Luc Pattyn wrote: The entry point's name may vary, in C it normally is called main, and sometimes WinMain.
Not quite; these are the start points for the user part of the application, and are called by the initialisation routine, which is why (Win)main() has to have a specific signature. The actual entry point of the exe is much earlier and is part of the framework library that is automatically added by the linker.
The best things in life are not things.
|
|
|
|
|