Reference ActiveX controls in SDK programs

Source: Internet
Author: User

Most of the time, I really envy Vb/Delphi programmers. They can easily use various controls to build an application.
However, to use ActiveX controls, we need to look for big ones.
It's unfair to have to do a lot of work by hand on materials for half a day (well, it's much easier to think about hardware-driven programmers ).
Next I will briefly introduce how to reference
ActiveX Control. I use the flash control as an example:
Here I will not talk about it step by step. If you are interested, download the source code :)

Click here
Load engineering source code

// First, contain several com header files
//
To use the ATL container window, you need to initialize a ccommodule and the header file containing atlwin. h.

# Include
Ccommodule
_ Module;
# Include
# Include
# Pragma
Comment (Lib, "ATL ")

//
Introduce the flash control. The path here is the actual path of the flash control on your computer.

# Import
"C:/winnt/system32/macromed/flash. ocx"
Using
Namespace
Shockwaveflashobjects;

//
Initialize in winmain

Int
Apientry
Winmain (hinstance, hinstance hprevinstance, lpstr lpcmdline, int
Ncmdshow)
{
Coinitialize (null );
Atlaxwininit ();
.
.
.
Couninitialize ();
Return
MSG. wparam;
}

// Start creating the ATL container window and obtain the flash control object through querycontrol ().

Lresult
Callback wndproc (hwnd, uint message, wparam, lparam)
{
Static
Caxwindow wincontainer;
Static
Ccomptr pflash;

Switch
(Message)
{
Case
Wm_create:
Rect RC;
Getclientrect (hwnd, & rc );
Wincontainer. Create (hwnd, & rc, lpctstr ("shockwaveflash. shockwaveflash"), ws_child
| Ws_visible );
Hresult hr;
HR = wincontainer. querycontrol (_ uuidof
(Ishockwaveflash), (void
**) & Pflash );
If
(Failed (HR) Return
-1l;
HR = pflash-> put_movie (ccombstr (L ". // sample.swf "));
If
(Succeeded (HR) pflash-> play ();
Break;

.
.
.
Case
Wm_destroy:
Pflash. Release ();
Wincontainer. destroywindow ();
Postquitmessage (0 );
Break;

Default:

Return
Defwindowproc (hwnd, message, wparam, lparam );
}

Return
0l;
}

Now, I can play the Flash Animation in my program,
Happy :)
The following shows how to create a webbrower control in a program:

1. Run the following statement:

# Import

"C:/winnt/system32/macromed/flash. ocx"
Using
Namespace
Shockwaveflashobjects;

Replace:
# Include
"Exdisp. H"

2. Convert object variables
Static
Ccomptr pflash;

Replace:
Static
Ccomptr pwebbrowser;

3.
Set the following statement
Rect RC;
Getclientrect (hwnd, & rc );
Wincontainer. Create (hwnd, & rc, lpctstr ("shockwaveflash. shockwaveflash"), ws_child
| Ws_visible );
Hresult hr;
HR = wincontainer. querycontrol (_ uuidof
(Ishockwaveflash), (void
**) & Pflash );
If
(Failed (HR) Return
-1l;
HR = pflash-> put_movie (ccombstr (L ". // sample.swf "));
If
(Succeeded (HR) pflash-> play ();

Replace
To:
Rect RC;
Getclientrect (hwnd, & rc );
Wincontainer. Create (hwnd, & rc, lpctstr ("Microsoft. iexplorer.4"), ws_child
| Ws_visible );
Hresult hr;
HR = wincontainer. querycontrol (_ uuidof
(Iwebbrowser2), (void
**) & Pwebbrowser );
If
(Failed (HR) Return
-1l;
Variant URL;
Variant V;
URL. Vt = vt_bstr;
URL. bstrval
= Sysallocstring (L"
Http://www.cppblog.com/azhisoft/


");
HR =
Pwebbrowser-> navigate2 (& URL, & V, & V );

4.
Last point
Pflash. Release ();
Wincontainer. destroywindow ();
Postquitmessage (0 );

Replace
Replace:
Pwebbrowser. Release ();
Wincontainer. destroywindow ();
Postquitmessage (0 );

This
I hope it will help you learn from others !!!
In the future, you don't need to envy the programmers of VB/Delphi, because we can do the same. Haha, I'm glad.

Original link http://www.cppblog.com/azhisoft/articles/426.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.