• Flash GUI for Your EXE Using Minimalistic Approach


    http://www.codeproject.com/KB/cpp/FlashGui.aspx

    Introduction

    Well we all know how boring gui today applications have. Especially when compared to even subparflash web site. So how about nice flashy flashy gui for your super application ?

    Embed flash in 3 lines of code

    #include <windows.h>
    
    
    int WINAPI WinMain(HINSTANCE inst,HINSTANCE prev,LPSTR cmd,int show) {
        MSG   msg={0}; void* init = GetProcAddress(LoadLibrary("atl"),"AtlAxWinInit"); _asm call init;
        CreateWindow("AtlAxWin", "c:\\WINDOWS\\Help\\Tours\\mmTour\\segment2.swf", WS_VISIBLE|WS_POPUP,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),0,0,0,0);
        while (GetMessage(&msg,0,0,0)) DispatchMessage(&msg);
    };
    
    

    Also worth noting is fact that you can insert swf file as resource and have everything in one executable. Path to yourflash (second param to createwindow) would be then in this format "res://YOUR_EXE_PATH/YOUR_RES_NAME"

    Ehm... and what about 3D VRML Gui ?

    In fact it is possible to render ANY file format using ANY protocol that Internet Explorer is able. Just go ahead and tryZIP, PDF, JPG, VRML, DOC,CHM, AVI, MP3,etc... via MSHtml:,File:, Res:, Http:, Ftp:, etc. The only problem is if you wana react to user interactions in those documents. Right now i dig inside IE to find solution but let's focus to what this article is about.

    React to flash events

    After you play enough with previous sample you will notice that it's missing one important element.
    It's missing place where we catch events from flash. So here is another sample where i dig thru all the interfaces up to IShockwaveFlash. And i know what you think.
    it's 10 more lines but hey, still better than class galore ;) And as for the second usedflash. I must give credit to very talented artist named Stephane Bourez. That interface is really innovative and fresh light at the same time.

    #include <windows.h>
    #include <exdisp.h>
    #include <mshtmlc.h>
    
    #import  "PROGID:ShockwaveFlash.ShockwaveFlash" no_namespace raw_interfaces_only
    
    #define MsgLoopWhile(a) while(a) { GetMessage(&msg,0,0,0); DispatchMessage(&msg); }
    
    typedef HRESULT (WINAPI *LPAtlAxWinInit)   ();
    typedef HRESULT (WINAPI *LPAtlAxGetControl)(HWND hwnd, IUnknown** unk);
    
    int WINAPI WinMain(HINSTANCE inst,HINSTANCE prev,LPSTR cmd,int show) {
        LPAtlAxWinInit    AtlAxWinInit3    = (LPAtlAxWinInit)   GetProcAddress(LoadLibrary("atl"),"AtlAxWinInit"); // Atl.dll v 3.0 is part of the windows
    
        LPAtlAxGetControl AtlAxGetControl3 = (LPAtlAxGetControl)GetProcAddress(LoadLibrary("atl"),"AtlAxGetControl"); 
        MSG    msg;   HRESULT  hr = AtlAxWinInit3(); 
        HWND   hwnd = CreateWindow("AtlAxWin","http://www.screenvader.com/_ROOT.swf",WS_VISIBLE|WS_POPUP,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),0,0,0,0); 
    
        IUnknown*       unkn;          hr = AtlAxGetControl3(hwnd,&unkn);
        IWebBrowser2*   brow;          hr = unkn->QueryInterface(__uuidof(IWebBrowser2),(void**)&brow);
        IDispatch*      disp;               MsgLoopWhile( !brow->get_Document(&disp) && !disp );         // Document loading loop
    
        IHTMLDocument2* html;          hr = disp->QueryInterface(__uuidof(IHTMLDocument2),(void**)&html);
        IHTMLElementCollection* elems; hr = html->get_embeds(&elems); VARIANT id; VariantInit(&id);
                                            MsgLoopWhile( elems && !elems->item(id,id,&disp) && !disp ); // Document parsing loop
    
        IShockwaveFlash* flash=0;      hr = disp->QueryInterface(__uuidof(IShockwaveFlash),(void**)&flash);
        
        while (GetMessage(&msg,0,0,0) && flash) { 
            BSTR  val,var=L"MyEvent";  hr = flash->GetVariable(var,&val);  // Set this var/s in flash
    
            long frame;                hr = flash->CurrentFrame(&frame);  
            DispatchMessage( &msg); 
        }
    };

    Change Flash content from C++

    Text fields can be connected to variables names, thus alowing us to display dynamicflash content. For details see http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_16184 Then just use method SetVariable onflash object.

    Transparent Flash

    Well this one is a bit challenging and not yet finished. Rendering is usualy split to 2 steps. Clear background and draw rest. To gain control over how backround is filled we need to activateflash activex control in so called "windowless" mode. One way to do this with ATL is with AtlAxAttachControl (Thx for this info goes to JaeWook Choi )

    // create invisible container window
    
    HWND ctrl = CreateWindowEx(0,"AtlAxWin",0,0,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),0,0,0,0);
    IShockwaveFlash* flash=0; hr = CoCreateInstance(__uuidof(ShockwaveFlash),0,CLSCTX_ALL, __uuidof(IShockwaveFlash), (void **)&flash); 
                              hr = flash->put_WMode(L"transparent"); 
                              hr = AtlAxAttachControl(flash,ctrl,0);
    IViewObjectEx*    view=0; hr = flash->QueryInterface(__uuidof(IViewObjectEx),(void **)&view);
                              hr = flash->put_Movie(L"c:\\WINDOWS\\Help\\Tours\\mmTour\\segment2.swf");
    ... 
    // In msg loop update background and render (to 2nd visible window) 
    
    hr = view->Draw(DVASPECT_CONTENT, 0, 0, 0, 0, GetDC(hwnd), 0, 0, 0, 0);
    

    Points of interest

    Nice thing is that you can react to frame positions on allready existing .swf files or by checking variable values (if you know them for that swf). For your ownflashes you decide variable/s name/s that you will set inflash and monitor in exe msg loop. Also the path to swf file in 3 line sample is for Windows XP owners. Other users should put some other url/path to some other file.

    You may need PlatformSDK (Visual C++ 6)

    For example Visual c++ 6 etc does not contain PlatformSDK (thus mshtmlc.h) .But since this is MIDL generated file you should probably be able to generate it from mshtml ocx with MIDL compiler. Also thanks goes to Mirjini who found out that following changes are needed for VC++ 6:

    // An old Visual c++ 6 #import statement doesn't supports PROGID ?
    
    #import "C:\WINDOWS\system32\Macromed\Flash\Flash.ocx"
    #include "Debug\Flash.tlh"
    
    

    Now go and create some nice animated breath-taking GUI for your exe.
    And remember

    "There is always simpler way".

  • 相关阅读:
    使用清华源进行pip install
    BERT和ULMFIT embedding比较文本分类结果
    Ubuntu16.04更新python3.5到python3.7
    base64方式显示控件
    在使用redis做缓存后,mybatis的延迟加载失效
    springboot:redis反序列化发生类型转换错误
    eclipse :代码自动补全不生效解决办法
    微信扫码支付:问题集锦
    微信扫码支付(4):统一下单
    微信扫码支付(3):获取验签秘钥
  • 原文地址:https://www.cnblogs.com/xiayong123/p/3717181.html
Copyright © 2020-2023  润新知