Solved

Two Easy ActiveX Questions

Posted on 1998-08-09
9
199 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
  • 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
 
LVL 2

Accepted Solution

by:
igroove earned 50 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now