|
Hi,
I want to know, in a Doc/View MFC application, where is the place to map a message to quitting an application by the File menu and by the X button at the top right of a window ?
Thanks.
Claude
|
|
|
|
|
Hi,
WM_CLOSE would be posted when the X button is clicked or file->exit is chosen. If you can explain your what you're trying to achieve, someone may suggest a better way out.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
You can also use WM_SYSCOMMAND/SC_CLOSE.
|
|
|
|
|
Please reply to the person who asked the query.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
K, will take care about it
|
|
|
|
|
Hi,
I want to convert a 24 bpp image into 8 bit GRAYSCALE image. I have attached the following code snippet to do this .It is not working.
BITMAPINFOHEADER bmpInfoHeader;
BITMAPFILEHEADER bmpFileHeader;
unsigned int extrabytes, bytesize;
RGBQUAD palette[256];
unsigned int numPaletteEntries = 256;
// Fill the bitmap file header structure
bmpFileHeader.bfType = 'MB'; // Bitmap header
bmpFileHeader.bfSize = 0; // This can be 0 for BI_RGB bitmaps
bmpFileHeader.bfReserved1 = 0;
bmpFileHeader.bfReserved2 = 0;
bmpFileHeader.bfOffBits = 0;//sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * numPaletteEntries;
extrabytes = (4 - 320 % 4) % 4;
// This is the size of the padded bitmap
bytesize = (320 + extrabytes) * 435;
// Fill the bitmap info structure
bmpInfoHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfoHeader.biWidth = 320;
bmpInfoHeader.biHeight = 435;
bmpInfoHeader.biPlanes = 1;
bmpInfoHeader.biBitCount = 8; // 8 - bit bitmap
bmpInfoHeader.biCompression = BI_RGB;
bmpInfoHeader.biSizeImage = bytesize; // includes padding for 4 byte alignment
bmpInfoHeader.biXPelsPerMeter = 0;
bmpInfoHeader.biYPelsPerMeter = 0;
bmpInfoHeader.biClrUsed = numPaletteEntries;
bmpInfoHeader.biClrImportant = 0;
ByteArray = new BYTE[bmpInfoHeader.biSizeImage];
while(j < bmpInfoHeader.biSizeImage)
{
if(j < bmpInfoHeader.biSizeImage/2)
ByteArray[j] = 255;
else
ByteArray[j] = 0;
j++;
}
//Write the bitmap file header
UINT nWrittenFileHeaderSize = fwrite(&bmpFileHeader, 1,
sizeof(BITMAPFILEHEADER), pFile);
//And then the bitmap info header
UINT nWrittenInfoHeaderSize = fwrite(&bmpInfoHeader,
1, sizeof(BITMAPINFOHEADER), pFile);
//Finally, write the image data itself
fwrite(ByteArray, 1, bmpInfoHeader.biSizeImage, pFile);
Can u pls. help.
|
|
|
|
|
Member 6042182 wrote: while(j < bmpInfoHeader.biSizeImage)
{
if(j < bmpInfoHeader.biSizeImage/2)
ByteArray[j] = 255;
else
ByteArray[j] = 0;
j++;
}
What are you doing here?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Here ByteArray is an array of image data.I am not sure if BITMAPINFOHEADER and BITMAPFILEHEADER variables are correctly filled.I was trying to put some arbit data on that file.Will you tell me if the BITMAPINFOHEADER and BITMAPFILEHEADER variables are correctly filled?
int i=0,j=0;
while(j < bmpInfoHeader.biSizeImage)
{
ByteArray[j] = GrayData(m_pDrawingSurfaceBits[i++], 0.3;
ByteArray[j] = ByteArray[j] + GrayData(m_pDrawingSurfaceBits[i++], 0.59;
ByteArray[j] = ByteArray[j] + GrayData(m_pDrawingSurfaceBits[i++], 0.11);
j++;
}
m_pDrawingSurfaceBits is a pointer to data elements.
Where I have got m_pDrawingSurfaceBits from the following
CreateDIBSection(pDC->GetSafeHdc(), (CONST BITMAPINFO*)&BMIH, DIB_RGB_COLORS, (void**)&m_pDrawingSurfaceBits, NULL, 0);
GrayData is defined in following format.
BYTE CLoadBitmapDlg::GrayData(BYTE b, float Multiply)
{
float a;
a =(float) b;
a = a * Multiply;
b =(BYTE)a;
return b;
}
Is there any code to convert any bmp file to another bmp,in 8 bit grayscale format?
|
|
|
|
|
you need to write the pallete, too.
|
|
|
|
|
how can i give name to my exe module.
|
|
|
|
|
|
You are fast you changed your reply to a link!
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
|
i mean how can i give a name to my module that can be referenced to check that call to a specific function has come from which module.
|
|
|
|
|
See GetModuleBaseName .
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
On Visual Studio you may specify the name of the executable (if I understand your request). For instance (on VS2005 , at least)
Choose menu Project->Properties and then, select (on the appeared window) the Configuration Properties->Linker node and finally set the Output File property with the intended name.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
this is wat i exactly wanted but there is no output file property in linker options.m using vs2005.
|
|
|
|
|
Yes, there is. If you select the Configuration properties->Linker node (don't select any of the child nodes), then you may find the Output File property as the first item of the listview (such listview is on the right of the window).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
yeah thanx...it is in Configuration properties->C/C++.
|
|
|
|
|
I'm not sure whether this is the right place to ask. I am having difficulty trying to handle, in a conventional (unmanaged code) C++ application, an event raised by a managed code component.
I am tackling this as a C++ problem because I can successfully handle the same event, from the same component, in a VB6 application.
The component raising the event is implemented in C# and enclosed in a COM wrapper. On the C# side we have the following code:
public interface IMyObjectEvents
{ [DispId(1)] void TakenFocus(); }
public class MyObjectInterface : IMyObject
{
public event TakenFocusDelegate TakenFocus;
public void FireTakenFocus()
{
if (TakenFocus != null) TakenFocus();
}
}
The following code in an unmanaged VB6 application works fine:
Dim WithEvents oMyControl As MyControl.MyObjectInterface
Private Sub oMyControl_TakenFocus()
MsgBox "Event caught"
End Sub
When the object calls FireTakenFocus(), I see the messagebox "Event caught"
In C++ it all gets a bit harder. My code is in an MFC dll. I created a new class CEventSink as follows:
In the header file:
class CEventSink : public CCmdTarget
{
DECLARE_DYNCREATE(CEventSink)
CEventSink(); // protected constructor used by dynamic creation
// Attributes
public:
// Operations
public:
void Connect(LPUNKNOWN lpuEventSource);
void Disconnect();
void OnTakenFocus();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CEventSink)
public:
virtual void OnFinalRelease();
//}}AFX_VIRTUAL
// Implementation
protected:
virtual ~CEventSink();
// Generated message map functions
//{{AFX_MSG(CEventSink)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
// Generated OLE dispatch map functions
//{{AFX_DISPATCH(CEventSink)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_DISPATCH
DECLARE_DISPATCH_MAP()
DECLARE_INTERFACE_MAP()
private:
DWORD m_dwEventSinkHandle;
LPUNKNOWN m_puEventSource;
};
Then the implementation in the cpp file:
IMPLEMENT_DYNCREATE(CEventSink, CCmdTarget)
CEventSink::CEventSink()
{
EnableAutomation();
m_puEventSource = NULL;
}
CEventSink::~CEventSink()
{
Disconnect();
}
void CEventSink::OnFinalRelease()
{
CCmdTarget::OnFinalRelease();
}
BEGIN_MESSAGE_MAP(CEventSink, CCmdTarget)
//{{AFX_MSG_MAP(CEventSink)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BEGIN_DISPATCH_MAP(CEventSink, CCmdTarget)
//{{AFX_DISPATCH_MAP(CEventSink)
DISP_FUNCTION_ID(CEventSink, "TakenFocus", 1, OnTakenFocus, VT_EMPTY, VTS_NONE)
//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()
// {B0FD7D1F-6686-44B3-A040-A2BF4E37DA30}
static const IID IID_IEventSink =
{ 0xb0fd7d1f, 0x6686, 0x44b3, { 0xa0, 0x40, 0xa2, 0xbf, 0x4e, 0x37, 0xda, 0x30 } };
// {0C4298D9-7CEC-46D6-A865-79204E29557D}
static const IID IID_IMyObjectEvents =
{ 0x0c4298d9, 0x7cec, 0x46d6, { 0xA8, 0x65, 0x79, 0x20, 0x4e, 0x29, 0x55, 0x7D } };
BEGIN_INTERFACE_MAP(CEventSink, CCmdTarget)
INTERFACE_PART(CEventSink, IID_IMyObjectEvents Dispatch)
END_INTERFACE_MAP()
void CEventSink::Connect(LPUNKNOWN lpuEventSource)
{
AfxConnectionAdvise(m_puEventSource = lpuEventSource, IID_IMyObjectEvents,
GetIDispatch(FALSE), FALSE, &m_dwEventSinkHandle);
}
void CEventSink::Disconnect()
{
if (m_puEventSource != NULL)
{
AfxConnectionUnadvise(m_puEventSource, IID_IMyObjectEvents,
GetIDispatch(FALSE), FALSE, m_dwEventSinkHandle);
m_puEventSource = NULL;
}
}
void CEventSink::OnTakenFocus()
{
Trace("Event caught");
}
In my startup code I create an instance of the C# object and of the event sink, and call Connect (error checking code omitted for brevity):
IMyObjectPtr oMyObject;
oMyObject.CreateInstance(clsidMyObjectInterface);
CRuntimeClass *prtcEventSink = RUNTIME_CLASS(CEventSink);
CEventSink *pSink = (CEventSink *)prtcEventSink->CreateObject();
LPUNKNOWN pUnk;
oMyObject.QueryInterface(IID_IUNKNOWN, &pUnk);
pSink->Connect(pUnknown);
The connect works fine but as soon as my C# component calls FireTakenFocus I get a .net runtime error message:
Member not found. Exception from HRESULT 0x8002003
[DISPID_E_MEMBERNOTFOUND]
(detail)
ForwardCallToInvokeMember(String MemberName, BindingFlags Flags, Object Target,
Int32[] aWrapperTypes, MessageData &msgData)
CEventSink::OnTakenFocus is never called.
Any suggestions where I'm going wrong? As I said, I'm sure the problem is on the C++ side of the fence because a VB6 app can field the event without batting an eyelid.
Keith
|
|
|
|
|
Progress, of a sort...
I changed the code to pass the IDispatch interface pointer, rather than IUnknown, into the connect call. Ie. instead of:
LPUNKNOWN pUnk;
oMyObject.QueryInterface(IID_IUNKNOWN, &pUnk);
pSink->Connect(pUnknown);
I now have:
LPDISPATCH pDispatch = Sink->GetIDispatch(FALSE);
pSink->Connect(pDispatch);
Now it no longer breaks - but it doesn't catch the event either. A break point on the first line of OnTakenFocus() is never hit.
Any ideas yet?
|
|
|
|
|
How can I hide a process form being displayed in task manager? using win32 or C++...
|
|
|
|
|
Will you please stop spamming the site every day with your stupid posts?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
if u have interest u can help ..other wise ..plz shut u r mouth..and .........
|
|
|
|
|
|