[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] CPTButton::Create( [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] x, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] y,
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Width, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Height,
HWND hParent,UINT uPictureType,
UINT uID)
{
PWSTR pBitmap=[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] WCHAR[MAX_PATH];
wcsset(pBitmap,0);
m_hWnd=CreateWindowEx( 0,
L[/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"BUTTON"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],
NULL,
WS_CHILD | WS_VISIBLE | BS_BITMAP,
x,
y,
Width,
Height,
hParent,
NULL,
GetModuleHandle(NULL),
NULL);
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](m_hWnd==NULL)
{
ShowErrorMessage(GetLastError(),MB_ICONEXCLAMATION);
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
}
SetWindowLong(m_hWnd, GWL_ID, uID);
m_uID=uID;
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]switch[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](uPictureType)
{
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]case[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] 1:
wcscpy(pBitmap,L[/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"pictures\\monument.bmp"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]break[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]case[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] 2:
wcscpy(pBitmap,L[/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"pictures\\church.bmp"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]break[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]case[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] 3:
wcscpy(pBitmap,L[/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"pictures\\hospital.bmp"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]break[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]default[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]:
wcscpy(pBitmap,L[/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"pictures\\object.bmp"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
}
HANDLE hImage=LoadImage( GetModuleHandle(NULL),
pBitmap,
IMAGE_BITMAP,
0,
0,
LR_LOADFROMFILE);
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](hImage==NULL)
{
ShowErrorMessage(GetLastError(), MB_ICONEXCLAMATION);
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
}
SendMessage( m_hWnd,
BM_SETIMAGE,
(WPARAM)IMAGE_BITMAP,
(LPARAM)hImage);[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]}
[/SIZE]
очередной вопрос про tooltip
Создание кнопки:
Код:
Создание ToolTip'а (функция из MSDN):
Код:
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] CPTButton::CreateTooltip()
{
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// struct specifying control classes to register
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]INITCOMMONCONTROLSEX iccex;
HWND hwndTT; [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// handle to the ToolTip control
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// struct specifying info about tool in ToolTip control
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]TOOLINFO ti;
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]unsigned[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] uid = 0; [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// for ti initialization[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
PWSTR lptstr = m_pSmallText;
RECT rect; [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// for client area coordinates
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]/* INITIALIZE COMMON CONTROLS */
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]iccex.dwICC = ICC_WIN95_CLASSES;
iccex.dwSize = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]sizeof[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](INITCOMMONCONTROLSEX);
InitCommonControlsEx(&iccex);
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]/* CREATE A TOOLTIP WINDOW */
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]hwndTT = CreateWindowEx(WS_EX_TOPMOST,
TOOLTIPS_CLASS,
NULL,
WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP | TTS_BALLOON | TTS_CLOSE ,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
m_hWnd,
NULL,
GetModuleHandle(NULL),
NULL
);
SetWindowPos(hwndTT,
HWND_TOPMOST,
0,
0,
0,
0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]/* GET COORDINATES OF THE MAIN CLIENT AREA */
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]GetClientRect (m_hWnd, &rect);
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]/* INITIALIZE MEMBERS OF THE TOOLINFO STRUCTURE */
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]ti.cbSize = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]sizeof[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](TOOLINFO);
ti.uFlags = TTF_SUBCLASS;
ti.hwnd = m_hWnd;
ti.hinst = GetModuleHandle(NULL);
ti.uId = uid;
ti.lpszText = lptstr;
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// ToolTip control will cover the whole window
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]ti.rect.left = rect.left;
ti.rect.top = rect.top;
ti.rect.right = rect.right;
ti.rect.bottom = rect.bottom;
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]/* SEND AN ADDTOOL MESSAGE TO THE TOOLTIP CONTROL WINDOW */
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
SendMessage(hwndTT, TTM_SETMAXTIPWIDTH, 0, 300);
}
[/SIZE]
{
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// struct specifying control classes to register
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]INITCOMMONCONTROLSEX iccex;
HWND hwndTT; [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// handle to the ToolTip control
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// struct specifying info about tool in ToolTip control
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]TOOLINFO ti;
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]unsigned[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] uid = 0; [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// for ti initialization[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]
PWSTR lptstr = m_pSmallText;
RECT rect; [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// for client area coordinates
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]/* INITIALIZE COMMON CONTROLS */
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]iccex.dwICC = ICC_WIN95_CLASSES;
iccex.dwSize = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]sizeof[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](INITCOMMONCONTROLSEX);
InitCommonControlsEx(&iccex);
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]/* CREATE A TOOLTIP WINDOW */
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]hwndTT = CreateWindowEx(WS_EX_TOPMOST,
TOOLTIPS_CLASS,
NULL,
WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP | TTS_BALLOON | TTS_CLOSE ,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
m_hWnd,
NULL,
GetModuleHandle(NULL),
NULL
);
SetWindowPos(hwndTT,
HWND_TOPMOST,
0,
0,
0,
0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]/* GET COORDINATES OF THE MAIN CLIENT AREA */
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]GetClientRect (m_hWnd, &rect);
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]/* INITIALIZE MEMBERS OF THE TOOLINFO STRUCTURE */
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]ti.cbSize = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]sizeof[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](TOOLINFO);
ti.uFlags = TTF_SUBCLASS;
ti.hwnd = m_hWnd;
ti.hinst = GetModuleHandle(NULL);
ti.uId = uid;
ti.lpszText = lptstr;
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// ToolTip control will cover the whole window
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]ti.rect.left = rect.left;
ti.rect.top = rect.top;
ti.rect.right = rect.right;
ti.rect.bottom = rect.bottom;
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]/* SEND AN ADDTOOL MESSAGE TO THE TOOLTIP CONTROL WINDOW */
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
SendMessage(hwndTT, TTM_SETMAXTIPWIDTH, 0, 300);
}
[/SIZE]