Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem initializing CFrame from CView

Status
Not open for further replies.

Vachaun22

Programmer
Oct 7, 2003
171
US
The situation:

When the program is loaded, it's to check registry settings to determine whether to automatically connect to the last used MDB file or not. If it is to connect, it connects to the file, then is to update the status bar to reflect that is either connected or disconnected.

The layout:

The main frame contains a CSplitterWnd window that contains a listbox in the left pane, and a CView in the right pane. The CView actually contains the CDatabase variable, as all the database activity occurs within the CDialogs that get loaded into the CView to reflect the selected listbox item. The CView should send a user defined message to the Main frame in order to tell the main frame to update the status bar appropriately.

The Problem:

When the application initializes, the connection to the database is established correctly. However, no matter what I try I cannot show the connected state in the status bar.

I've tried getting the handle to the main frame by using GetParent(), which never returns a valid handle to the main frame. I've tried setting a public variable through a function in the CView class when it's created through the CSplitterWnd initialization (I have to get those handles in order to pass messages for the listbox selection). This also fails when attempting to set the status bar text.

I'm apparently missing something when it comes to window creation or something. Perhaps I'm thinking about this wrong way or something. Does any have any suggestions on how to initialize a frame window object from a child object at least 2 levels beneath?
 
To add a customized pane to display your own message on the status bar, it only takes the following 6 steps. For this example, we are going to display the current time at the rightmost location of the status bar. It will be updated every 60 seconds.
First of all, add a new entry to your string table with an ID of ID_INDICATOR_TIME and a caption of '%5s '. The extra spaces are to give you a little more room in the pane so the text will not be
clipped.
Second, append ID_INDICATOR_TIME to the indicators[] array in the MainFrm.cpp file as the last entry (so that it will appear as the rightmost item on status bar).
Third, in the message map add the following:
afx_msg void OnUpdateTimeIndicator(CcmdUI *pCmdUI);
Fourth, in MainFrm.cpp, add the macro call:
ON_UPDATE_COMMAND_UI ( ID_INDICATOR_TIME, OnUpdateTimeIndicator)
Fifth, in MainFrm.cpp, create the function body:-

CMainFrame::OnUpdateTimeIndicator(CCmdUI *pCmdUI)
{
CString strStatus;

strStatus.Format(ID_INDICATOR_TIME, time);

m_wndStatusBar.SetPaneText(
m_wndStatusBar.CommandToIndex(ID_INDICATOR_TIME),
strStatus );
}

Last of all, update the variable time every 60 seconds:
#define TIME_STATUSBAR 1

class CMainFrame : public CFrameWnd
{
private:
char time[7];
}

void CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
……
SetTimer(TIME_STATUSBAR, 60000, NULL);
Memset(time, ‘\0’, 7);
……
}

void CMainFrame::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if ( nIDEvent == TIME_STATUSBAR )
{
char tempchar[20];
_strtime(tempchar); // get current time
strncpy(time, tempchar, 5); // extract only hour and minute info
}

CFrameWnd::OnTimer(nIDEvent);
}

Note that this is from
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top