WIN32 API在图片中控制c。打开JPG ++ [英] win32 API open a jpg in a picture control c++

查看:676
本文介绍了WIN32 API在图片中控制c。打开JPG ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有打印JPG到图片控件的矩形(即我建立与ResEdit)的方式,应打印图像的动作是区分IDC_BUTTON1:和目标我想观看的图像是一个与ID图片控制:IDC_STATIC

i want to know if there's a way to print a jpg onto a picture control rectangle (that i build with ResEdit) the action that should print the image is case IDC_BUTTON1: and the target i want to view the image is in a picture control with the id: IDC_STATIC

BOOL CALLBACK AppDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
  switch(uMsg)
  {

  case WM_INITDIALOG:
      DragAcceptFiles(hDlg,true);
    SetClassLongPtr(hDlg, GCLP_HICON, (long)LoadIcon(0, IDI_APPLICATION));
    return 1;
  case WM_COMMAND:
   switch(wParam)
    {
    case IDOK:
  return 0;
case IDCANCEL:
  EndDialog(hDlg, 0);
}
 switch(wParam)
        {
            case IDC_BUTTON1:
               ShellExecute(hDlg,
         "open",
         "C:\immagine1.jpg",
         NULL,
         NULL,
         SW_SHOWDEFAULT);
            break;
        }

  switch(wParam)
        {
            case IDC_BUTTON4:
               ShellExecute(hDlg,
         "open",
         "C:\log.txt",
         NULL,
         NULL,
         SW_SHOWDEFAULT);
            break;
        }






  }
  return 0;
}

而不是使用shell执行该打开默认的浏览器谢谢大家。

instead of using shell execute that open the default viewer thank you all

推荐答案

OleLoadPicturePath API函数可以加载一个JPEG文件。

The OleLoadPicturePath API function can load a JPEG file.

然后,它只是一个访问该位的问题。

Then it's just a matter of accessing the bits.

另外还有 Windows图像处理组件 API,但我还没有使用的。

There's also the Windows Imaging Component API, but I haven't used that.

我怀疑它同样适用,虽然,这可能是比处理与OLE的东西简单,但在这里我举例说明 OleLoadPicturePath

I suspect that it also works, though, and it may be simpler than dealing with the OLE stuff, but here I exemplify OleLoadPicturePath.

努力适应低于code之前,您应该:

Before trying to adapt the code below, you should:


  • 确认画面控制资源的类型设置为位图(实际上,在.RC文字水平,它具有 SS_BITMAP 样式)

的ID更改为,而不是唯一的东西, IDC_STATIC

Change the ID to something unique, instead of IDC_STATIC.

#include <header_wrapper/olectl_h.h>        // IPicture
#include <header_wrapper/windows_h.h>
#include "resource.h"       // IDD_DEMO_DIALOG, IDC_PICTURE

#include <progrock/cppx/throwx.h>           // hopefully, throwX, std::exception
#include <progrock/cppx/size.h>             // size
#include <progrock/winapi/path.h>           // *
#include <progrock/winapi/ComPointer.h>     // ComPointer
using namespace progrock;

#include <assert.h>         // assert
#include <iostream>
#include <stdlib.h>         // EXIT_FAILURE, EXIT_SUCCESS
using namespace std;

using cppx::hopefully;
using cppx::size;
using cppx::throwX;

using winapi::String;

struct IsHrSuccess
{
    friend bool operator>>( HRESULT const hr, IsHrSuccess const& )
    {
        return SUCCEEDED( hr );
    }
};

IsHrSuccess const   isHrSuccess = IsHrSuccess();

short kindOf( IPicture const& pic )
{
    short kind  = 0;
    const_cast< IPicture& >( pic ).get_Type( &kind )
        >> isHrSuccess || throwX( "kindOf: IPicture::get_Type failed" );
    return kind;
}

bool isBitmap( IPicture const& pic )
{
    return (kindOf( pic ) == PICTYPE_BITMAP);
}

OLE_HANDLE handleOf( IPicture const& pic )
{
    OLE_HANDLE  result  = 0;
    const_cast< IPicture& >( pic ).get_Handle( &result )
        >> isHrSuccess || throwX( "handleOf: IPicture::get_Handle failed" );
    return result;
}

HBITMAP bmpHandle( IPicture const& pic )
{
    assert( isBitmap( pic ) );
    return reinterpret_cast< HBITMAP >( handleOf( pic ) );
}

namespace g {
    winapi::ComPointer<IPicture>  pPicture;
}  // namespace g

INT_PTR CALLBACK demoDialogProc(
    HWND const      window,
    UINT const      messageId,
    WPARAM const    wParam,
    LPARAM const    lParam
    )
{
    switch( messageId )
    {
    case WM_INITDIALOG:
        ::SendDlgItemMessage(
            window, IDC_PICTURE, STM_SETIMAGE,
            IMAGE_BITMAP,
            reinterpret_cast< LPARAM >( bmpHandle( *g::pPicture ) )
            );
        break;
    case WM_CLOSE:
        ::EndDialog( window, IDCANCEL );
        break;
    case WM_COMMAND:
        ::EndDialog( window, wParam );
        break;
    }
    return 0;
}

struct Com
{
    Com() { ::CoInitialize( 0 ) >> isHrSuccess || throwX( "::CoInitialize failed" ); }
    ~Com() { ::CoUninitialize(); }
};

void cppMain()
{
    Com usingCom;
    String const    picFileName     = L"image.jpg";
    String const    picFilePath     = winapi::path::combine( winapi::exeFolder(), picFileName );

    ::OleLoadPicturePath(
        const_cast< wchar_t* >( picFilePath.c_str() ),
        nullptr, 0, 0,
        IID_IPicture,
        g::pPicture.asOutArgument()
        )
        >> isHrSuccess || throwX( "OleLoadPicturePath failed" );
    assert( isBitmap( *g::pPicture ) );

    ::DialogBox( ::GetModuleHandle( 0 ), MAKEINTRESOURCE( IDD_DEMO_DIALOG ), 0, demoDialogProc );
}

int main()
{
    try
    {
        cppMain();
        return EXIT_SUCCESS;
    }
    catch( exception const& x )
    {
        wcout << "!" << x.what() << endl;
    }
    return EXIT_FAILURE;
}

这篇关于WIN32 API在图片中控制c。打开JPG ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆