Click here to Skip to main content
16,011,120 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: GUI Pin
ohadp2-Aug-04 23:54
ohadp2-Aug-04 23:54 
GeneralRe: GUI Pin
cristianmuller4-Aug-04 3:27
cristianmuller4-Aug-04 3:27 
QuestionDirectShow vs. DirectDraw ??? Pin
baboguru2-Aug-04 20:41
baboguru2-Aug-04 20:41 
QuestionHow to search a substring of a LPWSTR? Pin
ting6682-Aug-04 20:34
ting6682-Aug-04 20:34 
AnswerRe: How to search a substring of a LPWSTR? Pin
PJ Arends2-Aug-04 20:58
professionalPJ Arends2-Aug-04 20:58 
AnswerRe: How to search a substring of a LPWSTR? Pin
Johann Gerell2-Aug-04 21:09
Johann Gerell2-Aug-04 21:09 
AnswerRe: How to search a substring of a LPWSTR? Pin
Archer2824-Aug-04 11:54
Archer2824-Aug-04 11:54 
GeneralDLL making a MSN style pop up window Help. Pin
Member 9620472-Aug-04 19:46
Member 9620472-Aug-04 19:46 
I'm making a DLL that exports some functions that create and configure a window from the MSN Style PopUp window example on CP. Declaring the code goes thru without error but it crashes everytime I try to uae the functions. Please help! here is the code:



#include "stdafx.h"
#include "TaskbarNotifier.h"

#define IDT_HIDDEN 0
#define IDT_APPEARING 1
#define IDT_WAITING 2
#define IDT_DISAPPEARING 3

#define TASKBAR_ON_TOP 1
#define TASKBAR_ON_LEFT 2
#define TASKBAR_ON_RIGHT 3
#define TASKBAR_ON_BOTTOM 4

// CTaskbarNotifier

IMPLEMENT_DYNAMIC(CTaskbarNotifier, CWnd)
CTaskbarNotifier::CTaskbarNotifier()
{
m_strCaption="";
m_pWndParent=NULL;
m_bMouseIsOver=FALSE;
m_hSkinRegion=NULL;
m_hCursor=NULL;
m_crNormalTextColor=RGB(133,146,181);
m_crSelectedTextColor=RGB(10,36,106);
m_nSkinHeight=0;
m_nSkinWidth=0;

m_dwTimeToShow=0;
m_dwTimeToLive=0;
m_dwTimeToHide=0;
m_dwDelayBetweenShowEvents=0;
m_dwDelayBetweenHideEvents=0;
m_nStartPosX=0;
m_nStartPosY=0;
m_nCurrentPosX=0;
m_nCurrentPosY=0;
m_nIncrement=2;
m_nTaskbarPlacement=0;
m_nAnimStatus=IDT_HIDDEN;
m_rcText.SetRect(0,0,0,0);
}

CTaskbarNotifier::~CTaskbarNotifier()
{
// No need to delete the HRGN, SetWindowRgn() owns it after being called
}

int CTaskbarNotifier::Create(CWnd *pWndParent)
{
m_pWndParent=pWndParent;
CString strWndClass=AfxRegisterWndClass(0,AfxGetApp()->LoadStandardCursor(IDC_ARROW),GetSysColorBrush(COLOR_WINDOW),NULL);
return CreateEx(0,strWndClass,NULL,WS_POPUP,0,0,0,0,pWndParent->m_hWnd,NULL);
}

void CTaskbarNotifier::SetTextFont(LPCTSTR szFont,int nSize,int nNormalStyle,int nSelectedStyle)
{
LOGFONT lf;
m_myNormalFont.DeleteObject();
m_myNormalFont.CreatePointFont(nSize,szFont);
m_myNormalFont.GetLogFont(&lf);

// We set the Font of the unselected ITEM
if (nNormalStyle & TN_TEXT_BOLD)
lf.lfWeight = FW_BOLD;
else
lf.lfWeight = FW_NORMAL;

if (nNormalStyle & TN_TEXT_ITALIC)
lf.lfItalic=TRUE;
else
lf.lfItalic=FALSE;

if (nNormalStyle & TN_TEXT_UNDERLINE)
lf.lfUnderline=TRUE;
else
lf.lfUnderline=FALSE;

m_myNormalFont.DeleteObject();
m_myNormalFont.CreateFontIndirect(&lf);

// We set the Font of the selected ITEM
if (nSelectedStyle & TN_TEXT_BOLD)
lf.lfWeight = FW_BOLD;
else
lf.lfWeight = FW_NORMAL;

if (nSelectedStyle & TN_TEXT_ITALIC)
lf.lfItalic=TRUE;
else
lf.lfItalic=FALSE;

if (nSelectedStyle & TN_TEXT_UNDERLINE)
lf.lfUnderline=TRUE;
else
lf.lfUnderline=FALSE;

m_mySelectedFont.DeleteObject();
m_mySelectedFont.CreateFontIndirect(&lf);
}

void CTaskbarNotifier::SetTextColor(COLORREF crNormalTextColor,COLORREF crSelectedTextColor)
{
m_crNormalTextColor=crNormalTextColor;
m_crSelectedTextColor=crSelectedTextColor;
RedrawWindow();
}

void CTaskbarNotifier::SetTextRect(RECT rcText)
{
m_rcText=rcText;
}

BOOL CTaskbarNotifier::SetSkin(UINT nBitmapID,short red,short green,short blue)
{
BITMAP bm;

m_biSkinBackground.DeleteObject();

if (!m_biSkinBackground.LoadBitmap(nBitmapID))
return FALSE;
GetObject(m_biSkinBackground.GetSafeHandle(), sizeof(bm), &bm);
m_nSkinWidth=bm.bmWidth;
m_nSkinHeight=bm.bmHeight;
m_rcText.SetRect(0,0,bm.bmWidth,bm.bmHeight);

if (red!=-1 && green!=-1 && blue!=-1)
{
// No need to delete the HRGN, SetWindowRgn() owns it after being called
m_hSkinRegion=GenerateRegion((HBITMAP)m_biSkinBackground.GetSafeHandle(),(BYTE) red,(BYTE) green,(BYTE) blue);
SetWindowRgn(m_hSkinRegion, true);
}

return TRUE;
}

BOOL CTaskbarNotifier::SetSkin(LPCTSTR szFileName,short red,short green,short blue)
{
BITMAP bm;
HBITMAP hBmp;

hBmp=(HBITMAP) ::LoadImage(AfxGetInstanceHandle(),szFileName,IMAGE_BITMAP,0,0, LR_LOADFROMFILE);
if (!hBmp)
return FALSE;

m_biSkinBackground.DeleteObject();
m_biSkinBackground.Attach(hBmp);
GetObject(m_biSkinBackground.GetSafeHandle(), sizeof(bm), &bm);
m_nSkinWidth=bm.bmWidth;
m_nSkinHeight=bm.bmHeight;
m_rcText.SetRect(0,0,bm.bmWidth,bm.bmHeight);

if (red!=-1 && green!=-1 && blue!=-1)
{
// No need to delete the HRGN, SetWindowRgn() owns it after being called
m_hSkinRegion=GenerateRegion((HBITMAP)m_biSkinBackground.GetSafeHandle(),(BYTE) red,(BYTE) green,(BYTE) blue);
SetWindowRgn(m_hSkinRegion, true);
}

return TRUE;
}

void CTaskbarNotifier::Show(LPCTSTR szCaption,DWORD dwTimeToShow,DWORD dwTimeToLive,DWORD dwTimeToHide,int nIncrement)
{
unsigned int nDesktopHeight;
unsigned int nDesktopWidth;
unsigned int nScreenWidth;
unsigned int nScreenHeight;
CRect rcDesktop;

m_strCaption=szCaption;
m_dwTimeToShow=dwTimeToShow;
m_dwTimeToLive=dwTimeToLive;
m_dwTimeToHide=dwTimeToHide;

::SystemParametersInfo(SPI_GETWORKAREA,0,&rcDesktop,0);
nDesktopWidth=rcDesktop.right-rcDesktop.left;
nDesktopHeight=rcDesktop.bottom-rcDesktop.top;
nScreenWidth=::GetSystemMetrics(SM_CXSCREEN);
nScreenHeight=::GetSystemMetrics(SM_CYSCREEN);

BOOL bTaskbarOnRight=nDesktopWidth<nscreenwidth &&="" rcdesktop.left="=0;
" bool="" btaskbaronleft="nDesktopWidth<nScreenWidth" rcdesktop.left!="0;
" btaskbarontop="nDesktopHeight<nScreenHeight" rcdesktop.top!="0;
" btaskbaronbottom="nDesktopHeight<nScreenHeight" rcdesktop.top="=0;
"
="" switch="" (m_nanimstatus)
="" {
="" case="" idt_hidden:
="" showwindow(sw_show);
="" if="" (btaskbaronright)
="" m_dwdelaybetweenshowevents="m_dwTimeToShow/(m_nSkinWidth/m_nIncrement);
" m_dwdelaybetweenhideevents="m_dwTimeToHide/(m_nSkinWidth/m_nIncrement);
" m_nstartposx="rcDesktop.right;
" m_nstartposy="rcDesktop.bottom-m_nSkinHeight;
" m_ntaskbarplacement="TASKBAR_ON_RIGHT;
" }
="" else="" (btaskbaronleft)
="" (btaskbarontop)
="" (btaskbaronbottom)
="" taskbar="" is="" on="" the="" bottom="" or="" invisible
="" }

="" m_ncurrentposx="m_nStartPosX;
" m_ncurrentposy="m_nStartPosY;
" settimer(idt_appearing,m_dwdelaybetweenshowevents,null);
="" break;

="" idt_waiting:
="" redrawwindow();
="" killtimer(idt_waiting);
="" settimer(idt_waiting,m_dwtimetolive,null);
="" idt_appearing:
="" idt_disappearing:
="" killtimer(idt_disappearing);
="" setwindowpos(null,m_ncurrentposx,m_ncurrentposy,m_nskinwidth,m_nskinheight,swp_noownerzorder="" |="" swp_nozorder="" swp_noactivate);
="" break;
="" }
}

void="" ctaskbarnotifier::hide()
{
="" killtimer(idt_appearing);
="" movewindow(0,0,0,0);
="" showwindow(sw_hide);
="" m_nanimstatus="IDT_HIDDEN;
}

HRGN" ctaskbarnotifier::generateregion(hbitmap="" hbitmap,="" byte="" red,="" green,="" blue)
{
="" word="" wbmpwidth,wbmpheight;
="" hrgn="" hrgn,="" htmprgn;

="" 24bit="" pixels="" from="" bitmap
="" *ppixels="Get24BitPixels(hBitmap," &wbmpwidth,="" &wbmpheight);
="" (!ppixels)="" return="" null;

="" create="" our="" working="" region
="" (!hrgn)="" {="" delete="" ppixels;="" null;="" dword="" p="0;
" for="" (word="" y="0;" y<wbmpheight;="" y++)
="" x="0;" x<wbmpwidth;="" x++)
="" jred="pPixels[p+2];
" jgreen="pPixels[p+1];
" jblue="pPixels[p+0];

" (jred="=red" remove="" transparent="" color="" htmprgn="CreateRectRgn(x,y,x+1,y+1);
" combinergn(hrgn,="" htmprgn,="" rgn_xor);
="" deleteobject(htmprgn);
="" next="" pixel
="" p+="3;
" release="" pixels
="" ppixels;

="" hrgn;
}

byte*="" ctaskbarnotifier::get24bitpixels(hbitmap="" pbitmap,="" *pwwidth,="" *pwheight)
{
="" bitmap="" bmpbmp;
="" lpbitmapinfo="" pbmiinfo;
="" bitmapinfo="" bmiinfo;
="" wbmpwidth,="" wbmpheight;

="" getobject(pbitmap,="" sizeof(bmpbmp),&bmpbmp);
="" pbmiinfo="(LPBITMAPINFO)&bmpBmp;

" wbmpwidth="(WORD)pbmiInfo-">bmiHeader.biWidth;
wBmpWidth -= (wBmpWidth%4);
wBmpHeight = (WORD)pbmiInfo->bmiHeader.biHeight;

*pwWidth = wBmpWidth;
*pwHeight = wBmpHeight;

BYTE *pPixels = new BYTE[wBmpWidth*wBmpHeight*3];
if (!pPixels) return NULL;

HDC hDC =::GetWindowDC(NULL);

bmiInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmiInfo.bmiHeader.biWidth = wBmpWidth;
bmiInfo.bmiHeader.biHeight = -wBmpHeight;
bmiInfo.bmiHeader.biPlanes = 1;
bmiInfo.bmiHeader.biBitCount = 24;
bmiInfo.bmiHeader.biCompression = BI_RGB;
bmiInfo.bmiHeader.biSizeImage = wBmpWidth*wBmpHeight*3;
bmiInfo.bmiHeader.biXPelsPerMeter = 0;
bmiInfo.bmiHeader.biYPelsPerMeter = 0;
bmiInfo.bmiHeader.biClrUsed = 0;
bmiInfo.bmiHeader.biClrImportant = 0;

// get pixels from the original bitmap converted to 24bits
int iRes = GetDIBits(hDC,pBitmap,0,wBmpHeight,(LPVOID)pPixels,&bmiInfo,DIB_RGB_COLORS);

// release the device context
::ReleaseDC(NULL,hDC);

// if failed, cancel the operation.
if (!iRes)
{
delete pPixels;
return NULL;
};

// return the pixel array
return pPixels;
}

BEGIN_MESSAGE_MAP(CTaskbarNotifier, CWnd)
// ON_WM_CREATE()
// ON_WM_MOUSEMOVE()
// ON_WM_DESTROY()
// ON_WM_ERASEBKGND()
// ON_WM_PAINT()
// ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
// ON_MESSAGE(WM_MOUSEHOVER, OnMouseHover)
// ON_WM_SETCURSOR()
ON_WM_LBUTTONUP()
// ON_WM_TIMER()
END_MESSAGE_MAP()


// CTaskbarNotifier message handlers
/*
int CTaskbarNotifier::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;

m_hCursor = ::LoadCursor(NULL, MAKEINTRESOURCE(32649));
return 0;
}

void CTaskbarNotifier::OnDestroy()
{
CWnd::OnDestroy();

// TODO: Add your message handler code here
}

void CTaskbarNotifier::OnMouseMove(UINT nFlags, CPoint point)
{
TRACKMOUSEEVENT t_MouseEvent;
t_MouseEvent.cbSize = sizeof(TRACKMOUSEEVENT);
t_MouseEvent.dwFlags = TME_LEAVE | TME_HOVER;
t_MouseEvent.hwndTrack = m_hWnd;
t_MouseEvent.dwHoverTime = 1;

::_TrackMouseEvent(&t_MouseEvent);

CWnd::OnMouseMove(nFlags, point);
}
*/
void CTaskbarNotifier::OnLButtonUp(UINT nFlags, CPoint point)
{
m_pWndParent->PostMessage(WM_TASKBARNOTIFIERCLICKED,0,0);
CWnd::OnLButtonUp(nFlags, point);
}
/*
LRESULT CTaskbarNotifier::OnMouseHover(WPARAM w, LPARAM l)
{
if (m_bMouseIsOver==FALSE)
{
m_bMouseIsOver=TRUE;
RedrawWindow();
}
return 0;
}

LRESULT CTaskbarNotifier::OnMouseLeave(WPARAM w, LPARAM l)
{
if (m_bMouseIsOver==TRUE)
{
m_bMouseIsOver=FALSE;
RedrawWindow();
}
return 0;
}

BOOL CTaskbarNotifier::OnEraseBkgnd(CDC* pDC)
{
CDC memDC;
CBitmap *pOldBitmap;
BITMAP bm;

memDC.CreateCompatibleDC(pDC);
GetObject(m_biSkinBackground.GetSafeHandle(), sizeof(bm), &bm);
pOldBitmap=memDC.SelectObject(&m_biSkinBackground);

pDC->BitBlt(0,0,bm.bmWidth,bm.bmHeight,&memDC,0,0,SRCCOPY);
memDC.SelectObject(pOldBitmap);

return TRUE;
}

void CTaskbarNotifier::OnPaint()
{
CPaintDC dc(this);
CRect rcClient;
CFont *pOldFont;
char *szBuffer;

if (m_bMouseIsOver)
{
dc.SetTextColor(m_crSelectedTextColor);
pOldFont=dc.SelectObject(&m_mySelectedFont);
}
else
{
dc.SetTextColor(m_crNormalTextColor);
pOldFont=dc.SelectObject(&m_myNormalFont);
}

szBuffer=new char[m_strCaption.GetLength()+10];
strcpy(szBuffer,m_strCaption);

dc.SetBkMode(TRANSPARENT);
rcClient.DeflateRect(10,20,10,20);
dc.DrawText(szBuffer,-1,m_rcText,DT_CENTER | DT_VCENTER | DT_WORDBREAK | DT_END_ELLIPSIS);

delete[] szBuffer;
dc.SelectObject(pOldFont);
}

BOOL CTaskbarNotifier::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if (nHitTest == HTCLIENT)
{
::SetCursor(m_hCursor);
return TRUE;
}
return CWnd::OnSetCursor(pWnd, nHitTest, message);
}

void CTaskbarNotifier::OnTimer(UINT nIDEvent)
{
switch (nIDEvent)
{
case IDT_APPEARING:
m_nAnimStatus=IDT_APPEARING;
switch(m_nTaskbarPlacement)
{
case TASKBAR_ON_BOTTOM:
if (m_nCurrentPosY>(m_nStartPosY-m_nSkinHeight))
m_nCurrentPosY-=m_nIncrement;
else
{
KillTimer(IDT_APPEARING);
SetTimer(IDT_WAITING,m_dwTimeToLive,NULL);
m_nAnimStatus=IDT_WAITING;
}
break;
case TASKBAR_ON_TOP:
if ((m_nCurrentPosY-m_nStartPosY)<m_nskinheight)
m_ncurrentposy+="m_nIncrement;
" else
="" {
="" killtimer(idt_appearing);
="" settimer(idt_waiting,m_dwtimetolive,null);
="" m_nanimstatus="IDT_WAITING;
" }
="" break;
="" case="" taskbar_on_left:
="" if="" ((m_ncurrentposx-m_nstartposx)<m_nskinwidth)
="" m_ncurrentposx+="m_nIncrement;
" taskbar_on_right:
="" (m_ncurrentposx="">(m_nStartPosX-m_nSkinWidth))
m_nCurrentPosX-=m_nIncrement;
else
{
KillTimer(IDT_APPEARING);
SetTimer(IDT_WAITING,m_dwTimeToLive,NULL);
m_nAnimStatus=IDT_WAITING;
}
break;
}
SetWindowPos(NULL,m_nCurrentPosX,m_nCurrentPosY,m_nSkinWidth,m_nSkinHeight,SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOACTIVATE);
//RedrawWindow();
break;

case IDT_WAITING:
KillTimer(IDT_WAITING);
SetTimer(IDT_DISAPPEARING,m_dwDelayBetweenHideEvents,NULL);
break;

case IDT_DISAPPEARING:
m_nAnimStatus=IDT_DISAPPEARING;
switch(m_nTaskbarPlacement)
{
case TASKBAR_ON_BOTTOM:
if (m_nCurrentPosY<m_nstartposy)
m_ncurrentposy+="m_nIncrement;
" else
="" {
="" killtimer(idt_disappearing);
="" hide();
="" }
="" break;
="" case="" taskbar_on_top:
="" if="" (m_ncurrentposy="">m_nStartPosY)
m_nCurrentPosY-=m_nIncrement;
else
{
KillTimer(IDT_DISAPPEARING);
Hide();
}
break;
case TASKBAR_ON_LEFT:
if (m_nCurrentPosX>m_nStartPosX)
m_nCurrentPosX-=m_nIncrement;
else
{
KillTimer(IDT_DISAPPEARING);
Hide();
}
break;
case TASKBAR_ON_RIGHT:
if (m_nCurrentPosX<m_nstartposx)
m_ncurrentposx+="m_nIncrement;
" else
="" {
="" killtimer(idt_disappearing);
="" hide();
="" }
="" break;
="" setwindowpos(null,m_ncurrentposx,m_ncurrentposy,m_nskinwidth,m_nskinheight,swp_noownerzorder="" |="" swp_nozorder="" swp_noactivate);
="" redrawwindow();
="" }

="" cwnd::ontimer(nidevent);
}
*=""




and="" the="" functions="" are:



#define="" export="" extern="" "c"="" __declspec(="" dllexport="" )
#include="" "declare.h"

ctaskbarnotifier="" dialog1;
ctaskbarnotifier*="" dialog="&dialog1;
long" dietime="500;
long" staytime="3000;
long" showtime="500;

export" pchar="" initiate()
{
="" dialog-="">Create(NULL);
return "MSN Style Taskbar Notification PopUp DLL by Tyrant";
}

export void Show(PCHAR caption, int misc)
{
dialog->Show(caption,showTime,stayTime,dieTime,misc);
}

export void setTimeOptions(long comeUp, long stay, long down)
{
int stayTime=stay;
int showTime=comeUp;
int dieTime=down;
}

export void SetSkin(PCHAR file, short red, short green, short blue)
{
dialog->SetSkin(file,red,green,blue);
}

export void SetFont(LPCTSTR font, int size, DWORD normal, DWORD spec)
{
dialog->SetTextFont(font, size,normal,spec);
}

export void TextColor(COLORREF normal,COLORREF not)
{
dialog->SetTextColor(normal,not);
}

export void SetTextArea(long x, long y, long width, long height)
{
dialog->SetTextRect(CRect(x,y,width,height));
}



Thnx in advance for anybody taht helps me.
Generalwindows, mouse coordinates with ctrlbars Pin
radiox2-Aug-04 19:26
radiox2-Aug-04 19:26 
GeneralRe: windows, mouse coordinates with ctrlbars Pin
radiox2-Aug-04 20:32
radiox2-Aug-04 20:32 
Generalwindowsx.txt Pin
Archer2822-Aug-04 19:10
Archer2822-Aug-04 19:10 
GeneralRe: windowsx.txt Pin
V.2-Aug-04 22:15
professionalV.2-Aug-04 22:15 
GeneralRe: windowsx.txt Pin
Archer2824-Aug-04 7:48
Archer2824-Aug-04 7:48 
GeneralRe: windowsx.txt Pin
V.4-Aug-04 10:24
professionalV.4-Aug-04 10:24 
GeneralRe: windowsx.txt Pin
Archer2824-Aug-04 11:45
Archer2824-Aug-04 11:45 
QuestionHow to set Vertical CSliderCtrl position sequencely Pin
old_cat2-Aug-04 19:05
old_cat2-Aug-04 19:05 
Generalbitmap zooming Pin
Zeeshan Bilal2-Aug-04 18:59
Zeeshan Bilal2-Aug-04 18:59 
GeneralRe: bitmap zooming Pin
PJ Arends2-Aug-04 19:58
professionalPJ Arends2-Aug-04 19:58 
GeneralRe: bitmap zooming Pin
Zeeshan Bilal2-Aug-04 20:59
Zeeshan Bilal2-Aug-04 20:59 
GeneralRe: bitmap zooming Pin
PJ Arends2-Aug-04 21:12
professionalPJ Arends2-Aug-04 21:12 
Generaldatabase problem Pin
Anonymous2-Aug-04 17:48
Anonymous2-Aug-04 17:48 
GeneralRe: database problem Pin
wb2-Aug-04 20:25
wb2-Aug-04 20:25 
GeneralRe: database problem Pin
Anonymous2-Aug-04 20:39
Anonymous2-Aug-04 20:39 
GeneralRe: database problem Pin
wb2-Aug-04 20:51
wb2-Aug-04 20:51 
QuestionWhich is better? Pin
Zero_One_ADO2-Aug-04 17:35
Zero_One_ADO2-Aug-04 17:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.