Solved

Two Easy ActiveX Questions

Posted on 1998-08-09
9
201 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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
 

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

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…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

773 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