|
Why subclassing is very boring ?
Hook into EndPaint, where you can get the DC before it's released.
|
|
|
|
|
Subclassing takes a lot of time because a class have to be crated for each control type.
By hooking, do you mean make a class that inherits for example CButton and have an own EndPaint which overrides the standard one?
|
|
|
|
|
You can define a single class for subclassing all windows, each with an instance of the class. The reason is you just need to get control after WM_PAINT message is processed.
By hooking this time, I mean overwrite the code for EndPaint to point to your code.
Check this: http://www.fengyuan.com/article/wmprint.html
|
|
|
|
|
Yes, I can define a single class to subclass all windows, but not all controls. A class which subclasses CButton must inherit CButton, at least according to Visual Studio.
Overwrite the code for EndPaint surely works, but it isn't something you want to put in your application if you can avoid it. It also means changing the call for other applications.
I want to be able to access the contents of the client area as a device context or something similair when I know that all drawing is done for now. If I knew how to call a controls default drawing procedure, I could subclass all controls as a last solution and use OnDrawItem.
I don't want to create my own classes where I inherit for example CButton since I must ship those with my application, and they would be unusable with the dialog editor.
I've also notified that OnPaint isn't called for a CButton when pressed. Why not?
|
|
|
|
|
Defining a class without MFC to subclass every window, including all controls.
Why MFC ?
|
|
|
|
|
I have an MDI application. I have created an accelerator associated with the VK_DELETE key.
I would like to disable the translation of this accelerator in one type of frame window but not in others. How can i do it?
Thanks in advance,
Jose.
|
|
|
|
|
Hello people,
See this code:
#ifdef DLLTEST_EXPORTS
#define DLLTEST_API __declspec(dllexport)
#else
#define DLLTEST_API __declspec(dllimport)
#endif
//This class is exported from the dlltest.dll
class DLLTEST_API myclass {
public:
vector <myclass*> v;
myclass(void);
// TODO: add your methods here.
};
Every time I try to export classes (see example above) that use stl classes (e.g. vector) from DLL I get the following warning:
warning C4251: 'v' : class 'std::vector<class myclass="" *,class="" std::allocator<class="" ,="" *=""> >' needs to have dll-interface to be used by clients of class ',myclass'
Any Ideas to solve this?
|
|
|
|
|
I'm not sure, but it looks to me as though the problem is that your class inherits from a parameterized class without using templates. Either
template <class Ty_, class A_ = std::allocator<Ty_> > class DLLTEST_API myclass {
public:
std::vector<Ty_, A_> v;
...
};
or
class DLLTEST_API myclass {
public:
std::vector<char> v;
...
};
should work for you.
In the former case, you may also get into some trouble if you do not define specific instantiations of your generic class, since the way templates are handled in VC++ does not allow separate compilation of the bodies of template functions and class methods, so you can't hide the implementation details of generic classes in a .cpp file that goes into a DLL---the implementation must be present in the header file.
|
|
|
|
|
Read the article of Joseph M. Newcomer "Time is the Simplest Thing..." on this site: http://www.codeproject.com/system/simpletime.asp
|
|
|
|
|
Can any body help me how to achieve serialization in controls.Like suppose if check a checkbox it displays a rectangle in the view.it stays for till the application is closed.While once again if i open the application...how to keep the check mark remain as it is.....urgent?
|
|
|
|
|
Not sure this is what you are looking for, but it may be useful.
I'm assuming you have an MFC app here.
For settings like this, maybe the registry is a better choice than serializing to file. Standard practise is to have code in your InitInstance to get the settings, and code in Exit Instance to save them.
For example in InitInstance, I have code that does something like this to let the user know what directories they're working with:
SetRegistryKey(_T("My Application"));
LoadStdProfileSettings(16);
m_dlgOptions.m_strSlideDir = GetProfileString(_T("Settings"), _T("Slide directory"));
m_dlgOptions.m_strTaskDir = GetProfileString(_T("Settings"), _T("Task directory"));
m_dlgOptions.m_strResultsDir = GetProfileString(_T("Settings"), _T("Results directory"));
m_dlgOptions.m_nLastTaskID = GetProfileInt(_T("Settings"), _T("Last used task ID"),1000);
m_dlgOptions.m_nLastUserID = GetProfileInt(_T("Settings"), _T("Last used user ID"),100);
Then, since the user can change these, ExitInstance has mirror code to write them back:
WriteProfileString(_T("Settings"), _T("Slide directory"),m_dlgOptions.m_strSlideDir);
WriteProfileString(_T("Settings"), _T("Task directory"),m_dlgOptions.m_strTaskDir);
WriteProfileString(_T("Settings"), _T("Results directory"),m_dlgOptions.m_strResultsDir);
WriteProfileInt(_T("Settings"), _T("Last used task ID"),m_dlgOptions.m_nLastTaskID);
WriteProfileInt(_T("Settings"), _T("Last used user ID"),m_dlgOptions.m_nLastUserID);
You'll probably want to write a 1 or 0 to some key based on the checkbox setting, and if the dialog is not a member of the App class you'll need to update the App class with the data.
If you are saving lots and lots of data though, this might not be the best way to go.
One added advantage is that these settings come from HKEY_CURRENT_USER, so when another user logs on they get their own settings.
Actually, this is not serialazation of controls so much as preservation of the state they represent.
|
|
|
|
|
I am trying to connect to an MS Exchange Server, get all of the registered e-mail addresses and then cleanly exit. I have tried to do this with MAPI but so far been unsuccessful. ANy Ideas?
alan rencher
|
|
|
|
|
Hi , I was wondering how a callback timer procedure works ? It will be best if anyone can provide me with a source code to illustrate as an example. Thanks alot.
|
|
|
|
|
How can i get the Window-Name of a process, if i know the PID?
Or is there a way to check, if this process is running, if i still now the PID!
Thank's
|
|
|
|
|
Dr Norm says:
Enumerate all the windows on the system, this may sound an expensive process, but its quite fast.
Regards
Norm
// In your header...
struct EnumTest
{
DWORD dwProcID;
HWND hWnd;
};
... somewhere in your code
EnumTest t;
ZeroMemory(&t, sizeof(t));
t.dwProcID = yourProcID;
EnumWindows(EnumWindowsProc,(LPARAM) &t);
// If we found it
if (t.hWnd != 0)
{
char szBuffer[256];
GetWindowText(t.hWnd, szBuffer, sizeof(szBuffer));
}
BOOL CALLBACK CRemote::EnumWindowsProc(HWND hWnd, LPARAM lParam)
{
DWORD dwID = 0;
if (GetWindowThreadProcessId(hWnd,&dwID))
{
EnumTest *p = (EnumTest*) lParam;
DWORD dwResult;
if (dwID == p->dwProcID)
{
pProc->bHung = TRUE;
return FALSE;
}
}
return TRUE;
}
|
|
|
|
|
My first question to you would be "Why?"
If you have the PID, that suggests that you spawned this process. What are you trying to do? Find out when a process has ended? If that's the case, you need only wait on the process handle in a background thread.
|
|
|
|
|
If you were writing a spy program that monitors some aspect of the program, the obvious thing to do is to present the user with a list of process names, rather than a list of PIDs. Also if you were writing a task manager like program or a program to list the DLLs of a given process.
Plenty of reasons.
Stephen Kellett.
|
|
|
|
|
Yes, there are plenty of reasons. I want to know *HIS* reason, since there is probably some other way to accomplish what he wants.
|
|
|
|
|
Hi
First, thank you for your help, it was helpful.
I like to program an NT-Service, which starts a DOS-program. So if the program has been terminated, the service has to shut down too.
So I just like to find out when a process has ended or to find out the status of this process.
Peace
|
|
|
|
|
I don't know if any of you have ever noticed this... but assume that you want to create a popup menu that appears when you right in a tree control.
If you are using the single selection style (and perhaps in other cases as well) if you right click an item that does not have the selection/focus... then handle the NM_RCLICK notification and display a popup menu during it... the selection shifts BACK to the original item that was highlighted... instead of the item that was right clicked.
I assume that I am missing some simple trick to avoid this. I'm getting frustrated here.
Thanks for any assistance anyone can provide!!!
|
|
|
|
|
Funnily enough I just solved this one yesterday.
Hope this helps
Norm
void CLeftView::OnRclick(NMHDR* pNMHDR, LRESULT* pResult)
{
// Find client cursor pos...
CPoint point;
GetCursorPos(&point);
ScreenToClient(&point);
// Setup hit-code for treeitem
UINT dwItem = TVHT_ONITEM;
HTREEITEM hItem = GetTreeCtrl().HitTest(point,&dwItem);
if (hItem == NULL)
return;
// Now select the item - for real
GetTreeCtrl().Select(hItem,TVGN_CARET);
// ... some other code...
}
|
|
|
|
|
Hi All,
Q1: Any one have (simple) sample code on establishing a TCP Connection???
Q2: I need to capture some TCP/UDP Packet data (to see what a client sends to a virus server when a virus if found). I have a sniffer and the data is coming out unreadable (portions of it)??
Project Explination: I need to find out what data is being sent to a virus server which reports the virus. Once I have that, create a program that will test the reporting on all of the Virus Servers (50+). Basically send TCP/UDP message to each Server...who ever doesn't report the virus is having reporting problems.
Help is much appreciated
Thanks in advance,
Dan
|
|
|
|
|
Ok - so basically your prog is a kind of 'yes I'm here' type thing that you can run periodically to see that all hands are reporting.
The real killer would be if the packets are encrypted by the reporting program - then your only hope is binary dup and pray you fool the server.
But the first problem is getting the data.
You will probably be looking for UDP packets arriving from the clients on the server. (Just a guess). Next, there will probably be a port number you can identify (the servers listen or 'recievefrom' sockets local port).
Once you have that info, you can filter the packets accordingly and see whats being sent.
Just a suggestion though - except for the fact that you'll see the virus server respond, all your testing is that the wire's not cut. You could probably write simple clients on both ends to test that. (yes even a one socket client can do some 'listening' if you don't overload it).
Hmmm... surely this has been done before... hmmm... need coffee... hmmm... where's the 'sleepy' emoticon...
|
|
|
|
|
Thanks for the info Tim. I have created a server component that will monitor a port (139 - TCP) used by the reporting Server. After I perform some tests, I'll let you know hao it turns out. Seeing that this is not anything that my firm will not have a problem with me posting the code for others to use that need to perform simular tests.
Thanks in advance,
Dan
|
|
|
|
|
Has anyone capture the appearance of mouse on windows 98?
|
|
|
|