A method that can be used to dynamically display information about the system, very useful (^_^)
Keyword help file information displays the original author's name, Qi Gao, and the original source of the article.
Introduction: Most of the general system help files use a static form to display the content on the interface when displaying help information. Since I am responsible for project development this time, I always feel that it is too monotonous, so in each After searching the website, I found a good control class (font display control class), so I expanded it and completed some dynamic display functions. After completion, the various help information to be displayed can be displayed dynamically like a movie. The effect is quite good. Now I will write down the production process, code and demonstration effect. I hope it will be helpful to those who have researched in this area or are looking for a good method.
At the same time, you can modify the text information displayed in the code of this article as needed.
When the main text displays the help file, I use the full-screen display method, but if I use the VIEW full-screen method, I always feel it is too ugly, so I first paste a background image on the basis of the full screen, and then load it on the background image. Just display a function. In fact, the simple method is to dynamically create a CSTATIC control directly on the background image. However, since my system involves many other functional interfaces to process, I used a dialog box. , adopt the form of a modeless dialog box, and then move it to the specified location after it is created.
Production steps:
Start VC, create a single document function based on CVIEW, and keep the rest with the default settings.
I did not proceed with the concept of full screen as in the traditional way. Instead, I moved the main frame MoveWindow to the resolution of the screen, and then removed the title bar, menu bar, toolbar, status bar, etc. to display almost a full screen effect, and then in this Just paste the background image on it. Maybe this cannot be considered a full-screen concept at all (^_^). The specific implementation steps are as follows:
Modify the APP's InitInstance() function as follows:
// The one and only window has been initialized, so show and update it.
m_pMainWnd->SetMenu(NULL);//Remove the menu
m_pMainWnd->ModifyStyle(WS_THICKFRAME|WS_CAPTION,NULL);//Modify form properties
m_pMainWnd->MoveWindow(CRect(0,0,::GetSystemMetrics(SM_CXSCREEN),
::GetSystemMetrics(SM_CYSCREEN)),TRUE);//Move the form to the resolution of the screen
m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);//No need to explain this
m_pMainWnd->UpdateWindow();
Then modify the MainFrame class member function to remove the toolbar and status bar. Modify the PreCreateWindow(CREATESTRUCT& cs) function as follows:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
FindWindow("Shell_TrayWnd",NULL)->ShowWindow(SW_HIDE);//Hide the taskbar. If not hidden, this thing will always appear at inappropriate times and affect the overall effect.
return 0;
}
The above steps hide the WINDOWS taskbar, so we must restore it when the program exits. We don’t want to see it after the program ends. Since the program needs to send a WM_CLOSE message when it exits, we can intercept the WM_CLOSE message of MainFrame, here To restore the status bar, the code is as follows:
void CMainFrame::OnClose()
{
// TODO: Add your message handler code here and/or call default
FindWindow("Shell_TrayWnd",NULL)->ShowWindow(SW_SHOW);//Restore the taskbar
CFrameWnd::OnClose();
}
At this point, we have completed the basic preparation work. The next task is to paste the background bitmap and create the displayed dialog box.
Paste the background bitmap: Load the background bitmap, map the WM_PAITN message of VIEW, then paste the background bitmap, map the WM_EARSEBKGND message at the same time, and remove the screen erasure work. Just modify the return statement to: return TRUE.
void CAboutDemoView::OnPaint()
{
// TODO: Add your message handler code here
CPaintDC dc(this); // device context for painting
HBITMAP hbitmap;
hbitmap=::LoadBitmap(::AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BACKBMP));
HDC hMenDC=::CreateCompatibleDC(NULL);
SelectObject(hMenDC,hbitmap);
::StretchBlt(dc.m_hDC,0,0,1024,768,hMenDC,0,0,1024,768,SRCCOPY);
::DeleteDC(hMenDC);
::DeleteObject(hbitmap);
// Do not call CView::OnPaint() for painting messages
}
Create a dialog box resource for displaying relevant information, modify the dialog box properties, Style->Popup, Border->None; and create a dialog box class CShowAboutDlg; then place a CSTATIC control on the dialog box and adjust its position.
Create this modeless dialog box in VIEW and display:
CShowAboutDlg *m_pAboutDlg;
CRectrect;
m_pAboutDlg = new CShowAboutDlg();
m_pAboutDlg->Create(IDD_ABOUT);
m_pAboutDlg->MoveWindow(CRect(18,18,::GetSystemMetrics(SM_CXSCREEN)-13,::GetSystemMetrics(SM_CYSCREEN)-16),TRUE); //Because the background image has a border, that position should be reserved here
m_pAboutDlg->GetClientRect(&rect);
m_pAboutDlg->m_AboutCtrl.MoveWindow(rect,TRUE);//This PIC control occupies the dialog box client area
m_pAboutDlg->ShowWindow(SW_SHOW);
The following is the file to add the font display control class. Add ZgMemDC, ZgDraw.h, ZgDraw.cpp, TitleShow.h, TitleShow.cpp, PublicClass.cpp, PublicClass.h to the project, and then add AutoFont.h and AutoFont.cpp. Needless to say, the function of this class has been introduced in the previous article. Based on the person who provided the font display control class, I modified an appropriate amount of code and made modifications to the text display, because the original class The font is not suitable for the display requirements of our current system (^_^).
Then just load and display the message in the dialog class.
Define the display CSTATIC class object TitleShow, and then add your information display content in the initialization:
****
Another step is to intercept the carriage return and ESC keys to exit the dialog box.
BOOL CShowAboutDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message == WM_KEYDOWN)
{
switch(pMsg->wParam)
{
case VK_RETURN:
return TRUE;
case VK_ESCAPE:
return TRUE;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
At this point, the basic work of the program has been completed. Compile and run your project to see the effect.
Expand