|
(btw - no harm in starting a new thread with offshoot topics like this )
This question takes you into the fun and exciting world of Classic Win32. Well, perhaps i'm being generous with "fun and exciting"... but anyway...
In a nutshell, this is how it works: in basic ol' Win32 (and Win16 for that matter), dialogs are not quite the same as "regular" windows. They aren't created in the same way, they don't get passed messages in the same way, and the default behavior for unprocessed messages isn't the same either. MFC does a lot to hide this from you, but at its core it still behaves in much the same way. Which makes things interesting when you're creating a non-modal by deriving a class from CDialog , because you inherit a lot of defaults that you really don't want.
And one of those behaviors is what happens when you call ::DefWindowProc() with WM_CLOSE as the message. As you've found, dialogs do not call DestroyWindow() - they post WM_COMMAND with WPARAM set to 2 (IDCANCEL ). And because the message is posted, you don't get a nice call stack leading back to OnClose() from OnCancel() .
Why is this so? Because you don't close dialogs - real modal dialogs - by calling DestroyWindow() . They have their own message loops that need to be cleaned up, and those take care of actually destroying the window, so you call EndModalLoop() in MFC, or EndDialog() in Win32. And that is what the default behavior for OnClose() /OnOk() end up doing... which as you've noticed, is nearly useless for non-modal dialogs.
|
|
|
|
|
Yeah, its starting to make sense. But why when I hovered over the nMsg in the DefWindowProc did the message come back as 16. I know IDCANCEL is 2
#define IDOK 1
#define IDCANCEL 2
#define IDABORT 3
#define IDRETRY 4
#define IDIGNORE 5
#define IDYES 6
#define IDNO 7
#if(WINVER >= 0x0400)
#define IDCLOSE 8
#define IDHELP 9
Still scratching. Oh and by the way thanks for your help.
|
|
|
|
|
Here's a little trick: in the debugger, put a number (or variable) in the watch window, and follow the name with , wm - it'll display the name of the window message that the number maps to. But you're not gonna see IDCANCEL being passed in nMsg anyway - it's passed in the wparam field, while the message is WM_COMMAND .
|
|
|
|
|
Sounds neat, I wish I could get it to work. Both wparam and lparam are zero with nMsg = 16. I using Visual C++ 6.0 so maybe the watch stuff is a new edition.
IDCANCEL, wm gives me an error message in the watch window.
I also looked up the value of WM_COMMAND and it is 273
|
|
|
|
|
mx483 wrote: IDCANCEL, wm gives me an error message in the watch window.
Wrong way about. Try:
16, wm<br /> or
nMsg, wm<br /> Put a breakpoint in OnCancel() , and look up the callstack when it gets hit - you'll see WM_COMMAND being processed then.
|
|
|
|
|
Thanks for being so patient. Yep It works, it was case sensitive. I see where the WM_CLOSE message is being posted. I can keep pressing F11 and trace into the functions where finally the DefWindowProc shows up. Then I can go to the call stack and see all this too. I think I'm back to wondering why (according to you) I should be seeing a WM_COMMAND message instead of a WM_CLOSE message.
Hey thanks you are teaching me a bunch!
|
|
|
|
|
mx483 wrote: I think I'm back to wondering why (according to you) I should be seeing a WM_COMMAND message instead of a WM_CLOSE message.
You'll see both - WM_CLOSE first, then (if you let the default handler handle it) WM_COMMAND .
|
|
|
|
|
Thanks for your patience and thoughtful comments. Jay
|
|
|
|
|
I have a lattice, each cell of it stores a random number between 0 and another number (for example 25000). I would like to visualize this lattice on a Windows Form by coloring its cells with different shades of a color, according to the number they contain, I mean small number->light shade, large number->dark shade. Does anyone have a good idea how can I get those shades?
Thanks in advance.
|
|
|
|
|
by lattice, you mean something like a grid/2d array/spreasheet ?
I suggest you display your data using Chris Maunder's Grid Control[^], and define one new cell type that will draw itseld according to the number drawn inside it.
to define the shading, you have a number of choices, I suggest something simple using RGB values; to use shades of grey; but there is a resolution issue, depending on the range of the numbers in the cells ( between lower and upper values ) each grey shade will be used for a range of number.
int iRandomNumber; int iLowerBound = 0;
int iUpperBound = 25000;
int iShadeValue;
iShadeValue = ( iRandomNumber / iUpperBound ) * 255;
COLORREF cShadeColor = RGB( iShadeValue, iShadeValue, iShadeValue );
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Here's how to make a rainbowish colours:
COLORREF Rainbow(unsigned int val)
{
enum
{
max = 255,
h = max/2
};
BYTE red;
if ( val<h )
{
red = static_cast<BYTE>(255.0*(1.0-double(val)/double(h)) + 0.5);
}
else
{
red = 0;
}
BYTE green;
if ( val<h )
{
green = static_cast<BYTE>(255*(double(val)/double(h)) + 0.5);
}
else
{
green = static_cast<BYTE>(255*(2.0-double(val)/double(h)) + 0.5);
}
BYTE blue;
if ( val<=h )
{
blue = 0;
}
else
{
blue = static_cast<BYTE>(255*(double(val)/double(h)-1.0) + 0.5);
}
return RGB(red, green, blue);
}
0->Red, 128->Green, 255->Blue and the rest fall between.
Steve
|
|
|
|
|
Here's code to make a better rainbow:
-------------------------------------
COLORREF Rainbow(int x)
{
enum
{
maximum = 255, // Range of x is from 0 to this value.
h1 = maximum/4,
h2 = maximum/2,
h3 = 3*maximum/4,
};
const double m = 255/h1;
BYTE red;
if ( x<=h1 )
{
red = 255;
}
else if (x>=h2)
{
red = 0;
}
else
{
red = static_cast<BYTE>(-m*x+510.0 + 0.5);
}
BYTE green;
if (x<h1)
{
green = static_cast<BYTE>(m*x + 0.5);
}
else if (x>h3)
{
green = static_cast<BYTE>(-m*x+1020.0 + 0.5);
}
else
{
green = 255;
}
BYTE blue;
if (x<=h2)
{
blue = 0;
}
else if (x>=h3)
{
blue =255;
}
else
{
blue = static_cast<BYTE>(m*x-510.0 + 0.5);
}
return RGB(red, green, blue);
}
Steve
|
|
|
|
|
Hi,
Thanks for your help, I got really nice rainbowish colors. But I need to get only the shadows of one color (for example: different shades of grey or red). I have tried to modify your code, unfortunatelly I could't get the right solution. Is the method proposed by you suitable to solve this problem? Thanks. DirA
|
|
|
|
|
Code like this should do it:
double f = double(val)/max_val;
COLORREF Shade = RGB(GetRValue(BaseColour)*f, GetGValue(BaseColour)*f, GetBValue(BaseColour)*f);
Where
- val determines the shade an in between 0 and max_val .
- BaseColour is the base colour, the colour you want shades of.
Steve
|
|
|
|
|
How to create an application, which open multiple instances without invoking new exe.
For example if we open different word documents, many new word application will open, but there will be only one exe running at a time.
Thanks
anil
|
|
|
|
|
See here.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
It is for avoiding multiple instance. I need an application, whcih can spawn many instance from same exe. In WORD, if we open many word documents, we can see many windows as orginal one, but if we go to TaskManger, ther is only one WindWord.exe...
|
|
|
|
|
anilFirst wrote: we can see many windows as orginal one, but if we go to TaskManger, ther is only one WindWord.exe..
What MDI application!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
My bad. I misread your request. Most posts want to know how to limit the instances to one.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
|
Help! Im trying to figure out Active Directory and the C++ interface that microsoft provides. I need to return to a list box all the OUs in a domain. The application Im writing should eventually allow a user to create a new user in a domain and an OU selected from it. The problem I have is, what to do after binding to the object. Here is what I have so far........
CoInitialize(NULL);
IADsOU *pObject = NULL;
HRESULT hr;
hr = ADsOpenObject(L"LDAP://OU=yyy,DC=XXX,DC=xxxx,DC=co,DC=UK", NULL, NULL, ADS_SERVER_BIND, IID_IADs, (LPVOID*)&pObject);
if (hr == S_OK)
{
// need to get all OU's here somehow?
pObject->Release();
}
CoUninitialize();
This doesnt work though and I could really use some help with this Our AD structure is as follows:
DC=XXX.xxxx.co.uk
--OU=yyy
----OU
------User
----OU
------User
Hope this helps.
regards,
|
|
|
|
|
Dear everyone;
I want to build a flash decompiler. How hard is that gonna be ??? And will it take a very long time?
Does any one know how to do that? Or at least direct me to some articles if possible.
Your views and suggestions will be very much appreciated.
Thank you
llp00na
-- modified at 7:27 Wednesday 15th February, 2006
|
|
|
|
|
|
I really could not find any articles about how to make flash decompilers on google. most of what i found are commercials and products.
Well i want to build a flash decompiler for legal purposes. I am not gona sell the product or anything, i just need it as part of my research and its not my ultimate objective.
Its really weird though seing companies selling flash decompilers while you say it is illegal !!!
I need more views please
llp00na
|
|
|
|
|