|
Hi, I have a MDI MFC application and I would like to tell it to create a new empty document (basically the same as going to File->New). Can anyone tell me what the function call is to do this?
Thanks!
|
|
|
|
|
The Framework calls OnNewDocument() so unless calling this function directly asserts (I've never tried it) that should work.
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
If you can get a pointer to the document template you can call:
pDocTemplate->OpenDocumentFile(NULL) ;
Doc templates can be got through the m_pDocManager pointer of the CWinApp object. You need to iterate it using a POSITION object. Or, if you have an existing document object of the type you want to create, you can call GetDocTemplate() on your document object to get a pointer to it.
Roger Allen
Sonork 100.10016
If I'm not breathing, I'm either dead or holding my breath.
A fool jabbers, while a wise man listens. But is he so wise to listen to the fool?
Please step to the rear of the car and make room for more victims. - John Simmons the Outlaw programmer, 1st Feb 2002, in the lounge
|
|
|
|
|
I am trying to color the square box of the check button control.
I have had no luck finding code to do it. I would appreciate any help.
thanks.
Jyoti
|
|
|
|
|
You could use DrawFrameControl() or Draw3dRect().
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Can you give me some sample code if you have it.
I wasn't succesful using DrawFrameControl function.
thanks.
Jyoti
|
|
|
|
|
CDC dc = GetDC();
CRect rect = {10, 10, 100, 100};
dc.DrawFrameControl(&rect, DFC_BUTTON, DFCS_BUTTONPUSH);
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Hi
I've often seen programs (in most cases c programs) that use one or more of the following operators:
<<, >>
It is called bit-shifting. I saw an ID3-tagger program that uses this commands as well.
Now my question:
What does "bit-shifting" actually do and what is it good for?
Any articles or explanation is greatly appreciated
regards
Gregor
modified 12-Sep-18 21:01pm.
|
|
|
|
|
it shifts the bits to the left (<< ) or the right (>>).
if you have a BYTE x equal to 4, it looks like this in binary: 00000100. if you shift this to the left 2 bits, you get 00010000 (16).
it's used when you need to get at the individual bits in a value. i use it all the time in image processing when the size of the pixels is not an even multiple of 8 (like in a 1 or 4 bits per pixel image).
-c
|
|
|
|
|
It actually shifts the bits in the number. It is sometimes used for quick multiplication or division. Here are some examples :
<br />
<br />
int x = 5 << 3;<br />
<br />
in binary, 5 is 00000101<br />
shifted left 3 is 00101000<br />
<br />
This has the effect multiplying by 8.<br />
<br />
Another one :<br />
<br />
int y = 40 >> 3;<br />
<br />
in binary 40 is 00101000<br />
shifted right 2 is 00000101<br />
<br />
This is dividing by 8<br />
<br />
|
|
|
|
|
Erm, well, could you please explain what bit-shifting is used for in this case:
fprintf( outfile, "%d.%d.%d.%d:%hu\n",
(ipaddr>>24)&0xff, (ipaddr>>16)&0xff,
(ipaddr>>8)&0xff, ipaddr&0xff, port);
This is a code snippet of a tool that queries server and displays there IPs. This is actually what the above code does.
But I have no idea what it really does
maybe you could explain to me
idaddr is declared as
unsigned int ipaddr= ntohl(server->ipaddr);
And one last question:
How do I make keywords appear in red color in this message board?
modified 12-Sep-18 21:01pm.
|
|
|
|
|
An unsigned int consists of 32 bits, so you can see it as a packed array of 8-bit values --precisely what one needs to store a numeric IP address a.b.c.d. ipaddr&0xFF (or-ing with the binary number 0000 0000 0000 1111) yields the value of d. Shifting the appropriate number of bits and repeating the or-ing trick yields th remaining values.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Arrgh... This time you were faster.
I vote pro drink
|
|
|
|
|
Arrgh... This time you were faster.
the pretty formatting notwithstanding
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Gregor S. wrote:
fprintf( outfile, "%d.%d.%d.%d:%hu\n", (ipaddr>>24)&0xff, (ipaddr>>16)&0xff, (ipaddr>>8)&0xff, ipaddr&0xff, port);
This will split your 4-byte number ipaddr into individual bytes and print them.
I vote pro drink
|
|
|
|
|
Thanks for your example.
I finally understand most of this memory manipulation stuff now.
11111111 11111111 11111111 11111111
11000000 10101000 00000000 00000001
<<24:
[00000000 00000000 00000000] 11000000
<<16:
[00000000 00000000 00000000] 10101000
<<8:
[00000000 00000000 00000000] 00000000
<<0 (not shifted):
[00000000 00000000 00000000] 00000001
To get keywords to appear in red, enclose them in <span style="color:red"> and </span>
|
|
|
|
|
Hello,
Can anyone tell me why I get this error?
error:
error C2243: 'static_cast' : conversion from 'class IStopwatch *' to 'struct IUnknown *' exists, but is inaccessible
Here is the code:
<pre>
HRESULT __stdcall CStopwatch::QueryInterface(REFIID riid, void **ppvObject)
{
HRESULT hr = S_OK;
if(riid == IID_IUnknown)
*ppvObject = static_cast<IUnknown*>(static_cast<IStopwatch*>(this)); <-- error
else if (riid == IID_IStopwatch)
*ppvObject = static_cast<IStopwatch*>(this);
else
{
ppvObject = NULL;
hr = E_NOINTERFACE;
}
if(SUCCEEDED(hr))
(static_cast<IUnknown*>(*ppvObject))->AddRef();
return hr;
}
</pre>
Here is my header:
<pre>
#if !defined(AFX_STOPWATCH_H__CF2EC9CF_CCAA_4708_8320_0B5A054E3876__INCLUDED_)
#define AFX_STOPWATCH_H__CF2EC9CF_CCAA_4708_8320_0B5A054E3876__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <windows.h>
class IStopwatch : IUnknown
{
public:
//IStopwatch specific functions
virtual HRESULT __stdcall Start() = 0;
virtual HRESULT __stdcall ElapsedTime(float *Time) = 0;
};
class CStopwatch : public IStopwatch
{
public:
CStopwatch();
virtual ~CStopwatch();
private:
// The frequency of the counter
// returned by QueryPerformanceCounter()
LARGE_INTEGER m_nFrequency;
// The counter value when the start method was last called.
LARGE_INTEGER m_nStartTime;
public:
// IUnknown methods
HRESULT __stdcall QueryInterface(REFIID riid, void** ppvObject);
unsigned long __stdcall AddRef();
unsigned long __stdcall Release();
// IStopwatch specific functions
HRESULT __stdcall Start();
HRESULT __stdcall ElapsedTime(float *Time);
};
#endif // !defined(AFX_STOPWATCH_H__CF2EC9CF_CCAA_4708_8320_0B5A054E3876__INCLUDED_)
</pre>
Thanks,
Rob
|
|
|
|
|
IStopwatch inherits as private from IUnknown. Inherit public from IUnknown ( IStopwatch : public IUnknown )
|
|
|
|
|
Thanks! dumb mistake
Rob
|
|
|
|
|
How to PostMessage "NM_DBLCLK" to a Clistctrl ?
Thanx
|
|
|
|
|
Notification messages are sent by controls to their parent window. To simulate a double-click (I assume that's what you want to do), you should post a WM_LBUTTONDBLCLK message to the list control.
/ravi
"There is always one more bug..."
ravib@ravib.com
http://www.ravib.com
|
|
|
|
|
A small example will be great..
|
|
|
|
|
To send a message use
// see help of PostMessage for parameter options
#define WM_GENNIE_LEARN_MODE 2000 // use any id as you desire
PostMessage(WM_GENNIE_LEARN_MODE);
Now in the message map of the class where you want the message to be captured (namely the parent class in your case) make an entry in the BEGIN_MESSAGE_MAP section as given below
IMPLEMENT_DYNCREATE(..., ...)
BEGIN_MESSAGE_MAP(... , ...)
//{{AFX_MSG_MAP(CDict1View)
ON_MESSAGE(WM_GENNIE_LEARN_MODE,OnGennieLearnMode)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
Now declare the handler function, as given below
//{{AFX_MSG(CDict1View)
afx_msg LRESULT OnGennieLearnMode(WPARAM wParam, LPARAM lParam);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
and define it as
LRESULT YourParentClassName::OnGennieLearnMode(WPARAM wParam, LPARAM lParam)
{
// blah blah blah ...
return ...;
}
/**********************/
The above code will send a message WM_GENNIE_LEARN_MODE to the parent window where it would be handled by the function OnGennieLearnMode(). In your case you would sen the DBLCLICK message, and handle it in your own handler function.
hope it helps,
-cheers
-kashif manzoor
peace to all
|
|
|
|
|
|
Hi All,
I wonder if any of you guys can help - and I certainly need some now!! For our software, I have written a grid control that looks like the MS Outlook grid control. However, in this release of the software I have been asked to add Outlook style grouping. I am finding the task harder than I thought and am now very worried about the looming deadline.
Does anyone know of any code for grouping data (each row in the grid is a safearray of variants). Given certain grouping criteria (i.e. group by column 2, then by 3), I need to get the data into a suitable datatype and then render it on the screen. Once data is in the datatype, I need to be able to iterate through it. I would be very, very grateful if anyone could point me to any example code of doing this or something similar to this.
Thanks,
Mike.
|
|
|
|