Member
Group: Members
Posts: 125
Warn:0%
|
ребята есть такая вот библиотека, показывает всплывающие "MS-style balloon tips" работает отлично тока жаль что не с юникодом... если кто может подправить код... буду рад... спасибо...
CODE | // module.h #pragma once
#define IDT_TIMER 1024
BOOL __stdcall DialogProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam); BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved);
HANDLE ApiCreateBalloon( HANDLE hParent, LPTSTR msg, UINT msg_len, LPTSTR title, UINT title_len, int icon, int orientation, int x, int y); //, int timeout );
class BalloonData { private: char *T; char *M; public: LPTSTR title; LPTSTR messg; int messg_len; int title_len; int icon; int orientation; int x; int y; int timeout; public: BalloonData() { T = new char[1024]; M = new char[4096]; memset(T, 0, 1024); memset(M, 0, 4096); title = messg = (LPTSTR)NULL; messg_len = title_len = icon = orientation = x = y = timeout = 0; link(); } ~BalloonData() { if( T ) delete T; if( M ) delete M; } private: void link(void) { title = T; messg = M; } }; typedef BalloonData* pBalloonData;
|
CODE | // module.cpp : Defines the entry point for the DLL application. //
#include "stdafx.h" #include "module.h"
HINSTANCE hInstance;
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: hInstance = (HINSTANCE)hModule; case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break; } return TRUE;
UNREFERENCED_PARAMETER(lpReserved);
}
HANDLE ApiCreateBalloon( HANDLE hParent, LPTSTR msg, UINT msg_len, LPTSTR title, UINT title_len, int icon, int orientation, int x, int y, int timeout ) { BalloonData data; memcpy( data.messg, msg, msg_len ); memcpy( data.title, title, title_len ); data.messg_len = msg_len; data.title_len = title_len; data.icon = icon; data.orientation = orientation; POINT pnt; pnt.x=x; pnt.y=y; //bool a = ( ClientToScreen((HWND)hParent, &pnt) != 0 ); ClientToScreen((HWND)hParent, &pnt); data.x = pnt.x; data.y = pnt.y;
// HWND hDlg = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG), (HWND)hParent, (DLGPROC)DialogProc); HWND hDlg = CreateDialogParam(hInstance, MAKEINTRESOURCE(IDD_DIALOG), (HWND)hParent, (DLGPROC)DialogProc, (LPARAM)&data); //ShowWindow(hDlg, SW_HIDE); if( timeout > 0 ) { SetTimer(hDlg, IDT_TIMER, timeout, (TIMERPROC) NULL); }
//SystemParametersInfo(0x1025, 0, (PVOID)TRUE, SPIF_SENDCHANGE); return (HANDLE)hDlg; }
BOOL __stdcall DialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { RECT rc, wrc; HBRUSH br = NULL; HRGN hRgn = NULL; HFONT hfont = NULL; const int d = 15; const int r = 20;
switch (message) {
case WM_INITDIALOG: { DWORD style = GetClassLong(hDlg, GCL_STYLE); SetClassLong(hDlg, GCL_STYLE, style | CS_DROPSHADOW);
pBalloonData data = (pBalloonData)lParam; if(data != NULL) { char* title = new char[data->title_len+1]; memset(title, 0, data->title_len+1); memcpy(title, data->title, data->title_len); char* message = new char[data->messg_len+1]; memset(message, 0, data->messg_len+1); memcpy(message, data->messg, data->messg_len);
SetProp(hDlg, "title", (HANDLE)title); SetProp(hDlg, "message", (HANDLE)message); HBITMAP bitmap; switch(data->icon) { case 1: // exclamation bitmap = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_EX)); break; case 0: //info default: bitmap = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_I)); } SetProp(hDlg, "titleicon", (HANDLE)bitmap); }
HDC hdc = GetDC(hDlg); char str[1024]; int nHeight; HWND title = GetDlgItem(hDlg, IDC_TITLE); GetClientRect(title, &rc); GetWindowRect(hDlg, &wrc); strcpy(&str[0], data->title); nHeight = -MulDiv(8, GetDeviceCaps(hdc, LOGPIXELSY), 72); hfont = CreateFont(nHeight,0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, RUSSIAN_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH, "Tahoma"); SetProp(hDlg, "titlefont", hfont); HFONT oldFont = (HFONT)SelectObject(hdc, hfont); DrawText(hdc, (LPCTSTR)&str[0], (int)strlen(&str[0]), &rc, DT_CALCRECT|DT_NOPREFIX|DT_LEFT|DT_SINGLELINE); //DeleteObject(hfont);
SetWindowPos(title, NULL, 0, 0, (rc.right-rc.left), (rc.bottom-rc.top), SWP_NOMOVE|SWP_NOOWNERZORDER|SWP_NOZORDER); HWND hWndCloseButton = GetDlgItem(hDlg, IDC_CLOSE); if(rc.right-rc.left > (wrc.right-wrc.left)-(2*d)-40) { int dx = (rc.right-rc.left)-(wrc.right-wrc.left)+2*d+40; wrc.right += dx; SetWindowPos(hDlg, NULL, 0, 0, (wrc.right-wrc.left), (wrc.bottom-wrc.top), SWP_NOMOVE|SWP_NOOWNERZORDER|SWP_NOZORDER); }
HWND ctrl = GetDlgItem(hDlg, IDC_MESSAGE); SetWindowPos(ctrl, NULL, 0, 0, (wrc.right-wrc.left), (wrc.bottom-wrc.top), SWP_NOMOVE|SWP_NOOWNERZORDER|SWP_NOZORDER); GetClientRect(ctrl, &rc); strcpy(&str[0], data->messg); nHeight = -MulDiv(8, GetDeviceCaps(hdc, LOGPIXELSY), 72); hfont = CreateFont(nHeight,0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, RUSSIAN_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH, "Tahoma"); SetProp(hDlg, "messagefont", hfont); SelectObject(hdc, hfont); DrawText(hdc, (LPCTSTR)&str[0], (int)strlen(&str[0]), &rc, DT_CALCRECT|DT_NOPREFIX|DT_LEFT|DT_WORDBREAK); //DeleteObject(hfont);
SetWindowPos(ctrl, NULL, 0, 0, (rc.right-rc.left), (rc.bottom-rc.top), SWP_NOMOVE|SWP_NOOWNERZORDER|SWP_NOZORDER); if(rc.right-rc.left > (wrc.right-wrc.left)-2*d) { int dx = (rc.right-rc.left)-(wrc.right-wrc.left)+2*d; wrc.right += dx; SetWindowPos(hDlg, NULL, 0, 0, (wrc.right-wrc.left), (wrc.bottom-wrc.top), SWP_NOMOVE|SWP_NOOWNERZORDER|SWP_NOZORDER); } if(rc.bottom-rc.top > (wrc.bottom-wrc.top)-r-d-20) { int dy = (rc.bottom-rc.top)-(wrc.bottom-wrc.top)+r+d+20; wrc.bottom += dy; SetWindowPos(hDlg, NULL, 0, 0, (wrc.right-wrc.left), (wrc.bottom-wrc.top), SWP_NOMOVE|SWP_NOOWNERZORDER|SWP_NOZORDER); } SetWindowPos(hWndCloseButton, NULL, (wrc.right-wrc.left)-23,7,0,0, SWP_NOSIZE|SWP_NOOWNERZORDER|SWP_NOZORDER); SelectObject(hdc, (HGDIOBJ)(HFONT)oldFont); ReleaseDC(hDlg, hdc); HRGN hRgn1, hRgn2; hRgn = hRgn1 = hRgn2 = NULL;
GetClientRect(hDlg, &rc); GetWindowRect(hDlg, &wrc); hRgn1 = CreateRoundRectRgn(0, 0, rc.right, rc.bottom-r, d, d); hRgn = CreateRectRgn(0, 0, rc.right, rc.bottom); POINT BalloonPointer[3]; if(data->orientation == 0) //( PointerAlignment == 0 ) { BalloonPointer[0].x = rc.right - d; BalloonPointer[0].y = rc.bottom - r - 1; BalloonPointer[1].x = rc.right - d; BalloonPointer[1].y = rc.bottom; BalloonPointer[2].x = rc.right - d - r; BalloonPointer[2].y = rc.bottom - r - 1; } else if(data->orientation == 1) { BalloonPointer[0].x = d; BalloonPointer[0].y = rc.bottom - r - 1; BalloonPointer[1].x = d; BalloonPointer[1].y = rc.bottom; BalloonPointer[2].x = d + r; BalloonPointer[2].y = rc.bottom - r - 1; }
SetWindowPos(hDlg, 0, data->x-BalloonPointer[1].x+1, data->y-BalloonPointer[1].y+1, 0, 0, SWP_NOSIZE|SWP_NOOWNERZORDER|SWP_NOZORDER);
hRgn2 = CreatePolygonRgn(&BalloonPointer[0], 3, ALTERNATE); CombineRgn(hRgn, hRgn2, hRgn1, RGN_OR); SetWindowRgn(hDlg, hRgn, TRUE); SetProp(hDlg, "region", hRgn);
DeleteObject(hRgn1); DeleteObject(hRgn2); //DeleteObject(hRgn);
br = (HBRUSH)CreateSolidBrush(RGB(255,255,225)); SetProp(hDlg, "bgbrush", br);
ShowWindow(hDlg, SW_SHOW); break; } case WM_PAINT: { PAINTSTRUCT ps; HDC hdc;
hdc = GetDC(hDlg); //SetBkMode(hdc, OPAQUE); SetBkColor(hdc, RGB(255,255,225)); ReleaseDC(hDlg, hdc); //hRgn = (HRGN)GetProp(hDlg, "region"); hRgn = CreateRectRgn(0,0,0,0); GetWindowRgn(hDlg, hRgn); HBRUSH blbr = (HBRUSH)GetStockObject(BLACK_BRUSH); //br = (HBRUSH)GetProp(hDlg, "bgbrush");
// Paint frame hdc = BeginPaint(hDlg, &ps); //FillRgn(hdc, hRgn, br); FrameRgn(hdc, hRgn, blbr, 1, 1); EndPaint(hDlg, &ps);
char *str; HFONT hfont; // int nHeight; GetClientRect(hDlg, &wrc);
// Paint title HWND title = GetDlgItem(hDlg, IDC_TITLE); hdc = BeginPaint(title, &ps); GetClientRect(title, &rc); hfont = (HFONT)GetProp(hDlg, "titlefont"); (HFONT)SelectObject(hdc, (HGDIOBJ)(HFONT)hfont); SetTextColor(hdc, RGB(0,0,0)); //SetBkMode(hdc, OPAQUE); // OPAQUE or TRANSPARENT SetBkColor(hdc, RGB(255,255,225)); str = (char*)GetProp(hDlg, "title"); DrawText(hdc, (LPCTSTR)str, (int)strlen(str), &rc, DT_NOPREFIX|DT_LEFT|DT_SINGLELINE); EndPaint(title, &ps);
// Paint message HWND ctrl = GetDlgItem(hDlg, IDC_MESSAGE); hdc = BeginPaint(ctrl, &ps); GetClientRect(ctrl, &rc); hfont = (HFONT)GetProp(hDlg, "messagefont"); (HFONT)SelectObject(hdc, (HGDIOBJ)(HFONT)hfont); SetTextColor(hdc, RGB(0,0,0)); SetBkColor(hdc, RGB(255,255,225)); str = (char*)GetProp(hDlg, "message"); DrawText(hdc, (LPCTSTR)str, (int)strlen(str), &rc, DT_NOPREFIX|DT_LEFT|DT_WORDBREAK); EndPaint(ctrl, &ps);
// Paint title icon HWND titleicon = GetDlgItem(hDlg, IDC_TITLEICON); hdc = BeginPaint(titleicon, &ps); { HBITMAP bitmap = (HBITMAP)GetProp(hDlg, "titleicon"); HDC chdc = CreateCompatibleDC(hdc); SelectObject ( chdc, bitmap ); BitBlt(hdc, 0, 0, 16, 16, chdc, 0, 0, SRCCOPY ); DeleteDC(chdc); } EndPaint(titleicon, &ps); DeleteObject(hRgn);
break; }
case WM_CTLCOLORDLG: //case WM_CTLCOLORSTATIC: { br = CreateSolidBrush(RGB(255,255,225)); return (BOOL)br; //return (BOOL)(HBRUSH)(GetProp(hDlg, "bgbrush")); } case WM_LBUTTONDOWN: case WM_LBUTTONUP: case WM_MOUSEMOVE: { HWND clBt = GetDlgItem(hDlg, IDC_CLOSE); int xPos = LOWORD(lParam); int yPos = HIWORD(lParam);
WINDOWINFO winfo; POINT mPoint; HDC hdc, chdc; HBITMAP bitmap;
winfo.cbSize = sizeof(WINDOWINFO); GetWindowInfo(clBt, &winfo); mPoint.x = winfo.rcWindow.left; mPoint.y = winfo.rcWindow.top; ScreenToClient(hDlg, &mPoint); rc.left = mPoint.x; rc.top = mPoint.y; rc.right = rc.left + ( winfo.rcWindow.right - winfo.rcWindow.left); rc.bottom = rc.top + ( winfo.rcWindow.bottom - winfo.rcWindow.top);
hdc = GetWindowDC(clBt); chdc = CreateCompatibleDC(hdc); if( xPos < rc.right && xPos > rc.left && yPos < rc.bottom && yPos > rc.top ) { if( message == WM_LBUTTONUP ) { PostMessage(hDlg, WM_COMMAND, MAKEWPARAM(IDOK, 0), 0 ); } if( (wParam & MK_LBUTTON) == 1 ) { bitmap = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_X_DOWN)); } else { bitmap = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_X_HOVER)); } } else { bitmap = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_X)); } SelectObject ( chdc, bitmap ); BitBlt(hdc, 0, 0, 16, 16, chdc, 0, 0, SRCCOPY );
DeleteObject( bitmap ); if( DeleteDC(chdc) == 0) throw "error"; if( ReleaseDC(clBt, hdc) == 0) throw "error"; return TRUE; } case WM_COMMAND: { UINT nID = LOWORD(wParam); if( nID == IDOK || nID == IDCANCEL ) { DestroyWindow(hDlg); break; } return FALSE; } case WM_TIMER: switch (wParam) { case IDT_TIMER: // process the autoclose timer DestroyWindow(hDlg); break; } return FALSE; case WM_USER+1: { RECT rc; GetWindowRect(hDlg, &rc); int dx = (int)((int)LOWORD(wParam) - 0x7fff); int dy = (int)((int)HIWORD(wParam) - 0x7fff); int x = rc.left + dx; int y = rc.top + dy;
SetWindowPos(hDlg, HWND_TOPMOST, x, y, 0, 0, SWP_NOZORDER|SWP_NOSENDCHANGING|SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_ASYNCWINDOWPOS); break; } case WM_DESTROY: if (GetProp(hDlg, "region")) { DeleteObject(GetProp(hDlg, "region")); RemoveProp(hDlg, "region"); } if( GetProp(hDlg, "title")) { char* title = (char*)GetProp(hDlg, "title"); delete title; RemoveProp(hDlg, "title"); } if( GetProp(hDlg, "message") ) { char* message = (char*)GetProp(hDlg, "message"); delete message; RemoveProp(hDlg, "message"); } if (GetProp(hDlg, "titleicon")) { DeleteObject(GetProp(hDlg, "titleicon")); RemoveProp(hDlg, "titleicon"); } if (GetProp(hDlg, "bgbrush")) { DeleteObject(GetProp(hDlg, "bgbrush")); RemoveProp(hDlg, "bgbrush"); } if (GetProp(hDlg, "bgbrush")) { DeleteObject(GetProp(hDlg, "bgbrush")); RemoveProp(hDlg, "bgbrush"); } if (GetProp(hDlg, "titlefont")) { DeleteObject(GetProp(hDlg, "titlefont")); RemoveProp(hDlg, "titlefont"); } if (GetProp(hDlg, "messagefont")) { DeleteObject(GetProp(hDlg, "messagefont")); RemoveProp(hDlg, "messagefont"); }
break; default: return FALSE; } if( br != NULL ) { DeleteObject((HGDIOBJ)br); br = NULL; }
return TRUE; }
|
|