COP4226, Review Topics
These are the topics that I covered in the first half of the semester
-
Windows Messages
-
WM_LBUTTONDOWN, WN_LBUTTONUP, WM_RBUTTONDOWN
-
WM_CREATE, WM_CLOSE, WM_COMMAND
-
GDI and device independence
-
Resource based programming
-
OnDraw
-
pDC->TextOut(0, 0, "Hello, World");
-
pDC->SelectStockObject(GRAY_BRUSH);
-
pDC->Ellipse(CRect(0,20,100,120);
-
TRACE - like printf
-
Message mapping
-
afx_msg - "no-op" prototype for message map function
-
In.cpp file
BEGIN_MESSAGE_MAP
ON_WM_LBUTTONDOWN()
ON_BTN_CLICKED(IDC_OK, OnClickedOK)
END_MESSSAGE_MAP
-
In .h file
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnClickedOk();
DECLARE_MESSAGE_MAP()
-
Using member variables to save the view's state
-
Invlidate() vs. InvalidateRect()
-
CRect, CPoint, CSize and their arithmetic operators
-
Testing if a point is in a rectangle
-
Mapping Modes
-
fixed: MM_TEXT, MM_HIENGLISH, MM_LOENGLISH, MM_HIMETRIC, MM_LOMETRIC, MM_TWIPS
-
variable: MM_ISOTROPIC, MM_ANISOTROPIC
-
SetWindowExt, SetViewportExt are used to set the scale.
-
Mapping the entire client area
GetClientRect(rectClient);
pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetWindowExt(1000, 1000);
pDC->SetViewPortExt(rectClient.right, -rectClient.bottom);
pDC->SetViewPortOrg(rectClient.right / 2, rectClient.bottom / 2);
-
Converting between device and logical coordinates
-
Scroll View
-
OnInitialUpdate - set scroll parameters
-
sizeTotal, sizePage, sizeLine
-
Accepting keyboard input for scroll bars
-
WM_CHAR
-
WM_KEYDOWN
-
OnKeyDown
-
VK_HOME, VK_END, VK_UP, VK_DOWN,
-
VK_PRIOR, VK_NEXT, VK_LEFT, VK_RIGHT
-
OnVScroll, OnHScroll
-
SB_TOP, SB_BOTTOM, SB_LEFT, SB_RIGHT
-
SB_LINEUP, SB_LINEDOWN, SB_LINERIGHT, SB_LINELEFT
-
SB_PAGEUP, SB_PAGEDOWN, SB_PAGERIGHT, SB_PAGELEFT
-
GDI classes
-
CPen
-
CBrushe
-
CFont
-
CBitmap
-
CRgn
-
Selecting a GDI object into the device context
-
pDC->SelectObject(&pen);
-
pDC->SelectStockObject(GRAY_BRUSH);
-
Create GDI objects on the stack, deselect them to avoid memory leaks
-
GetDeviceCaps
-
GetTextMetrics
-
tmExternalLeading, tmHeight, tmInternalLeading
-
Device Context member functions
-
pDC->SetBkColor(RGB((255,0,0))
-
pDC->SetTextColor(RGB((255,0,255))
-
pDC->Rectangle(rectTemp)
-
pDC->GetTextExtent(strText)
-
Dialogs: modal vs modeless
-
Control classes in dialogs
-
CEdit
-
CButton
-
CComboBox
-
CListBox
-
CSScrollBar
-
CStatic
-
Create a class for a dialog
-
Create member variables for each control
-
Create message maps for buttons
-
Special Initialization inOnInitDialog
-
Insert list box items
CListBox* pLB = (CListBox*) GetDlgItem(IDC_LISTBOX);
pLB->InsertString9-1, "Documentation");
-
Call the base class OnInitDialog after initialization
-
Connecting the view and the dialog
-
dialog member variable in the view
-
UpdateData(TRUE) to get dat from controls to the class
-
UpdateData(FALSE) to get the data from the class to the controls
-
DoModal does both UpdateData calls
-
DoDataExchange
-
Preventing ENTER and ESC to close the dialog
-
Identifying controls
-
GetDlgItem(IDC_DATA)
-
pWnd->GetDlgCtrlID()
-
Setting the background color of a control
-
OnCtlColor
-
HBRUSH m_bYellow
-
m_bYellow = CreateSolidBrush(RGB(0,255,255));
-
return a brush from the function
-
CFontDialog, CFileDialog: how to call them.
-
User defined messages
-
PostMessage - on queue
-
SendMessage - immediate
-
Add message mapping
-
Begin(.cpp): ON_MESSAGE(WM_GOODBYE, OnGoodbye)
-
Declare (.h): afx_msg LRESULT OnGoodbye(WPARAM wParam, LPARAM lParam)
-
Modeless Dialog
-
Overload constructor with pointer to view, so dialog knows which view gets
the message
-
Overload the Create function. Call the base class Create with the IDD of
the Dialog
-
DestroyWindow to kill the dialog
-
Override the OnOK and OnCancel handlers to post the message to the view
-
Create dialog in constructor, delete it in the destructor
-
Bitmaps
-
Bitmaps are like other GDI objects
-
Display surface is bitmap associated with device context
-
Must copy other bitmaps into the display bitmap
Create bitmap: CBitmap bitmap;
Create dc: CDC dcMemory;
Load bitmap: bitmap.LoadBitmap(IDB_REDBLOCKS);
Select bitmap: dcMemory.SelectObject(&bitmap);
Copy bitmap: pDC->BitBlt(100, 100, 54, 96, &dcMemory, 0, 0,
SRCCOPY);
-
To map pixels exaclty, use StretchBlt
CSize(54, 96);
pDC->DPtoLP(&size);
pDC->StretchBlt(100, 100, size.cx, -size.cy, &dcMemory, 0, 0, 54,
96, SRCCOPY);