简体   繁体   English

如何使图片适合静态控件vc ++ win32

[英]how to make a picture fit in a static control vc++ win32

can you tell me how to make a picture fit in a static control, i mean like if you create a static control for viewing pictures and if the picture quality or size of picture is bigger than control then it re size the static control with the size of picture. 您能告诉我如何使图片适合静态控件吗?我的意思是,例如,如果您创建用于查看图片的静态控件,并且图片的质量或图片尺寸大于控件,那么它将使用该尺寸调整静态控件的大小图片。 i could create the control and set the picture to it alright. 我可以创建控件并将图片设置为正确。 but i don't know how to make it fit on control. 但我不知道如何使其适合控制。 this is how i create control and set picture to it. 这就是我创建控件并为其设置图片的方式。

Code: 码:

HWND static_con(HWND hWnd, HINSTANCE hInst){
    HWND Static_Pic;

    Profile_Pic = CreateWindow("STATIC", NULL, SS_BITMAP|WS_CHILD|WS_VISIBLE|WS_TABSTOP, 5,5,33,33, hWnd, NULL, hInst, NULL);
    HBITMAP hBmp = (HBITMAP)LoadImage(NULL, "camera1.jpg", IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
    if(hBmp == NULL){
        MessageBox(NULL, "Error while loading image", "Error", MB_OK|MB_ICONERROR);
    }
    SendMessage(Static_Pic, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBmp);
    return 0;
}

and then i call the function in WM_CREATE handler which creates it successfully and now i don't know how to make it fit on control, i really appreciate if you could tell me how to make the picture fit on control. 然后我在WM_CREATE处理程序中调用该函数,该函数成功创建了该函数,现在我不知道如何使其适合控件,如果您能告诉我如何使图片适合控件,我将不胜感激。

You can use SS_REALSIZECONTROL From Microsoft's documentation. 您可以使用Microsoft文档中的SS_REALSIZECONTROL

SS_REALSIZECONTROL - Adjusts the bitmap to fit the size of the static control.

You can also manually scale the image. 您也可以手动缩放图像。 Get the size of the control where image is to go by using GetWindowRect(), then by using StretchBlt() scale the image so that its dimensions match that of the source, then do STM_SETIMAGE. 通过使用GetWindowRect()获得图像的控件大小,然后使用StretchBlt()缩放图像以使其尺寸与源图像尺寸匹配,然后执行STM_SETIMAGE。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM