|
Here is the code I use in one of my applications that has a tray icon:
In my header fo MyDlg class I have declared
private:
NOTIFYICONDATA m_notifyIconData;
I have also added the declaration for OnTrayNotification after the MFC stuff
// Generated message map functions
//{{AFX_MSG(CAVCDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnDestroy();
afx_msg void OnPaint();
// ... other MFC wizard junk
//}}AFX_MSG
// Our handler for the tray WM_ message
afx_msg LRESULT OnTrayNotification(WPARAM nID, LPARAM lParam);
DECLARE_MESSAGE_MAP()
At the top of my Dlg cpp file I declare a WM_ message
static UINT WM_MY_TRAY_NOTIFICATION = RegisterWindowMessage("MyTrayNotification");
// In my message map I use ON_REGISTERED_MESSAGE to handle
// the WM_MY_TRAY_NOTIFICATION instead of ON_MESSAGE
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CAVCDlg)
ON_WM_SYSCOMMAND()
ON_WM_DESTROY()
ON_WM_PAINT()
// ... other wizard junk
//}}AFX_MSG_MAP
// This should be delcared outside the wizard section
ON_REGISTERED_MESSAGE(WM_MY_TRAY_NOTIFICATION,OnTrayNotification)
END_MESSAGE_MAP()
// Link up the tray to the MyDlg in OnInitDlg()
BOOL CMyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//...
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
m_notifyIconData.cbSize = sizeof(m_notifyIconData);
m_notifyIconData.hWnd = this->m_hWnd;
m_notifyIconData.uID = WM_MY_TRAY_NOTIFICATION;
m_notifyIconData.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
m_notifyIconData.uCallbackMessage = WM_MY_TRAY_NOTIFICATION;
m_notifyIconData.hIcon = m_hIcon;
lstrcpy( m_notifyIconData.szTip, _T("Hello") );
Shell_NotifyIcon( NIM_ADD, &m_notifyIconData );
return TRUE;
}
// We need to destroy what we created...
void CMyDlg::OnDestroy()
{
m_notifyIconData.uFlags = NIF_ICON;
Shell_NotifyIcon( NIM_DELETE, &m_notifyIconData );
CDialog::OnDestroy();
}
LRESULT CMyDlg::OnTrayNotification( WPARAM uID, LPARAM lEvent )
{
if ( lEvent == WM_LBUTTONDBLCLK )
{
AfxMessageBox("Left Button Double-Click");
}
else if ( lEvent == WM_RBUTTONUP )
{
AfxMessageBox("Right Button Up");
}
return 0;
}
Hope all this rambling on help you some
If you still have questions email me and I will send you this test app zipped up.
Roger Stewart
rstewart27104@yahoo.com
|
|
|
|
|
|
Hi folks,
more or less simple question.
I am using the mfc-odbc api to get information about a database table. Currently I am using SQLDescribeCol(...). But I need more information, because I will dynamically build a new table. This table should consist of columns from other tables. so I need all information to create a new CREATE TABLE sql statement.
e.g. I will need the varchar size or the columns default parameter.
Can anyone help me ?
many thanx
bye
murphman
|
|
|
|
|
|
|
Use it any place that your would normally use the c style cast operator.
LPARAM lParam
LPCSTR szString = (LPCSTR)lParam;
LPCSTR szString = reinterpret_cast<lpcstr>(lParam);
However, if you can it is alot safer to use static_cast, because the compiler will check to make sure that there are define rules to cast from one type to another.
When you use reinterpret_cast, you are basically saying to the compiler:
SHUT UP, I know what I am doing, it is ok to treat object of type A as a type B object.
|
|
|
|
|
|
syntax for reinterpret_cast:
reinterpret_cast < type-id > ( expression )
example:
CFoo oFoo;
CFoo* poFoo = &oFoo;
CBar* poBar = reinterpret_cast<cbar*>(poFoo);
Caution should be used, because you are bypassing all of the compiler's safeguards against type conflicts, etc.
Sef Tarbell
"A mind all logic is like a knife all blade, it makes the hand bleed that wields it." --Rabindranath Tagore
|
|
|
|
|
syntax for reinterpret_cast:
reinterpret_cast < type-id > ( expression )
example:
CFoo oFoo;
CFoo* poFoo = &oFoo;
CBar* poBar = reinterpret_cast<CBar*>(poFoo);
Caution should be used, because you are bypassing all of the compiler's safeguards against type conflicts, etc.
Sef Tarbell
"A mind all logic is like a knife all blade, it makes the hand bleed that wields it." --Rabindranath Tagore
|
|
|
|
|
I am a fairly new programmer, i have been looking at MFC, and being the young person that I am would like to have a try at the art of game programming. From what i gather games can be made in both OpenGL and DirectX, but i do not know which is the best to use, and where i can learn about the programming techniques.
Could someone tell please inform me.
==================================================
When Your Mind Wonders...Where Does It Go???
|
|
|
|
|
As of DX8 I believe DX is easier and more powerful, a new OpenGL standard is on the way. OpenGl is cross platform though, if that is of any use to you.
I'd start with DX and then learn GL later if you want to, although the nehe site has excellent OpenGL tutorials that are free, so you may chose GL as a matter of economics.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
|
|
|
|
|
OpenGL is available for many platforms where DirectX is Windows only.
Jeremy L. Falcon
"The One Who Said, 'The One Who Said...'"
|
|
|
|
|
Is there anyway to do this ?
Ex.:
I´ve a function
HRESULT blah(BSTR sString, BSTR* sResult)
sString is [in] and sResult is [out, retval]
I need to allocate a new BSTR in the second parameter... maybe subclassing the pointer that sResult has and letting the CComBSTR do the dirty work ? Any guesses ?
Mauricio Ritter - Brazil
Sonorking now: 100.13560 Trank
|
|
|
|
|
|
Hi !
Here is my problem :
I've created and connected a CClntSocket* object (derived from CSocket) in my app.
And I want to use this socket to send & receive data in a modeless dialog box.
How can I "pass" this socket to my modeless dialog box ?
Thanks in advance for any kind of advice !!
Laurent
|
|
|
|
|
Augment the dialog constructor with an additional CCIntSocket * parameter. Depending on what part (the dialog or the code using it) takes responsibility for the cleanup of this CCIntSocket * , you'll delete it in one place or the other.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks ! but it is already done
In fact, when I "start" the modeless dialog by :
AfxBeginThread( RUNTIME_CLASS(CMyDlgThread) )
there's no way I can pass parameters...
Am I missing something ?
|
|
|
|
|
Ummm... So, you're launching a separate thread to maintain that modeless dialog of yours, right? If so, then you can use the CREATE_SUSPEND flag when creating the thread, pass the socket pointer to some member variable in CMyDlgThread designed to that purpose and then call CWinThread::ResumeThread to start the actual execution of the dialog.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
The trick works ! Thank you !
Unfortunately I get an assertion failure on "sockcore.cpp", maybe a socket cannot be reused in another thread ?
Any idea ?
|
|
|
|
|
If you could post the actual assertion and the context where is signaled, maybe we'd be avle to figure out ehat's going wrong.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
You'll note that I achieved this successfully the other day. I came across all sorts of problems:
It seems that when you create a socket, various message maps and macros and stuff are set up internally. When these fire off, all sorts of odd stuff happens.
What you need to do it this:
1. Detach() your socket to get a SOCKET handle
2. Start your (User Interface type) thread, with THREAD_SUSPENDED
3. Tell you UI Thread object what the SOCKET handle is. ie, use a public member variable.
4. Resume your thread.
5. In your threads init function, create a new CYourSocket object, and Attach() it to the socket handle.
that worked for me.
jon
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
In fact I forgot to do the Detach/Attach procedure...
Now everything is working fine !
Thanks for your help !
|
|
|
|
|
Wow, second time you've answered that in as many days!
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
Yeah, I'm the CREATE_SUSPEND man
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I'm writing a complex C program with VC++ 6.0. This program is very low-level (OS-like), and will actually run on a non-PC device. So the program itself must be in portable C and cannot use any Windows-specific features or APIs. I’m doing primary development and simulation with VC++/Windows because it is a much more convenient IDE than what is available for the native machine.
Examining the program's state with the standard VC++ debugging features (local/global variables, memory window) is proving to be very tedious. I need some aids to help me display (and hopefully modify) the program-specific state in a more human-readable format.
I've been trying to learn about all the VC++ features that I never knew existed. It seems that some combination of Visual Basic Macros, Debugger Add-ins, and/or Visual Studio Automation Interface might be able to help me. But I need some advice from those who know more about these facilities.
The kinds of things I need to display are the program’s private internal:
- Heaps
- Stacks
- Data structures
- Object references
- Object contents
- Memory maps
- Configuration data
- Trace buffers
Initially, I would be happy with some simple display-only capability, such as just writing text to the console or debug output window. While I could do this with internal printf and trace statements, I’d prefer to do it “on demand”, for example, by invoking a VC++ Debugger VB macro.
Ideally, what I want is to be able to add some menu items and/or icons to the Debugger Toolbar. Selecting these items will launch custom code (written by me) which will display in a nicely formatted way my program's custom internal state. The next step beyond that is to display groups of items in their own custom Debugger GUI windows, and allow me to modify program data in those windows.
I realize that this is a lot of work, and amounts to writing pieces of my own custom symbolic debugger. But it might be worth it to me in the long run, especially when I realize that Visual Studio seems to be designed to support this kind of thing.
So ... I’d appreciate it if someone can point me to:
- Architectural documents
- "How to" documents
- API reference documents
- Sample code
that will help me in my quest.
Thanks a bunch!
Mitch Butler
|
|
|
|