|
I'll assume you mean styles like WS_VSCROLL and such...?
Umm...well I dunno if windows reserves all 32 bits of the DWORD nStyle paramter, but you could find out pretty easy and use bit locations that weren't used or use a DOWRD StyleEx and set your own bits using bitwise OR's.
Like this overloaded version of Create
Create(CWnd* pParent, DWORD nStyle)
{
CWnd::Create(nSytle...blah);
}
For instance if bit 17 wasn't already used by CreateWindow() you could use it to specifiy SHOW/HIDE 3D borders around custom button control.
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
How do you handle them I guess is what I was wondering. Say you have an enumeration.
enum { ID_STYLE1 = 0, ID_STYLE2 = 1, ID_STYLE3 = 2 };
How do you handle the those styles in a function with the bitwize OR and AND ops? Thanks for the inputs in advance.
-CDuddley
|
|
|
|
|
Hope this is what you are after.
Serge
class MyClass
{
public:
enum Style
{
Style1 = 1 << 0, // bit 0
Style2 = 1 << 1, // bit 1
Style3 = 1 << 2, // bit 2
// so on
};
MyClass() : m_styles(0) {}
void SetStyle(Style style) {m_styles |= style;}
void ClearStyle(Style style) {m_styles &= ~style;}
void Dump() {printf("Style = 0x%08X\n", m_styles);}
private:
unsigned int m_styles;
};
void main()
{
MyClass mc;
mc.SetStyle(MyClass::Style1);
mc.Dump();
mc.SetStyle(MyClass::Style2);
mc.Dump();
mc.SetStyle(MyClass::Style3);
mc.Dump();
mc.ClearStyle(MyClass::Style3);
mc.Dump();
mc.ClearStyle(MyClass::Style2);
mc.Dump();
mc.ClearStyle(MyClass::Style1);
mc.Dump();
}
|
|
|
|
|
#define CWS_3DBORDER 0x01 //First bit of DWORD style is now used by child window style (CWS)
m_wndChild.Create(this, WS_CHILD | WS_VISIBLE | CWS_3DBORDER);
CCustom::Create(CWnd* pParent, DWORD nStyle)
{
m_b3DBorder = nStyle & MASK;
}
CCustom::OnPaint()
{
CPaintDC dc(this);
if(m_b3DBorder)
}
You may have to give the and operation the once over
I dunno how accurate my attempt at masking bits is in the above...but you should figure it out easily. I did try and give a solid example of how I would use custom flags.
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
I have created a control from scratch derived from CWnd.
The only problem I had was deriving from this control at first I couldn't figure out why nothing was happening after the overloadded Create function was called. I quickly figured out how t fix it, but i'm not 110% sure why?
Basically in my newly derived class I had to implement(???) each function that was implemented in the base class and call the base class version in the derived class.
Is there another way around this...?
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
I would be puzzled too because, generally speaking, you do not have to do this. You only need to implement functions that are overridden in derived classes or those that are pure virtual (not implemented in the base class.)
Something strange is afoot at the Circle-K.
|
|
|
|
|
I can't figure it out...i've done nothing out of the ordinary...my computer is definetly screwing up though.
default paramters in one of my member functions compiled fine, but the classwizrd wouldn't locate the function...so I had to remove one default parameter and everything worked fine again.
Thanx
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Did you really have to implement every function? CWnd has an awful lot of functions.
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
Hockey,
This sounds *very* strange. Send me the files if you want - I'll check them.
Regards,
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
What are the best tools available for detecting memory leaks in MFC applications? I have tried boundschecker so far, wondered if anyone could recommend any others out there...
Also, if anyone has ever seen a system error box "Required Resource Was" (thats it!), I would love to know what it means...
Cheers
|
|
|
|
|
I like Rational Purify
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Here is a link to Fortify. I believe it is free.
Also, VC++ has fairly good built-in facilities. Check MSDN for articles on this topic.
|
|
|
|
|
Rick York wrote:
Here is a link to Fortify
Thanks. I was lookin for a free tool too...
Nish
My miniputt high is now 29
I do not think I can improve on that
My temperament won't hold
www.busterboy.org
|
|
|
|
|
hi there. I have a text box that holds a string, i want to have a button so that when you press it, the string in the textbox is added to the list box. Can some please help me
Greatly Appreciated.
|
|
|
|
|
See the documentation on CEdit and CListBox . There are methods to get the string from an edit control and add it to the list box. I was tempted to write the few lines of code for you, but I'd be doing you a disservice by not putting you on the right track instead.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
No you can't...
You see, another process doesn't have access to the memory you are passing to SendMessage. You are actually lucky your SendMessage isn't crashing the other application.
Now some messages such as WM_GETTEXT have code inside of GDI32 or USER32 (whatever) that handle this case for you. But, most messages don't have this. Generally, you shouldn't be sending messages to other application unless the message has been specifically designed to support inter-process sends.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Hi Im trying to override the equal_range method in a class
inherited from multimap so it is non case sensitive:
#include <algorithm>
#include <string>
#include <map>
typedef std::pair<std::string, void *> Range_t;
typedef std::multimap<std::string, void *> MyMap;
typedef MyMap::iterator MyMapIterator;
bool nocase_compare(Ranger a, const Ranger b) { return a.first < b.first; }
class AMap : public MyMap {
Range_t equal_range(MyMapIterator start, MyMapIterator stop, const std::string& key) {
return std::equal_range(start, stop, key, nocase_compare);
}
};
int main()
{
AMap m;
}
But I just cant get the nocase_compare to match what equal_range needs. Help someone?
help
|
|
|
|
|
Try with bool nocase_compare(const Ranger& a,const Ranger& b) .
Also, *start and *stop must be of the same type as key (which they are currently not, I think).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I have come across an interesting problem. I have a Resource only DLL which contains only string tables in about 7 languages. Using the resource editor I can confirm that the Dll is built correctly.
In InitInstance of my app I call LoadLibrary and save the returned handle. ( m_hInstDLL )
The I added a function for extracting the strings. This is when the fun starts.
This code works and returns the string from the default language table.
HINSTANCE hInst = AfxGetResourceHandle();
CString theString;
AfxSetResourceHandle( m_hInstDLL );
theString.LoadString( IDS_TESTDTRING );
AfxSetResourceHandle( m_hInst );
However if I use the FindResource or FindResourceEx functions they fail as in the following code.
HINSTANCE hInst = AfxGetResourceHandle();
CString theString;
AfxSetResourceHandle( m_hInstDLL );
theString.LoadString( IDS_TESTDTRING );
HINSTANCE hInst2 = AfxFindResourceHandle(MAKEINTRESOURCE(IDS_TESTSTRING), RT_STRING);
HRSRC hRes = ::FindResource(hInstDLL,MAKEINTRESOURCE(IDS_TESTSTRING), RT_STRING);
......
AfxSetResourceHandle( m_hInst );
The interesting thing is that AfxFindResourceHandle returns the same value as hInstDLL, as it should. This means that AfxFindResourceHandle finds the string resource. FindResource on the other hand returns 0.
Calling FindResourceEx with the appropriate language code also returns 0.
What makes this even more confusing is that in searching through MSDN it is stated that AfxFindResourceHandle actually calls FindResource.
Ideas anyone? It must be possible to make it work.
Happy programming!!
|
|
|
|
|
AfxSetResourceHandle( m_hInstDLL );
theString.LoadString( IDS_TESTDTRING );
HINSTANCE hInst2 = AfxFindResourceHandle(MAKEINTRESOURCE(IDS_TESTSTRING), RT_STRING);
HRSRC hRes = ::FindResource(hInstDLL,MAKEINTRESOURCE(IDS_TESTSTRING), RT_STRING); This might be an absolutely irrelevant question, but have you noticed you're using two variables m_hInstDLL and hInstDLL ? Do they store the same value?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
That is a typo in here, it is actually m_hInstDLL.
Happy programming!!
|
|
|
|
|
I found 2 issues in ATL 7.0 (code in atlbase.h) regarding services. I may or may not be right, some of you will tell me if I'm not. Here they are:
1- A service with no COM interface refuses to start
When creating a service, and you don't define any COM object in it (let's say you want to write a service in ATL, but don't have any use of a COM server in it), it won't start with the SCM reporting that it refuses to start without returning an error code.
This is because of the call to RegisterClassObjects in CAtlExeModule<T>::PreMessageLoop() . When there is no object to register, this method returns S_FALSE . In the CAtlServiceModule<T>::Run() method, there is a line that says:
if (hr == S_OK) {
}
The problem with that is that hr = S_FALSE . Replace with the following:
if (SUCCEEDED(hr)) {
}
Some may argue that there is no point in having a service not exposing a COM object. To those I say "hey, COM is not the only thing that a server could implement". Heh. And I like to write services using ATL because it is easy.
2- Multithreaded service
If you write a service containing objects with the "free" threading model, you may want to change the _ATL_APARTMENT_THREADED define to _ATL_FREE_THREADED in stdafx.h . I can tell you upfront that your service will start but you won't be able to activate any of the COM objects in it.
The problem is with the m_bDelayShutdown member variable in CAtlExeModule<T> , from which CAtlServiceModule<T> derives. In CAtlServiceModule<T>::ServiceMain , this member is set to false , probably because it is irrelevant (and maybe harmful, who knows) in a service.
This generates a problem in CAtlExeModule<T>::PreMessageLoop . Look at this snippet from the function:
hr = pT->RegisterClassObjects(CLSCTX_LOCAL_SERVER,
REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED);
if (FAILED(hr))
return hr;
if (hr == S_OK)
{
if (m_bDelayShutdown)
{
CHandle h(pT->StartMonitor());
if (h.m_h == NULL)
{
hr = E_FAIL;
}
else
{
hr = CoResumeClassObjects();
ATLASSERT(SUCCEEDED(hr));
if (FAILED(hr))
{
::SetEvent(m_hEventShutdown); ::WaitForSingleObject(h, m_dwTimeOut * 2);
}
}
}
if (FAILED(hr))
pT->RevokeClassObjects();
}
else
{
m_bDelayShutdown = false;
}
NOTE: This code is only available with _ATL_FREE_THREADED defined.
As your keen eye may have noticed (see the bolded lines of code if not), the RegisterClassObjects method is called with the REGCLS_SUSPENDED flag. This requires a call to CoResumeClassObjects in order for a client to be able to activate an object from your exec.
If you read the code carefully, this method is never called if m_bDelayShutdown is set to false . What I did is simply override the PreMessageLoop method (tell me if you don't know how to do it), and modify it as follow (see bolded line of code):
hr = pT->RegisterClassObjects(CLSCTX_LOCAL_SERVER,
REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED);
if (FAILED(hr))
return hr;
if (hr == S_OK)
{
if (m_bDelayShutdown)
{
CHandle h(pT->StartMonitor());
if (h.m_h == NULL)
{
hr = E_FAIL;
}
else
{
hr = CoResumeClassObjects();
ATLASSERT(SUCCEEDED(hr));
if (FAILED(hr))
{
::SetEvent(m_hEventShutdown); ::WaitForSingleObject(h, m_dwTimeOut * 2);
}
}
} else {
hr = CoResumeClassObjects();
}
if (FAILED(hr))
pT->RevokeClassObjects();
}
else
{
m_bDelayShutdown = false;
}
This will make your objects available to the outside world.
------------------------------------------------------------------------------
I don't know if I'm right or not, but it resolved some issues for me. If some of you find that what I'm saying is completely dumb, please demonstrate.
Tx for listening
Michel
If I am wrong or said something stupid, I apologize in advance
|
|
|
|
|
Write an article describing these issues. Your post in VC++ board will soon become old and nobody (ok, *almost* nobody) will be able to find it.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hello,
I'm having a problem with the CFileDialog class in a UNICODE build. I'm overriding the OnFileNameOK function, and upon entering the function, I'm finding that the nFileOffset and nFileExtension variables in the OPENFILENAME struct have not been set (or were set to 0) after DoModal called GetSaveFileName. The rest of the struct is filled out appropriately, and it is clear that nFileOffset should be a non zero value. In a non unicode build, the variables are set correctly. Am I missing something? Any help would be greatly appreciated.
Thanks,
SQ
|
|
|
|
|
Can you show some snippet of the offending code? Are you sure you haven't forgot some _T (or TEXT ) somewhere? How do you check the value of those parameters (OutputDebugString , debugger watch, other)?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|