|
Actually, you don't need to typecast when you call CPtrArray::Add() method. However, you're right, you need to do that when you get the struct back using GetAt() method.
If typecasting bothers you too much, you can instead use MFC's template class CTypedPtrArray (declared in afxtempl.h). In this case, you don't need to typecast while calling GetAt() method. Here is how this works:
CTypedPtrArray < CPtrArray, MyStruct* > m_Array;
m_Array.Add(&struct1);
m_Array.Add(&struct2);
MyStruct* pStruct1 = m_Array.GetAt(0);
MyStruct* pStruct2 = m_Array.GetAt(1);
// Fazlul
Get RadVC today! Play RAD in VC++
http://www.capitolsoft.com
|
|
|
|
|
It doesn't *worry* me, it's just plain ugly IMHO. But I'm an STL zealot, so I'm likely to take a dim view of MFC containers, I guess....
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
Yes, it's kinda *religious* to talk about the relative advantages (or disadvantages) of using container classes supported by MFC and STL.
I guess, we all showed the original poster various ways of doing the same thing. It's up to him to decide which way to go.
Cheers.
// Fazlul
Get RadVC today! Play RAD in VC++
http://www.capitolsoft.com
|
|
|
|
|
How can I use a Timer in a CListView?
(With the Timer I want to update the view)
|
|
|
|
|
This should be helpful:
CWnd::SetTimer
UINT SetTimer( UINT nIDEvent, UINT nElapse, void (CALLBACK EXPORT* lpfnTimer)(HWND, UINT, UINT, DWORD) );
Return Value
The timer identifier of the new timer if the function is successful. An application passes this value to the KillTimer member function to kill the timer. Nonzero if successful; otherwise 0.
Parameters
nIDEvent
Specifies a nonzero timer identifier.
nElapse
Specifies the time-out value, in milliseconds.
lpfnTimer
Specifies the address of the application-supplied TimerProc callback function that processes the WM_TIMER messages. If this parameter is NULL, the WM_TIMER messages are placed in the application’s message queue and handled by the CWnd object.
Remarks
Installs a system timer. A time-out value is specified, and every time a time-out occurs, the system posts aWM_TIMER message to the installing application’s message queue or passes the message to an application-defined TimerProc callback function.
The lpfnTimer callback function need not be named TimerProc, but it must be defined as follows:
void CALLBACK EXPORT TimerProc(
HWND hWnd, // handle of CWnd that called SetTimer
UINT nMsg, // WM_TIMER
UINT nIDEvent // timer identification
DWORD dwTime // system time
);
Timers are a limited global resource; therefore it is important that an application check the value returned by the SetTimer member function to verify that a timer is actually available.
Example
// This example shows how to use CWnd::SetTimer, CWnd::KillTimer, and how to handle WM_TIMER messages. A timer is set up to send a WM_TIMER message to the main frame window every 2 seconds in OnStartTimer(). OnStopTimer will stop the timer by calling CWnd::KillTimer. OnTimer was set up through class wizard to handle WM_TIMER messages for the main frame window. In this example the PC speaker will beep every 2 seconds.
void CMainFrame::OnStartTimer()
{
m_nTimer = SetTimer(1, 2000, 0);
}
void CMainFrame::OnStopTimer()
{
KillTimer(m_nTimer);
}
void CMainFrame::OnTimer(UINT nIDEvent)
{
MessageBeep(0xFFFFFFFF); // Beep
// Call base class handler.
CMDIFrameWnd::OnTimer(nIDEvent);
}
Andres Manggini.
Buenos Aires - Argentina.
|
|
|
|
|
Hello,
I have the following code to make a push button check box, and it still draws the button as a check box.
// Create an check box push button.
m_blah4.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_CHECKBOX|BS_PUSHBUTTON, CRect(10,100,100,130), this, MY_BTN4);
Does anyone have any suggestions, as to what I am doing wrong?
Thanks in advance!!
|
|
|
|
|
|
Excellant that is what I needed!!!
Thanks for your help!!!
|
|
|
|
|
Hello all,
Here is my final solution to my original question:
// Create an auto check box.
m_blah4.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_PUSHLIKE|BS_AUTOCHECKBOX, CRect(10,100,100,130), this, MY_BTN4);
Now the button works like the push button check box in the resource.
Thanks to all of you who helped me!!
|
|
|
|
|
When I do
CSocket sock;
sock.Connect(place_that_doesn't_exist);
Connect waits like half a minute before returning. I could do some kind of multithreading or overlapped IO completion ports (neither of which I have any experience with) but it would work for me just to have it return after a second or two if it can't connect. I was thinking along the lines of something like
sock.SetTimeout(500_milliseconds);
or
setsockopt(sock.m_socket, SO_TIMEOUT, 500_milliseconds);
Any suggestions? Thanks!
- Alex Griffing
|
|
|
|
|
I am having trouble with overriding CWndClassInfo in ATL/WTL. I am working to set the cursor for a CListViewCtrl derived class (ListCtrl) to be a cross (IDC_CROSS) and remove the CS_HREDRAW & CS_VREDRAW to eliminate the flicker during resizing (Q183210). I thought I made the appropriate changes (see below) yet the view does not display the cross cursor and the flicker is still present. What else is needed to invoke the ListCtrl::GetWndClassInfo()? Are there examples of what I am trying to do in ATL?
// ListCtrl.h
class ListCtrl : public CWindowImpl<listctrl, clistviewctrl="">
{
public:
ListCtrl();
virtual ~ListCtrl();
BEGIN_MSG_MAP(ListCtrl)
MESSAGE_HANDLER(WM_PAINT, OnPaint)
END_MSG_MAP()
public:
LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/,
BOOL& /*bHandled*/);
static CWndClassInfo& GetWndClassInfo()
{
static CWndClassInfo wc = {
{
sizeof(WNDCLASSEX),
0,
StartWindowProc,
0, 0, NULL, NULL, NULL, (HBRUSH)(COLOR_WINDOW+1), NULL,
_T("ListCtrl"), NULL
},
NULL, NULL, IDC_CROSS, TRUE, 0, _T("")
};
return wc;
};
};
// Status.cpp
Status::Status()
{
list_view = new ListCtrl;
}
Status::~Status()
{
if (list_view)
delete list_view;
}
HRESULT Status::open(const HWND hWnd)
{
if (list_view) {
RECT rect;
::GetClientRect(hWnd, &rect);
HWND h = list_view->Create(hWnd, rect, _T("ListCtrl"),
WS_CHILD |
WS_VISIBLE |
WS_CLIPSIBLINGS |
WS_CLIPCHILDREN |
LVS_REPORT,
WS_EX_CLIENTEDGE);
return S_OK;
}
|
|
|
|
|
How can I access the information about my display? I want to get the HxW pixel settings (i.e. 2048x768) so that I can place my dialogs on the screen (desktop) with minimal overlap.
Also, I have a dual monitor setup and my users may/may not have the same - would this matter in the information retrieved?
Ad-THANKS-vance
Johnny
|
|
|
|
|
I just can tell you how to get the witdh and height of your screen:
int width = GetSystemMetrics(SM_CXSCREEN);
int height = GetSystemMetrics(SM_CYSCREEN);
regards
|
|
|
|
|
How I can disable the item in list control.
Thanks!
|
|
|
|
|
Hello, the codegurus around the world.;)
I don't understand cleary what means "disable the item".
But, I guess that you want to make the mouse click on some itme on the list disable?
Maybe, after you subclass CMyListCtrl, and create struct value like ItemProperties,
and keep the record of which index item will be disabled (kill the mouse clicking).
If you disable one all row, colum or one special cell, these are different stories and
you need more codes to do these.
You also add the code to show how this item is disable, and must redraw the index disabled.
But, this kind of the code seems to be very interesting.
If someone creates this kind of the control, please post your new class to Codeproject.
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
Hi
I want to create a window that will stay on top of the screen. It should be as width as the screen and as height as the taskbar (may have a constant height). The user shouldn't be able to move the bar.
How should I start? Do I need to create deskband, or does a simple dialog based app teh same job?
Any suggestions or links are greatly appreciated
|
|
|
|
|
What you want is an app bar. Look up "application desktop toolbars" in MSDN.
--Mike--
http://home.inreach.com/mdunn/
"Listen you footwarriors, can you hold down a bit with the firing? I've just got three impromptu weddings breaking out behind me!" -- Arthur Dent
your with and
|
|
|
|
|
A dialog based app will work. Just use a CDialog without a caption bar.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
|
I am looking for a way to use the TRACE macros without adding MFC to my project. Does anyone have macro definitions to do this?
But if you do wrong, be afraid, for [the one in authority] does not bear the sword for nothing. He is God's servant, an agent of Wrath to bring punishment to the wrongdoer -- Romans 13:4
|
|
|
|
|
void RDTrace(const char* fmt, ...)
{
#ifdef _DEBUG
char buffer[1024];
va_list argptr;
va_start(argptr, fmt);
_vsnprintf(buffer, 1024, fmt, argptr);
va_end(argptr);
OutputDebugString(buffer);
#endif
}
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
Thanks Chris, I just about got this far, but where is the OutputDebugString function declared?
I'm currently using <fstream> to dump my TRACE output to a file, but I would prefer it to come into the IDE so I can see it while it runs.
But if you do wrong, be afraid, for [the one in authority] does not bear the sword for nothing. He is God's servant, an agent of Wrath to bring punishment to the wrongdoer -- Romans 13:4
|
|
|
|
|
OutputDebugString is a Win32 API function. #include Windows.h to get it. (it's actually in winbase.h).
it's what TRACE ends up calling. ODS will even dump stuff in release mode, hence the #ifdef _DEBUG.
you can even use the lovely WinDBG32 app to capture these message outside of the IDE.
-c
------------------------------
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
Thanks, I gave it a try and it worked. This is the first time I've actually had a question. It's great the speed with which this community answers questions.
But if you do wrong, be afraid, for [the one in authority] does not bear the sword for nothing. He is God's servant, an agent of Wrath to bring punishment to the wrongdoer -- Romans 13:4
|
|
|
|
|
You can just grab the code for AfxTrace() from the MFC\src directory and copy it to your program, too. There's also ATLTRACE if you are using ATL.
--Mike--
http://home.inreach.com/mdunn/
"Listen you footwarriors, can you hold down a bit with the firing? I've just got three impromptu weddings breaking out behind me!" -- Arthur Dent
your with and
|
|
|
|
|