PopUp bugsuche

iLu_is_a_loser

Erfahrenes Mitglied
Gutn Abend!
Für mein Programm brauche ich ein Popup, hier mal mein code.
Wenn ich die PopUp function öfters aufrufe, crasht das Programm nach ca 5 min.!
Bevor ich mit einem Debugger rangeh wollte ich lieber hier mal fragen, ob man schon im code sieht, wo das Problem liegt Meine vermutung liegt an der timer funktion,
bitte um hilfe!!

Code:
typedef struct popupstruct_t
{
 UINT delay;
 UINT transparence;
 HWND hWnd;
 PAINTSTRUCT ps;
 COLORREF bgColor;
 COLORREF txtColor;
 LPSTR lpUser;
 LPSTR lpText;
 HINSTANCE hInstance;
} POPUPSTRUCT;
extern POPUPSTRUCT	ps;
Code:
  #include "Main.h"
#define TIMER_ID 0x01
DWORD t = 0;
VOID CALLBACK Timer(HWND hWnd, UINT iMsg, UINT iTimer, DWORD dwTime)
{
 t = t + 10;
 if(t >= ps.delay)
 {
 SendMessage(ps.hWnd, WM_DESTROY, 0, 0);
 DestroyWindow(ps.hWnd);
 }
 return;
}
VOID CreateRect()
{
 MoveToEx( ps.ps.hdc, 0, 0, NULL);
 LineTo( ps.ps.hdc, 0, ps.ps.rcPaint.bottom-1);
 LineTo( ps.ps.hdc, ps.ps.rcPaint.right-1, ps.ps.rcPaint.bottom-1);
 LineTo( ps.ps.hdc, ps.ps.rcPaint.right-1, 0);
 LineTo( ps.ps.hdc, 0, 0);
}
HFONT PreCreateFont(DWORD dwFW)
{
 return
 CreateFont(
 0x10,			   // height of font
 0,				// average character width
 0,		   // angle of escapement
 0,		  // base-line orientation angle
 dwFW,			  // font weight
 FALSE,		   // italic attribute option
 FALSE,		// underline attribute option
 FALSE,		// strikeout attribute option
 ANSI_CHARSET,		  // character set identifier
 OUT_DEFAULT_PRECIS,  // output precision
 CLIP_DEFAULT_PRECIS,	// clipping precision
 DEFAULT_QUALITY,		  // output quality
 DEFAULT_PITCH | FF_DONTCARE,   // pitch and family
 "Arial"		   // typeface name
 );
}
LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
 switch(msg)
 {
  case WM_CREATE:
   {
	LOG("start timer\n");
	SetTimer(hWnd, TIMER_ID, 10, (TIMERPROC)Timer);
	return(0);
   } break;
  case WM_PAINT:
   {
	ps.ps.hdc = BeginPaint( ps.hWnd, &ps.ps);
	CreateRect();
	SetBkMode( ps.ps.hdc, TRANSPARENT);
	SetTextColor( ps.ps.hdc,ps.txtColor);
	SelectObject( ps.ps.hdc, PreCreateFont(FW_BOLD));
	TextOut( ps.ps.hdc, 5, 3, ps.lpUser, strlen(ps.lpUser));
	SelectObject( ps.ps.hdc, PreCreateFont(FW_THIN));
	TextOut( ps.ps.hdc, 5, 0x10, ps.lpText, strlen(ps.lpText));
	EndPaint( ps.hWnd, &ps.ps);
	return(0);
   } break;
  case WM_DESTROY:
   {
	LOG("kill timer\n");
	KillTimer(hWnd, TIMER_ID);
	return(0);
   } break;
  default: break;
 }
 return(DefWindowProc(hWnd, msg, wparam, lparam));
}
#define WIN32_LEAN_AND_MEAN   // MFC abschalten
#define WNDCLASSNAME "PopUp"
#define WS_EX_LAYERED		   0x00080000	
#define LWA_COLORKEY			0x00000001
#define LWA_ALPHA			   0x00000002
VOID PopUp(LPCSTR lpUser, LPCSTR lpText)
{
 if(IsWindow(ps.hWnd) != FALSE)
 {
  t=ps.delay;
  Sleep(50);
 }
 t=0;
 WNDCLASS winclass;
 winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
 winclass.lpfnWndProc = WindowProc;
 winclass.cbClsExtra = 0;
 winclass.cbWndExtra = 0;
 winclass.hInstance = ps.hInstance;
 winclass.hIcon = NULL;
 winclass.hCursor = NULL;
 winclass.hbrBackground = (HBRUSH) CreateSolidBrush(ps.bgColor);
 winclass.lpszMenuName = NULL;
 winclass.lpszClassName = WNDCLASSNAME;
  // Windows-Klasse registrieren
 RegisterClass(&winclass);
 ps.lpUser = new char[strlen(lpUser)];
 ps.lpText = new char[strlen(lpText)];
 strcpy(ps.lpUser, lpUser);
 strcpy(ps.lpText, lpText);
 ps.hWnd = FindWindow("Shell_TrayWnd",0); // Get TaskBar handle
 GetWindowRect(ps.hWnd,&ps.ps.rcPaint);
 ps.hWnd = CreateWindowEx (
  WS_EX_LAYERED |
  WS_EX_TOOLWINDOW |
  WS_EX_TOPMOST,
  WNDCLASSNAME,
  "PopUp", 
  WS_POPUP |
  WS_VISIBLE |
  WS_CLIPSIBLINGS,  
  ps.ps.rcPaint.right - 163,
  ps.ps.rcPaint.top - 38,
  160,35,
  NULL,
  NULL,
  ps.hInstance,
  NULL);
 typedef DWORD (WINAPI *PSLWA)(HWND, DWORD, BYTE, DWORD);
 PSLWA pSetLayeredWindowAttributes;
 
 pSetLayeredWindowAttributes = 
  (PSLWA) GetProcAddress(LoadLibrary ("user32"), "SetLayeredWindowAttributes");
 pSetLayeredWindowAttributes (
  ps.hWnd, 
  RGB(255,255,255), 
  ps.transparence,
  LWA_COLORKEY |
  LWA_ALPHA);
 LOGF("set popuptransparence to %d",ps.transparence);
 ShowWindow(ps.hWnd, SW_SHOWNORMAL);
 UpdateWindow(ps.hWnd);
 return;
}
 
Zurück