?
Solved

Two Easy ActiveX Questions

Posted on 1998-08-09
9
Medium Priority
?
214 Views
Last Modified: 2010-04-10
Questions:
      1 - How do I insert an icon into the ActiveX Control?
      2 - How do I prevent this ActiveX from Changing dimensions (at design and run time).
Regards
(NB: Its behaviour should be similar to a Timer Control (in VB) or a MSCOmm)
0
Comment
Question by:Shaheen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 

Author Comment

by:Shaheen
ID: 1169817
Edited text of question
0
 
LVL 2

Expert Comment

by:igroove
ID: 1169818
By icon, I would think you mean for the whole .OCX file, right?  If so, just add an icon to the resource.  Right click and get it's properties (ID, filename, etc).  For the ID, rename it as you wish, and put "= 101" after it.  This makes it the default icon for the file, e.g.:  IDI_MYOCXICON = 101

As far as the sizing, you can set the initial size in your Control's constructor by calling:
  SetInitialSize(XSize, YSize);

To prevent design/runtime sizing, handle it in the appropriate
COleControl member, perhaps OnSetExtent() or something like that.

0
 

Author Comment

by:Shaheen
ID: 1169819
can you please be more illustrative about the icon business?


0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Accepted Solution

by:
igroove earned 150 total points
ID: 1169820
Ok.  In your OCX project, view the resources in the workspace
view.  If you don't see any icons (which by default, you wouldn't), then right click and choose Insert..., pick Icon from the list box, or alternately, insert one from the Resource toolbar.  This icon should have the MFC picture in cubes thingy that you get from AppWizard projects.  Ok.  You can get to it's properties by hitting Alt+Enter, or right clicking (or going to the File menu) and selecting Properties...; you should see a box with an IDI_ICON1 in it.  That's the resource name.  Change it to "IDI_MYOCXICON = 101" (without the quotes).  You can pick the filename in a box below that one.  This makes it the default icon for your ActiveX control.  After that, you just paint it to your hearts content.  Also, be aware that the icon is 32x32 pixels, and supports a second one that's 16x16.  If you don't want the 16x16, then choose Image|Delete Image when you have the 16x16 one selected.  You can also add a new, larger, or more coloured one too.  It all goes in the .ico icon file.

0
 

Author Comment

by:Shaheen
ID: 1169821
can this icon be drawn on a form at design time (using the ActiveX control)?
0
 
LVL 2

Expert Comment

by:igroove
ID: 1169822
BTW, to limit the resizing of your control, override the OnSetExtend() method.  The method accepts one parameter, a pointer to a SIZEL structure that holds a HIMETRIC size.  If you're not sure what to do with the size, just take your size in pixels and convert it to HIMETRIC and compare it to the parameter passes in OnSetExtent().  If you're happy with the size, you can return TRUE, otherwise, if you don't like it, return FALSE.  If you don't want ANY resizing, just return FALSE and forget bothering with the parameter.  Here's the OnSetExtent() signature:

virtual BOOL COleControl::OnSetExtent(LPSIZEL lpSizeL)

The SIZEL structure is identical to SIZE, but uses Long integers for the size in HIMETRIC units.
The MFC documentation is unclear using CDC::HIMETRICToDP to convert HIMETRICs to SIZEs, but you can:

CDC* pMyDC = GetDC();  // get the control's DC
SIZE mySize;

mySize.cx = /* your horizontal required size in pixels */
mySize.cy = /* your vertical required size in pixels */

pMyDC->DPToHIMETRIC(&mySize);  // conversion

ReleaseDC(pMyDC); // done

// now just compare lpSizeL
BOOL bOK=(mySize.cx <= lpSizeL.cx) && (mySize.cy <= lpSizeL.cy);

return bOk;

--

At least that's supposed to work ;)


0
 
LVL 2

Expert Comment

by:igroove
ID: 1169823
If not, then a little hunting in the online help won't hurt either of us ;)
0
 
LVL 2

Expert Comment

by:igroove
ID: 1169824
As far as "drawing" an Icon in the icon's design-time, just add an icon, like you did above to make the OCX icon, then
load it using the windows ::LoadIcon() API.  You'll draw it using a few calls to paint it in your OnDraw() override:

void CMyOCX::OnDraw(CDC* pdc, ...) {
 // something similar to this
 pDC->FillSolidRect(rcBounds, ::GetSysColor(COLOR_3DFACE));

 HINSTANCE hInst = AfxGetResourceHandle();
 HICON hIcon = ::LoadIcon(hInst, IDI_MYPICTUREICON);

 if (hIcon) {
  pdc->DrawIcon(0, 0, hIcon);  // if you want your icon at 0, 0
 }
}

There 'tis.

0
 

Author Comment

by:Shaheen
ID: 1169825
Thank you for your help
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question