11.04.2014 Views

Advanced MFC Programming

Advanced MFC Programming

Advanced MFC Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 13. Adding Special Features to Application<br />

);<br />

MAPPING_PROJECT<br />

}<br />

if(hMapFile != NULL)<br />

{<br />

lpMapAddress=(LPSTR)MapViewOfFile<br />

(<br />

hMapFile,<br />

FILE_MAP_ALL_ACCESS,<br />

0,<br />

0,<br />

0<br />

);<br />

if(lpMapAddress != NULL)<br />

{<br />

szText=lpMapAddress;<br />

}<br />

CEdit &editCtrl=((CEditView *)GetActiveView())->GetEditCtrl();<br />

editCtrl.SetSel(0, -1);<br />

editCtrl.ReplaceSel(szText);<br />

}<br />

return (LONG)TRUE;<br />

There are other methods for sharing memory among different processes, such as DDE and OLE.<br />

Comparing to the two methods, file mapping method is relatively simple and easy to implement.<br />

Summary<br />

1) Before a window is created, we must stuff a WNDCLASS type object, register the window class name, and<br />

use this name to create the window. Class WNDCLASS contains useful information about the window<br />

such as mainframe menu, default icon, default cursor shape, brush that will be used to erase the<br />

background, and the window class name.<br />

1) To implement one-instance application, we need to register our own window class name, and override<br />

function CWnd::PreCreateWindow(…). Before the window is created, we need to replace the default<br />

window class name with the new one. By doing this, we can implement one-instance application by<br />

searching for registered window class name: before registering the window class, we can check if there<br />

already exists a window that has the same class name. If so, the application simply exits.<br />

1) We can call function CWnd::FindWindow(…) to find out a window with a specific class name or<br />

window name in the system.<br />

1) The document/view structure is implemented by class CSingleDocTemplate or CMutiDocTemplate. If<br />

we want to create an application that does not use document/view structure, we need to eliminate the<br />

procedure of creating CSingleDocTemplate or CMutiDocTemplate type object and call function<br />

CWnd::Create(…) to create the mainframe window by ourselves.<br />

1) We can create several CMultiDocTemplate type objects in an application to let it support multiple<br />

views or multiple documents.<br />

1) Caption bar and window frame belong to non-client area. To paint non-client area, we need to handle<br />

messages WM_NCPAINT and WM_NCACTIVATE.<br />

1) To create a window with transparent background, we need to specify style WS_EX_TRANSPARENT while<br />

creating the window.<br />

1) An application can save its states in the system registry by calling function<br />

CWinApp::SetRegistryKey(…). The information can be saved and loaded by calling the following<br />

functions: CWinApp::WriteProfileInt(…), CWinApp::WriteProfileString(…), CWinApp::<br />

GetProfileInt(…)., CWinApp::GetProfileString(…).<br />

1) To exchange user defined messages between two different processes, we must use function<br />

::RegisterWindowMessage(…) to register the messages.<br />

1) Calling function CWnd::SetWindowPos(…) using parameter CWnd::wndTopMost will make a window<br />

always stay on top of any other window.<br />

426

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!