Link to home
Start Free TrialLog in
Avatar of khlauster
khlausterFlag for United States of America

asked on

Number of controls is limited in dialog!?..

Trying to place about 300 static controls(not at run time!) in dialog..
it does not allow me  more than 254 ..
any idea how to overcome this limitation..
there is nothing about limits on number of controls with VC++ 6.0 documentation.
still need to place my controls through resource editor.. not at run time
Avatar of alb66
alb66
Flag of Italy image

I found a number of forum describing you problem. I don't know why, but it seems that is impossible to add 300 controls in the same dialog with VC6.
Anyway, it seems to me that you should consider to change your interface because I think that 300 static controls are really too much for only one dialog. You can consider to use a grid, a list or some property page.
I do not think that you have a screen with the resolution allowing to show all 300 controls.

Anyway you planned to use a vertical/horizontal scrollers.
This is the answer for your question - you need only few controls that initially will show an info and when the user will click on the scrollers you will update the information and show a next portion of data in the same controls.
Avatar of AndyAinscow
Is this related to your other question about splitting an image into smaller pieces, displaying the pieces in the controls and then having multiple event handlers ?

If yes then why split the image ?  (More code, worse performance)

Just display the image in one picture control, add the event handlers you require for that one control.  Then in the event handler code check where the mouse is and act as if the SMALL image had been clicked (or whatever)
Avatar of khlauster

ASKER

pgnatyuk!

Sorry can not do scroll bars for my task: GUI must remain still.. along with other multiple controls it has to contain image, which must be fragmented into 300 pieces and response to events, for example: if user clicks on some fragment I have to replace this fragment with some other bitmap ..

AndyAinscow!

Yes, this related to my other question..

Basically, if I paint or load entire bitmap I need to know a few things:
Should I load my image on static or paint one right on dialog
how to intercept where was the image clicked
how to replace the clicked fragment with another bitmap of a similar to fragment’s size

I will appreciate a code sample and points up!
Thank you for helping out, experts!
>>Should I load my image on static or paint one right on dialog
>>how to intercept where was the image clicked
>>how to replace the clicked fragment with another bitmap of a similar to fragment’s size
If you are going to have 300 controls, better draw these images directly on the dialog DC. You can store in an array the rectangles of your images and on mouse down/move/up events you will know where is the mouse cursor. So you can replace the image and invalidate the image rectangle. Then call UpdateWindow to update the dialog immediately.

 The attached function will draw a bitmap in a rectangle. So in OnPaint of your dialog you have CPaintDC dc declared. Calculate the size of your rectangles and call this function for each one.


BOOL DrawPicture(HDC hDC, HBITMAP hBitmap, LPRECT lpRect)
{
	if (hBitmap == NULL)
		return FALSE;
	BITMAP bitmap = { 0 };
	GetObject(hBitmap, sizeof(BITMAP), &bitmap);
	HDC hMemDC = CreateCompatibleDC(hDC);
	HBITMAP hBitmapOld = (HBITMAP)SelectObject(hMemDC, hBitmap);
	StretchBlt(hDC, lpRect->left, lpRect->top, 
		lpRect->right - lpRect->left,
		lpRect->bottom - lpRect->top, 
		hMemDC, 0, 0, bitmap.bmWidth, bitmap. bmHeight, 
		SRCCOPY);
	SelectObject(hMemDC, hBitmapOld);
	DeleteDC(hMemDC);
	return TRUE;
}

Open in new window

>>Should I load my image on static or paint one right on dialog
I'd load - then the static can be easily repositioned or resized.

Button click - there is a style setting that accepts mouse actions.

Cursor - GetCursorPos to find the cursor position (look in help files for more info)
pgnatyuk!
thank you, i'll be testing your suggestion with the DrawPicture(HDC hDC, HBITMAP hBitmap, LPRECT lpRect)

AndyAinscow!
To load bitmap on staticis seems to me as a good  idea, yet
I am not clear on how to replace the fragments of the bitmap
I would appreciate the code sample
>>I am not clear on how to replace the fragments of the bitmap

Would this be a permanent or a temporary replacement ?  
this will be a a temporary replacement,
any fragmented piece of a bitmap can be replaced depending on event brought by the user
Then drawing directly to the dc is probably simplest.
It does not redraw a fragment on my image..
i'm trying to use DrawPicture(..) suggested by pgnatyuk
UpdateWindow() gives me a flicker..
//////////////////////////////////////////////////////////////////
void CTestDlg::OnPaint()
{
      CPaintDC dc(this);
      CRect rect;
      GetClientRect(&rect);
      CBitmap bitmap;

      int Left  =  223;
      int Right =  503;
      int Top   =  55;
      int Bottom = 280;

      bitmap.LoadBitmap(IDB_IMG);
      DrawPicture(dc, bitmap, CRect(Left, Top, Right, Bottom));

}


void CTestDlg::InsertPic(int Col,int  Row)
{
      CPaintDC dc(this);

      CRect rect;
      GetClientRect(&rect);
      rect.NormalizeRect();
      CBitmap bitmap;

      int Left  =  223 + Col*14;
      int Right =  237 + Col*14;;
      int Top     = 55 + Row*19;
      int Bottom  = 74 + Row*19;      

      bitmap.LoadBitmap(IDB_FRAGMENT);
       DrawPicture(dc, bitmap, CRect(Left, Top, Right, Bottom));
//                   UpdateWindow();
}

void CTestDlg::OnButton1()
{
      DrawFragment(5,7);
      
}
Yes, of course. You may use it carefully - call InvalidateRect for the needed rectangle, have a double buffering drawing, etc.
Why you have CPaintDC in InsertPict method? CPaintDC can be used in OnPaint only. In that place you need to use CDC.
The function I posted use LPRECT as the third parameter.
It does not redraw, because you could make another mistakes too or a problem in the logic somewhere. Try to this function for one bitmap and one rectangle. Then add few more. And so on.

pgnatyuk!

The image drawing comes out very well in the:

void CTestDlg::OnPaint()
{
CPaintDC dc(this);
……………..
bitmap.LoadBitmap(IDB_IMG);
DrawPicture(dc, bitmap, CRect(Left, Top, Right, Bottom));

}


The problem was in replacing the fragment and, so far I came out with only the following:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CTestDlg::InsertPic(int Col,int  Row, UINT nIDResource, COLORREF penColor)
{

        CClientDC dc(this);


        int Left  =  223 + Col*14;
        int Right =  237 + Col*14;;
        int Top     = 55 + Row*19;
        int Bottom  = 74 + Row*19;

        CPen mypen;
        mypen.CreatePen ( PS_DOT, 1, penColor) ;

 CPen *oldPen = dc.SelectObject ( &mypen ) ;

  //////////////////////////////////////////////////    
 CBrush mybrush (penColor) ;
 CBrush *oldbrush = dc.SelectObject ( &mybrush ) ;

 CBitmap mybitmap ;
 mybitmap.LoadBitmap(nIDResource) ;
 
 mybrush.DeleteObject( ) ;

mybrush.CreatePatternBrush ( &mybitmap ) ;
oldbrush = dc.SelectObject ( &mybrush ) ;
dc.Rectangle ( Left, Top, Right, Bottom ) ;
   
mybrush.DeleteObject( ) ;



}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
It works good except the border around repainted fragment of the bitmap..
I would appreciate if you provide code sample, which would replace the fragment of the bitmap with another bitmap and without a border..
Thanks again
ASKER CERTIFIED SOLUTION
Avatar of pgnatyuk
pgnatyuk
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial