优化校准不显示任何图片

发布于 2024-12-09 18:40:05 字数 961 浏览 0 评论 0原文

我目前正在制作一个包含图片控件的对话框。我将类型设置为 BITMAP,并将图像设置为我也想要的图像。该图像也位于资源 .rc 文件中。当我将其设置为图片控件的位图时,我可以在编辑器中很好地看到它,但是当我运行我的应用程序时,它不起作用,我在图片控件中看不到任何内容。

我尝试过以下方法:

调用 Initcommoncontrols(); (这个函数已被弃用,所以我尝试了 InitCommonControlsEx() 和它想要的参数)结果:仍然没有图片

我在初始化表单时使用了以下代码片段:

SendMessage( GetDlgItem( aHWND, HEADERLOGO), STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap );

hBitmap 声明为:

HBITMAP hBitmap = LoadBitmap( hInstance, MAKEINTRESOURCE(BITMAP_LOGO) );

当我在 LoadBitmap() 之后执行 getlasterror 时,错误代码是:1814 (0x716),也翻译为 ERROR_RESOURCE_NAME_NOT_FOUND 我不知道为什么找不到图像,我可以在编辑器中很好地看到该图像,没有任何抱怨。 hInstance 是从 WinMain() 获得的,我也尝试使用以下代码片段获取它:

(HINSTANCE)GetWindowLong( aHWND, GWL_HINSTANCE);

我假设 WinMain HINSTANCE 是正确的,但只是为了确保我尝试过这个,没有效果。

之后我认为这可能只是 IDE 搞砸了,所以我扔掉了对话框,重新创建了它,添加了新的图片控件,再次添加了图像。仍然是同样的事情,在编辑器中看起来不错,但在运行项目时不显示。

我猜我在这里遗漏了一些非常简单的东西,请启发我。

I'm currently making a dialog which holds a picture control. I set the type to BITMAP and set the image to the image I want it too. This image is also in the resource .rc file. When I set this as the bitmap for the picture control I can see it just fine in the editor, when I run my application however it does not work, I don't see anything in the picture control.

I've tried the following:

Call Initcommoncontrols(); ( this function is deprecated so I tried the InitCommonControlsEx() with the argument it wanted ) Result: Still no picture

I used the following snippet when the form is initialized:

SendMessage( GetDlgItem( aHWND, HEADERLOGO), STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap );

hBitmap is declared as:

HBITMAP hBitmap = LoadBitmap( hInstance, MAKEINTRESOURCE(BITMAP_LOGO) );

When I did getlasterror after LoadBitmap() the error code was: 1814 (0x716) which translates too ERROR_RESOURCE_NAME_NOT_FOUND
I have no clue why the image could not be found, I can see the thing just fine in the editor, get no complaints about it. hInstance is obtained from WinMain(), I also tried getting it using this snippet:

(HINSTANCE)GetWindowLong( aHWND, GWL_HINSTANCE);

I assume the WinMain HINSTANCE would be correct but just to be sure I tried this, had no effect.

After that I thought it might just be the IDE screwing up somehow so I threw away the dialog, recreated it, added new picture control, added the image again. Still same thing, looks fine in the editor but doesn't show when running the project.

I'm guessing I'm missing something really simple here, please enlighten me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

维持三分热 2024-12-16 18:40:05

事实证明,在对话框中获取 HINSTANCE 是行不通的。它对应用程序内存无效。如果您获取从 WinMain 获得的 HINSTANCE,它将起作用。我的引擎现在抓住了这个,现在 HBITMAP 句柄已填充得很好。

It turned out that getting the HINSTANCE inside a dialog won't work. It won't be valid to application memory. If you grab the HINSTANCE you get from WinMain it will work. My engine now grabs this one and now the HBITMAP handle is filled just fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文