Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Two Easy ActiveX Questions

Posted on 1998-08-09
9
Medium Priority
?
216 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.
Suggested Courses

618 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