Thread: Scroll bars.......

  1. #1
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    Scroll bars.......

    They are going to be the Death of me.......hopefully not.

    Ok so I scroll a screen, I use ScrollWindowEX with SW_ERASE as the last parameter to this function. I am hoping that his will cause an WM_PAINT message and that the whole screen will be painted in white and then repainting the text in the window. This is not happening.....I included the .exe so you can see the behavior and please tell me what I should do. I have been with this problem for the past three days and I have not been able to make any progress with my program. Thanks here's the code.....

    Click on the pagare button to see the text in the screen



    Code:
    
    
    
    
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    
    	 
         HDC         hdc ;
         PAINTSTRUCT ps ;
    	 TEXTMETRIC  TextMetrics;
    	 static int CharWidth,CharHeight,CharCaps;
    	 static int ClientX,ClientY;
    	 char Buffer[20];
    	 static SCROLLINFO  si;
    
    	 static int iVscrollPos;
    	 static int iHscrollPos;
    
    	
    	 static Client Cliente;
    	 
         RECT        Rect ;
    	 
         
         switch (message)
         {
    
    
    	 case WM_SIZE:
    
    		 {
    
    
    		ClientX = LOWORD (lParam) ;
    		ClientY = HIWORD (lParam) ;
    
    		               // Set vertical scroll bar range and page size
    
            si.cbSize = sizeof (si) ;
            si.fMask  = SIF_ALL|SIF_DISABLENOSCROLL ;
            si.nMin   = 0 ;
            si.nMax   = NUMLINES - 1 ;
            si.nPage  = NUMLINES-5 ;
            SetScrollInfo (hwnd, SB_VERT, &si, TRUE) ;
    	
    
    
    		 }
    
    
    		
    	
    		
    	 case WM_COMMAND:
    		 switch (LOWORD(wParam))
    		 {
    
    		case ID_SAVE:
    
    			if(SaveClientInfo(NewClientWindowHandle)!=Success)
    			{
    
    				MessageBox(hwnd,"did not save right","asflkasfdlkdf!!!",MB_OK);
    			}
    			
    			
    			break;
    
    
    			case ID_NEW:
    
    			NewClientWindowHandle = CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(ID_DIALOGNEW), hwnd, ClienteProc);
    			ShowWindow(NewClientWindowHandle,SW_SHOW);			
    			GetClientRect(hwnd,&Rect);
    			InvalidateRect(hwnd,&Rect,TRUE);
    
    			break;
    
    			case ID_PRINT:
    			//MessageBox(NULL, "Goodbye, cruel world!", "Note", MB_OK);
    		    Print=TRUE;
    
    	
    			break;
    
    			case ID_PAGARENOSHOW:
    				ViewPagare=FALSE;
    
    				break;
    
    			
    
    			case ID_COPYRIGHT:
    
    				DialogBox (hInstance, MAKEINTRESOURCE(IDD_DIALOG1),hwnd, CopyRightNotice) ;
    
    				break;
    
    				
    
    
    			case ID_EXIT:
    			SendMessage (hwnd, WM_CLOSE, 0, 0) ;
    
              break ;
    				
    		 }
    
    
         case WM_CREATE:
    		 {
    
    
    			 hdc=GetDC(hwnd);
    			 GetTextMetrics(hdc,&TextMetrics);
    			 CharWidth=TextMetrics.tmAveCharWidth;
    			 CharHeight=TextMetrics.tmHeight+TextMetrics.tmExternalLeading;
    			 CharCaps=(TextMetrics.tmPitchAndFamily & 1 ? 3 : 2) * CharWidth / 2 ;
    
    			         si.cbSize = sizeof (si) ;
    			 si.fMask  = SIF_RANGE | SIF_PAGE|SIF_DISABLENOSCROLL ;
    			 si.nMin   = 0 ;
    			 si.nMax   = NUMLINES - 1 ;
    			 si.nPage  = NUMLINES-5 ;
    			 SetScrollInfo (hwnd, SB_VERT, &si, TRUE) ;
    
    			 ReleaseDC(hwnd,hdc);
    			 AddToolBar(hwnd,IDC_TOOLBAR);
    
    			 //initialize the save as and open dialog structure
    			 SaveDialog(hwnd);
    			
             
              return 0;
    		 }
    
              
         case WM_PAINT:
    		 {
    
    
    			 
    
              hdc = BeginPaint (hwnd, &ps) ;
    
    		 if (ViewPagare)
    		  {
    			 
    
    			 si.cbSize=sizeof si;
    			 si.fMask=SIF_ALL;
    			 GetScrollInfo(hwnd,SB_VERT,&si);
    			 int Line=si.nPos;
    			 
    	
    
    			 
    		  int i;
    		  for (i=0;i<NUMLINES;i++)
    			//displaying pagare on the screen  
    
    		  {
    					  
    		  char string[]="hi";
    		  TextOut(hdc,20,Line,PagareLines[i].Array,lstrlen(PagareLines[i].Array));
    		  Line+=15;
    		  SetTextAlign(hdc,TA_LEFT);
    		  SetBkMode(hdc, TRANSPARENT);
    		  
    	
    		  
    		  }
    
    		
    
    		  }
    
    
    
    
    		 //print pagare
    		 //if Print has been se to true print pagare
    
    		 if(Print)
    
    		 {
    
    			PrintingState=PrintPagare(hwnd,Print);
    			Print=PrintingState;
    
    		 }
    
    		  
    
    
    	           
              EndPaint (hwnd, &ps) ;
              return 0 ;
    		 }
    
    
    		  case WM_VSCROLL:
                   // Get all the vertical scroll bar information
    
    		  si.cbSize = sizeof (si) ;
              si.fMask  = SIF_ALL ;
    		  iVscrollPos=si.nPos;
              GetScrollInfo (hwnd, SB_VERT, &si) ;
    
    
    
              switch (LOWORD (wParam))
              {
              case SB_LINEUP:
    			  iVscrollPos -=1;
    			 
    				  
                  
                   break ;
                   
              case SB_LINEDOWN:
    			  iVscrollPos +=1;
    			  
    				  
    			  break;
    
    		  default: break;
    
    		  }
    
    
    		  
    			   si.fMask = SIF_POS ;
    			   SetScrollInfo (hwnd, SB_VERT, &si, TRUE) ;
    			   GetScrollInfo (hwnd, SB_VERT, &si) ;
    
    
    	
                   ScrollWindowEx(hwnd,NULL,CharHeight*(iVscrollPos-si.nPos),NULL,NULL,NULL,NULL,SW_ERASE);
    			   UpdateWindow (hwnd) ;
    			   
    
    	   return 0;
    
    
    
    
              
         case WM_DESTROY:
              PostQuitMessage (0) ;
              return 0 ;
         }
         return DefWindowProc (hwnd, message, wParam, lParam) ;
    }
    where ViewPagare is a flag that is set when you click on the pagare button.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  2. #2
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    here's the code in notepad.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  3. #3
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    I think that for some reason is not processing a Paint Message until you resize the window or something like that, because when you do it places the text and toolbar in the original position. Very nicesly looking. here's the code in notepad............please or point me to some good resources, BTW I've looked at Petzold's and the tutorial on msdn.com
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    You could simply call UpdateWindow.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    EUREKA!!!!!!

    yeah!!! it's finally scrolling.........

    for some reason neither UpdateWindow nor SendMessage (with WM_PAINT as one of the arguments) were causing a WM_PAINT message. So I had to call Invalidate Window........and fix some other stuff...........

    Code:
    		  /* Get the current scroll bar information
    		  Initialize the beginning of the line */
    
    		  si.cbSize=sizeof si;
    		  si.fMask=SIF_ALL;
    		  GetScrollInfo(hwnd,SB_VERT,&si);
    		  int Line;
    		  int Position;
    		  Position=si.nPos;
    
    		  /* We multiply by negative one to make sure
    		  that we paint the line at the oposite of where the
    		  scroll bar is going and the line is displayed at a ratio of
    		  CharHeight meaning that it will increment one line of text 
    		  at the time or CharHeight*/
    
    		  Line=(Position*-1)*CharHeight;
    		  Line+=60;//to make sure the text is not displayed 
    		  //directly at the top of the window.



    Code:
    
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    
    	 
         HDC         hdc ;
         PAINTSTRUCT ps ;
    	 TEXTMETRIC  TextMetrics;
    	 static int  CharWidth,CharHeight,CharCaps;
    	 static int  ClientX,ClientY;
    	 char		 Buffer[20];
    	 static	SCROLLINFO  si;
    
    	 static int iVscrollPos;
    	 static int iHscrollPos;
    
    	
    	 static		Client Cliente;
    	 
         RECT       Rect ;
    	 
         
         switch (message)
         {
    
    
    	 case WM_SIZE:
    
    		 {
    
    
    		ClientX = LOWORD (lParam) ;
    		ClientY = HIWORD (lParam) ;
    
    		// Set vertical scroll bar range and page size
    
            si.cbSize = sizeof (si) ;
            si.fMask  = SIF_ALL|SIF_DISABLENOSCROLL ;
            si.nMin   = 0 ;
            si.nMax   = NUMLINES - 1 ;
            si.nPage  = NUMLINES-5 ;
            SetScrollInfo (hwnd, SB_VERT, &si, TRUE) ;
    	
    
    
    		 }
    
    
    		
    	
    		
    	 case WM_COMMAND:
    		 switch (LOWORD(wParam))
    		 {
    
    		case ID_SAVE:
    
    			if(SaveClientInfo(NewClientWindowHandle)!=Success)
    			{
    
    				MessageBox(hwnd,"did not save right","asflkasfdlkdf!!!",MB_OK);
    			}
    			
    			
    			break;
    
    
    			case ID_NEW:
    
    			NewClientWindowHandle = CreateDialog(GetModuleHandle(NULL),MAKEINTRESOURCE(ID_DIALOGNEW), hwnd, ClienteProc);
    			ShowWindow(NewClientWindowHandle,SW_SHOW);			
    			GetClientRect(hwnd,&Rect);
    			InvalidateRect(hwnd,&Rect,TRUE);
    
    			break;
    
    			case ID_PRINT:
    			//MessageBox(NULL, "Goodbye, cruel world!", "Note", MB_OK);
    		    Print=TRUE;
    
    	
    			break;
    
    			case ID_PAGARENOSHOW:
    				 ViewPagare=FALSE;
    				 InvalidateRect(hwnd,NULL,TRUE);
    
    				break;
    
    			
    
    			case ID_COPYRIGHT:
    
    				DialogBox (hInstance, MAKEINTRESOURCE(IDD_DIALOG1),hwnd, CopyRightNotice) ;
    
    				break;
    
    				
    
    
    				case ID_EXIT:
    				SendMessage (hwnd, WM_CLOSE, 0, 0) ;
    
              break ;
    				
    		 }
    
    
         case WM_CREATE:
    		 {
    
    
    			 hdc=GetDC(hwnd);
    			 GetTextMetrics(hdc,&TextMetrics);
    			 CharWidth=TextMetrics.tmAveCharWidth;
    			 CharHeight=TextMetrics.tmHeight+TextMetrics.tmExternalLeading;
    			 CharCaps=(TextMetrics.tmPitchAndFamily & 1 ? 3 : 2) * CharWidth / 2 ;
    
    			 si.cbSize = sizeof (si) ;
    			 si.fMask  = SIF_RANGE | SIF_PAGE|SIF_DISABLENOSCROLL ;
    			 si.nMin   = 0 ;
    			 si.nMax   = NUMLINES - 1 ;
    			 si.nPage  = NUMLINES-5 ;
    			 SetScrollInfo (hwnd, SB_VERT, &si, TRUE) ;
    
    			 ReleaseDC(hwnd,hdc);
    			 AddToolBar(hwnd,IDC_TOOLBAR);
    
    			 //initialize the save as and open dialog structure
    			 SaveDialog(hwnd);
    			
             
              return 0;
    		 }
    
              
         case WM_PAINT:
    		 {
    
    
    			 
    
              hdc = BeginPaint (hwnd, &ps) ;
    
    		  GetClientRect(hwnd,&Rect);
    		  FillRect(hdc,&Rect,WHITE_BRUSH);
    
    		 if (ViewPagare)
    		  {
    			 
    
    		  /* Get the current scroll bar information
    		  Initialize the beginning of the line */
    
    		  si.cbSize=sizeof si;
    		  si.fMask=SIF_ALL;
    		  GetScrollInfo(hwnd,SB_VERT,&si);
    		  int Line;
    		  int Position;
    		  Position=si.nPos;
    
    		  /* We multiply by negative one to make sure
    		  that we paint the line at the oposite of where the
    		  scroll bar is going and the line is displayed at a ratio of
    		  CharHeight meaning that it will increment one line of text 
    		  at the time or CharHeight*/
    
    		  Line=(Position*-1)*CharHeight;
    		  Line+=60;//to make sure the text is not displayed 
    		  //directly at the top of the window. 
    			 
    			 
    		  int i;
    		  for (i=0;i<NUMLINES;i++)
    			//displaying pagare on the screen  
    
    		  {
    					  
    		  char string[]="hi";
    		  TextOut(hdc,20,Line,PagareLines[i].Array,lstrlen(PagareLines[i].Array));
    		  Line+=15;
    		  SetTextAlign(hdc,TA_LEFT);
    		  SetBkMode(hdc, TRANSPARENT);
    		  
    	
    		  
    		  }
    
    		
    
    		  }
    
    
    
    
    		 //print pagare
    		 //if Print has been se to true print pagare
    
    		 if(Print)
    
    		 {
    
    			PrintingState=PrintPagare(hwnd,Print);
    			Print=PrintingState;
    
    		 }
    
    
    	           
              EndPaint (hwnd, &ps) ;
              return 0 ;
    		 }
    
    
    
    
    		  case WM_VSCROLL:
                   // Get all the vertical scroll bar information
    		  
    
    		  si.cbSize = sizeof (si) ;
              si.fMask  = SIF_ALL ;
    		  iVscrollPos=si.nPos;
              GetScrollInfo (hwnd, SB_VERT, &si) ;
    
    
    
              switch (LOWORD (wParam))
              {
              case SB_LINEUP:
    			  iVscrollPos -=1;
    			 
    				  
                  
                   break ;
                   
              case SB_LINEDOWN:
    			  iVscrollPos +=1;
    			  
    				  
    			  break;
    
    		 
    
    		  }
    
    
    		  si.nPos=iVscrollPos;
      		  si.fMask = SIF_POS ;
    		  SetScrollInfo (hwnd, SB_VERT, &si, TRUE) ;
    		  GetScrollInfo (hwnd, SB_VERT, &si) ;
    
    
    		  //scroll our window by one text line
    		  //and call InvalidateRect
    	
              ScrollWindowEx(hwnd,NULL,CharHeight*(si.nPos-iVscrollPos),NULL,NULL,NULL,NULL,SW_ERASE);
    		  UpdateWindow (hwnd) ;
    		  InvalidateRect(hwnd,NULL,TRUE);
    		  			   
    
    		  return 0;
    
    
    
    
              
         case WM_DESTROY:
              PostQuitMessage (0) ;
              return 0 ;
         }
         return DefWindowProc (hwnd, message, wParam, lParam) ;
    }
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  6. #6
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    There's still some minor bugs to work out ie when resizing...
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Scroll Bars Are Scrolling Me Crazy
    By Iyouboushi in forum C# Programming
    Replies: 6
    Last Post: 03-03-2006, 01:43 PM
  2. Scroll bars
    By bigdan43 in forum C++ Programming
    Replies: 5
    Last Post: 04-19-2005, 12:05 PM
  3. Scroll Bars and Focus
    By Thantos in forum Windows Programming
    Replies: 1
    Last Post: 08-21-2003, 11:57 AM
  4. Horizontal Scroll Bars with CListBox
    By Malek in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2003, 09:58 PM
  5. Scroll Bars
    By bc17 in forum Windows Programming
    Replies: 2
    Last Post: 02-21-2003, 03:15 PM