Prevent application from "APPCRASH"

Hi,

I'm trying to write a code for scrolling on a touchscreen, but half of the time my app crashes (APPCRASH message) (this is not the only application I am writing that has these crashes), so I wonder if it is because of my code and I'd like to know how I can prevent my apps from crashing this way over and over again.

Touchscreen logic code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
     case WM_LBUTTONDOWN :
          ptBeg.x = ptEnd.x = LOWORD (lParam) ;
          ptBeg.y = ptEnd.y = HIWORD (lParam) ;
          starttemp = start;
          
          GetSystemTime (&time);
          tsBeg  = time.wSecond;
          tmsBeg = time.wMilliseconds;
          
          KillTimer (hwnd, TIMERSCROLL);
          InvalidateRect (hwnd, NULL, TRUE) ;
          return 0;
          
     case WM_MOUSEMOVE :
          if (wParam & MK_LBUTTON){
           
             ptEnd.x = LOWORD (lParam) ;
             ptEnd.y = HIWORD (lParam) ;

             start = (ptBeg.y - ptEnd.y) + starttemp;
             if      (start < startmin)           start = startmin;
             else if (start > startmax- cyScreen) start = startmax-cyScreen;
             else {InvalidateRect (hwnd, NULL, TRUE) ;}
          
          }
          return 0;
          
     case WM_LBUTTONUP:
          ptEnd.x = LOWORD (lParam) ;
          ptEnd.y = HIWORD (lParam) ;
          dMouse.x = ptBeg.x - ptEnd.x;
          dMouse.y = ptBeg.y - ptEnd.y;
                     
          GetSystemTime (&time);
          tsEnd  = time.wSecond;
          tmsEnd = time.wMilliseconds;
          dTime = ((tsEnd*1000+tmsEnd) - (tsBeg*1000+tmsBeg)+60000)%60000;
                        
          if (abs(dMouse.y) > 2*cm && dTime <800 && dMouse.y > 2* dMouse.x){
             iCountScroll = 0;
             SetTimer (hwnd, TIMERSCROLL, 100, 0);
          }
                    
          return 0;
          
     case WM_TIMER:
          switch (wParam)
          {
          case TIMERSCROLL:
               iCountScroll +=10;
               start += dMouse.y/(iCountScroll*dTime*dTime/1000000);
               
               if (start < startmin) {
                    start = startmin; 
                    KillTimer (hwnd, TIMERSCROLL);}
               else if (start > startmax - cyScreen) {
                    start = startmax-cyScreen; 
                    KillTimer (hwnd, TIMERSCROLL);}
               else if ((10*iCountScroll/(dTime))>5)
                    KillTimer (hwnd, TIMERSCROLL);
               else {}
               InvalidateRect (hwnd, NULL, TRUE);
               break;
               
          default:
               break;      
          }
          return 0;
          
     case WM_PAINT:
          hdc = BeginPaint (hwnd, &ps) ;
          SetBkMode (hdc, TRANSPARENT);
          SetTextColor (hdc, 0x00FFFFFF);
          
          for (i=start/cyChar; i<(cyScreen + start)/cyChar+1; i++){
              TextOut (hdc, 10 , i*cyChar - start, szBuffer, wsprintf (szBuffer, TEXT ("This is line %i"),i+1));
          }
                    
          EndPaint (hwnd, &ps) ;
          return 0;


I hope someone can help me,


Tim
Topic archived. No new replies allowed.