Windows API Tutorials
Здесь есть возможность читать онлайн «Windows API Tutorials» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Жанр: Программирование, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.
- Название:Windows API Tutorials
- Автор:
- Жанр:
- Год:неизвестен
- ISBN:нет данных
- Рейтинг книги:3 / 5. Голосов: 1
-
Избранное:Добавить в избранное
- Отзывы:
-
Ваша оценка:
- 60
- 1
- 2
- 3
- 4
- 5
Windows API Tutorials: краткое содержание, описание и аннотация
Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Windows API Tutorials»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.
Windows API Tutorials — читать онлайн бесплатно полную книгу (весь текст) целиком
Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Windows API Tutorials», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.
Интервал:
Закладка:
Without further ado, here's the code in WinMain that sets up the stage.
// Create top window class
TopWinClassMaker topWinClass (WndProcMain, ID_MAIN, hInst, ID_MAIN);
topWinClass.Register ();
// Create child pane classes
WinClassMaker paneClass (WndProcPane, IDC_PANE , hInst);
paneClass.SetSysCursor (IDC_IBEAM);
paneClass.SetDblClicks ();
paneClass.Register ();
Splitter::RegisterClass (hInst);
// Create top window
ResString caption (hInst, ID_CAPTION);
TopWinMaker topWin (caption, ID_MAIN, hInst);
topWin.Create ();
topWin.Show (cmdShow);
First, we register classes. The top window class is associated with its window procedure WndProcMain, which we'll examine in a moment. The two child panes share the same window class associated with WndProcPane. Next, our own splitter class is registered (we'll see the code soon). Finally, the top window is created and displayed. Child windows are created dynamically during the initialization of the parent window.
Here's the window procedure of the top window.
LRESULT CALLBACK WndProcMain(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
Controller * pCtrl = GetWinLong (hwnd);
switch (message) {
case WM_CREATE:
try {
pCtrl = new Controller (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 MSG_MOVESPLITTER:
pCtrl->MoveSplitter (wParam);
return 0;
case WM_DESTROY:
SetWinLong (hwnd, 0);
delete pCtrl;
return 0;
}
return :: DefWindowProc(hwnd, message, wParam, lParam);
}
It's a pretty standard window procedure, except for one message, MSG_MOVESPLITTER. This is our own, user-defined message that is sent by the splitter control to the parent window. But first, let's have a look at the main window controller.
class Controller{
public:
Controller (HWND hwnd, CREATESTRUCT * pCreat);
~Controller ();
void Size (int cx, int cy);
void MoveSplitter (int x);
private:
enum { splitWidth = 8 }; // width of splitter
// User Interface
HWnd _hwnd; //Main controller window HWnd
_leftWin;
HWnd _rightWin;
HWnd _splitter;
int _splitRatio; // in per cent
int _cx;
int _cy;
};
It has a handle to itself, the two child panes, and the splitter window. It also stores the current split ratio, in percent.
The controller's constructor is responsible for the creation of child windows.
Controller::Controller(HWND hwnd, CREATESTRUCT * pCreat) : _hwnd (hwnd), _leftWin (0), _rightWin (0), _splitter (0), _splitRatio (50) {
// Create child windows
{
ChildWinMaker leftWinMaker (IDC_PANE, _hwnd, ID_LEFT_WINDOW);
leftWinMaker.Create ();
_leftWin.Init (leftWinMaker);
leftWinMaker.Show ();
}
{
ChildWinMaker rightWinMaker (IDC_PANE, _hwnd, ID_RIGHT_WINDOW);
rightWinMaker.Create ();
_rightWin.Init (rightWinMaker);
rightWinMaker.Show ();
}
Splitter::MakeWindow (_splitter, _hwnd, ID_SPLITTER);
}
When the user drags the splitter bar, the parent receives the MSG_MOVESPLITTERmessages. The parameter wParamcontains the new distance of the splitter bar from the left edge of the parent window. In response to such a message, the parent has to resize both child panes and move the splitter. It does it by calling the Sizemethod.
void Controller::MoveSplitter(int x) {
_splitRatio = x * 100 / _cx;
if (_splitRatio < 0) _splitRatio = 0;
else if (_splitRatio > 100) _splitRatio = 100;
Size (_cx, _cy);
}
In general, Sizeis called whenever the user resizes the main window, but as you've just seen, we also call it when the splitter is moved.
void Controller::Size(int cx, int cy) {
_cx = cx;
_cy = cy;
int xSplit = (_cx * _splitRatio) / 100;
if (xSplit < 0) xSplit = 0;
if (xSplit + splitWidth >= _cx) xSplit = _cx - splitWidth;
_splitter.MoveDelayPaint (xSplit, 0, splitWidth, cy);
_leftWin.Move (0, 0, xSplit, cy);
_rightWin.Move (xSplit + splitWidth, 0, cx - xSplit - splitWidth, cy);
_splitter.ForceRepaint ();
}
Notice an important trick here. We move the splitter, but delay its repainting until both panes, to its left and to its right, are resized. This technique eliminates some nasty smudging .
That's it as far as client code goes. Now you might be interested to see the implementation of the splitter.
First of all, we like to combine related functions into namespaces. You've seen the calls to Splitter::RegisterClassand Splitter::MakeWindow. The Splitterpart of these names is the namespace.
namespace Splitter{
void RegisterClass(HINSTANCE hInst);
void MakeWindow(HWnd & hwndSplitter /* out */, HWnd hwndParent, int childId);
};
Here's how these functions are implemented
LRESULT CALLBACK WndProcSplitter (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
void Splitter::RegisterClass(HINSTANCE hInst) {
Интервал:
Закладка:
Похожие книги на «Windows API Tutorials»
Представляем Вашему вниманию похожие книги на «Windows API Tutorials» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.
Обсуждение, отзывы о книге «Windows API Tutorials» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.