Solved

Two Easy ActiveX Questions

Posted on 1998-08-09
9
206 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 
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

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

Suggested Solutions

Title # Comments Views Activity
What is sub-make ? 2 71
Where are the c++ header files to use in Eclipse? 4 25
C++ Code Issue 4 26
find Speed using GPS latitude & longitude 4 47
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 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.

820 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