Windows API Tutorials

Здесь есть возможность читать онлайн «Windows API Tutorials» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Жанр: Программирование, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

Windows API Tutorials: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Windows API Tutorials»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

Windows API Tutorials — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Windows API Tutorials», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

WinClassMaker splitterClass (WndProcSplitter, "RsSplitterClass", hInst);

splitterClass.SetSysCursor (IDC_SIZEWE);

splitterClass.SetBgSysColor (COLOR_3DFACE);

splitterClass.Register ();

}

void Splitter::MakeWindow(HWnd & hwndSplitter, HWnd hwndParent, int childId) {

ChildWinMaker splitterMaker ("RsSplitterClass", hwndParent, childId);

splitterMaker.Create ();

hwndSplitter.Init (splitterMaker);

splitterMaker.Show ();

}

The mouse cursor, IDC_SIZEWE, that we associate with the splitter class is the standard Size-West-East double arrow. We also set the background brush to COLOR_3DFACE.

The splitter's window procedure deals with splitter's creation/destruction, painting and mouse dragging.

LRESULT CALLBACK WndProcSplitter (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {

SplitController * pCtrl = GetWinLong (hwnd);

switch (message) {

case WM_CREATE:

try {

pCtrl = new SplitController (hwnd, reinterpret_cast(lParam));

SetWinLong (hwnd, pCtrl);

}

catch (char const * msg) {

MessageBox (hwnd, msg, "Initialization", MB_ICONEXCLAMATION | MB_OK);

return -1;

}

catch (...) {

MessageBox (hwnd, "Unknown Error", "Initialization", MB_ICONEXCLAMATION | MB_OK);

return -1;

}

return 0;

case WM_SIZE:

pCtrl->Size (LOWORD(lParam), HIWORD(lParam));

return 0;

case WM_PAINT:

pCtrl->Paint ();

return 0;

case WM_LBUTTONDOWN:

pCtrl->LButtonDown (MAKEPOINTS (lParam));

return 0;

case WM_LBUTTONUP:

pCtrl->LButtonUp (MAKEPOINTS (lParam));

return 0;

case WM_MOUSEMOVE:

if (wParam & MK_LBUTTON) pCtrl->LButtonDrag (MAKEPOINTS (lParam));

return 0;

case WM_CAPTURECHANGED:

pCtrl->CaptureChanged ();

return 0;

case WM_DESTROY:

SetWinLong (hwnd, 0);

delete pCtrl;

return 0;

}

return ::DefWindowProc (hwnd, message, wParam, lParam);

}

This is all pretty much standard code. The details, as usual, are in the controller's methods. The constructor is very simple.

SplitController::SplitController (HWND hwnd, CREATESTRUCT * pCreat) : _hwnd (hwnd), _hwndParent (pCreat->hwndParent) {}

Painting is more interesting. We have to imitate Windows 2.5-dimensional effects. We do it with a carfuly chosen selection of pens.

class Pens3d {

public:

Pens3d ();

Pen & Hilight () {

return _penHilight;

}

Pen & Light () {

return _penLight;

}

Pen & Shadow () {

return _penShadow;

}

Pen & DkShadow () {

return _penDkShadow;

}

private:

Pen _penHilight;

Pen _penLight;

Pen _penShadow;

Pen _penDkShadow;

};

Pens3d::Pens3d () : _penLight ( GetSysColor(COLOR_3DLIGHT)), _penHilight ( GetSysColor(COLOR_3DHILIGHT)), _penShadow ( GetSysColor(COLOR_3DSHADOW)), _penDkShadow ( GetSysColor(COLOR_3DDKSHADOW)) {}

void SplitController::Paint () {

PaintCanvas canvas (_hwnd);

{

PenHolder pen (canvas, _pens.Light ());

canvas.Line (0, 0, 0, _cy - 1);

}

{

PenHolder pen (canvas, _pens.Hilight ());

canvas.Line (1, 0, 1, _cy - 1);

}

{

PenHolder pen (canvas, _pens.Shadow ());

canvas.Line (_cx - 2, 0, _cx - 2, _cy - 1);

}

{

PenHolder pen (canvas, _pens.DkShadow ());

canvas.Line (_cx - 1, 0, _cx - 1, _cy - 1);

}

}

The tricky part is the processing of mouse messages, although most of this code is pretty standard. We have to be able to deal with button-down, mouse drag and button-up.

void SplitController::LButtonDown(POINTS pt) {

_hwnd.CaptureMouse ();

// Find x offset of splitter

// with respect to parent client area

POINT ptOrg = {0, 0};

_hwndParent.ClientToScreen (ptOrg);

int xParent = ptOrg.x;

ptOrg.x = 0;

_hwnd.ClientToScreen (ptOrg);

int xChild = ptOrg.x;

_dragStart = xChild - xParent + _cx / 2 - pt.x;

_dragX = _dragStart + pt.x;

// Draw a divider using XOR mode

UpdateCanvas canvas (_hwndParent);

ModeSetter mode (canvas, R2_NOTXORPEN);

canvas.Line (_dragX, 0, _dragX, _cy - 1);

}

When the left mouse button is clicked over the client area of the splitter, we perform the following tasks. First, we capture the mouse. The user might, and probably will, drag the mouse cursor outside of the splitter bar. Capturing the mouse will ensure that all mouse messages will now be directed to us, even though the mouse cursor may wander all over the screen.

Next, we convert the local splitter-bar coordinates to the parent window coordinates. We do it by converting the parent's origin to screen coordinates and converting our (splitter's) origin to screen coordinates. The difference gives us our origin with respect to parent's client area. We do some more arithmetics in order to find the x coordinate of the center of the splitter, because that's what we'll be dragging.

To give the user dragging feedback, we draw a single vertical line that will be dragged across the client area of the parent window. Notice two important details. The canvas that we are creating are associated with the parent — we are using the parent's window handle. The drawing mode is logical xor(exclusive or). That means that the pixels we are drawing are xor'd with the original pixels. Logical xor has this useful property that if you apply it twice, you restore the original. It's the oldest trick in computer graphics — the poor man's animation technique. You draw something using the xor mode and erase it simply by drawing it again in the xor mode. Just look at the dragging code below.

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «Windows API Tutorials»

Представляем Вашему вниманию похожие книги на «Windows API Tutorials» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «Windows API Tutorials»

Обсуждение, отзывы о книге «Windows API Tutorials» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x