15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Restricting the size of an OCX

Norman_Almond@Europe.notes.pw.com
Monday, September 30, 1996

Environment: Environment: VC++ 4.2, Win 95
Subject:     Restricting the size of an OCX

Hi All

I currently developing a specialized calendar widget in the form of a child 
window.
I'm am now converting this project into an OCX (No Problemo!).
The problem I am having is:

1.  I want to set the OCX at a particular size in the  CCalCtrl::OnCreate
    function and update the calendar window without putting any code in
    CCalCtrl::OnDraw function.

2.  I then want to prevent the OCX from being resized when in design mode.

I can set the size of the control by using SetControlSize but the child window 
doesn't
paint correctly.
I've looked thru MSDN and Samples nothing seems to prevent any OCX from 
resizing.
Has anyone come across any code to do the above.

TIA.

Regards

// NormSki



SBERTRAN.US.ORACLE.COM -- SBERTRAN@us.oracle.com
Thursday, October 03, 1996

[Mini-digest: 2 responses]

To restrict the control's size during design time: 
 
1. In the constructor of the control class (CCalCtrl::CCalCtrl for you), add a 
call to SetInitialSize: 
 
	// Restrict size of control 
	SetInitialSize(cx, cy) 
 
where cx is the initial width of the control, and cy is the initial height of 
the control.  If your control is represented in design time by an icon, then 
cx should probably be 15 and cy should be 14.  If it is a graphical 
representation, then just play around with the width and height. 
 
2. If your control is represented by an icon, override the OnDraw function (if 
you haven't already) and add the following code: 
 
	CBitmap bitmap; 
	BITMAP  bmp; 
	CPictureHolder picHolder; 
	CRect rcSrcBounds; 
 
	// Load ORACD bitmap 
	bitmap.LoadBitmap(IDB_ORACD); 
	bitmap.GetObject(sizeof(BITMAP), &bmp); 
	rcSrcBounds.right = bmp.bmWidth; 
	rcSrcBounds.bottom = bmp.bmHeight; 
 
	// Create picture and render 
	picHolder.CreateFromBitmap((HBITMAP)bitmap.m_hObject, NULL, FALSE); 
	picHolder.Render(pdc, rcBounds, rcSrcBounds); 
 
This code will load your control's icon and display it when the control is 
drawn. 
Also override the OnSetExtent function of your control class and add this code: 
 
	// Some containers can't handle the control directly 
	// modifying the provided lpSizeL structure. So we 
	// create a copy to modify and pass it on to the COleControl 
	// implementation 
	SIZEL sizeL; 
 
	// Ensure that the icon is always sized 
	// as 32x32 pixels 
	CDC cdc; 
	cdc.CreateCompatibleDC(NULL); 
	CSize size(15,14); 
 
	// Convert the device points to HIMETRIC 
	// OLE uses HIMETRICE measurements 
	cdc.DPtoHIMETRIC(&size); 
	sizeL.cx = size.cx; 
	sizeL.cy = size.cy; 
 
	// Call the parent implementation 
	return COleControl::OnSetExtent(&sizeL); 
 
This code will ensure that the control remains the size of the icon when its 
extent needs to be changed (e.g. when the user resizes the control). 
 
Hope this helps... 
 
Shawn Bertrand, Developer 
Oracle Corporation-OLAP Products Division 
200 Fifth Avenue    |  mail:  sbertran@us.oracle.com 
Waltham, MA  02154  |  phone: (617) 684-5690 
 
"If you drink, don't drive.  Don't even putt."  - Dean Martin

-----From: "Julius Hamelberg" 

     
     You'll need to override:
     
     OnSetExtent(LPSIZEL lpSizeL);
     
     Take a look at:
     
     http://www.sky.net/~toma/faqgen.htm#Restrict
     
     
     - J
     




| Вернуться в корень Архива |