当窗口离屏时,为什么 CreateDIBSection() 会失败?

发布于 2024-07-15 05:32:27 字数 615 浏览 2 评论 0原文

我正在构建一个 Delphi 组件,以在 VCL 表单上嵌入 SDL 渲染表面。 只要创建 SDL 表面时表单显示在屏幕上,它就可以正常工作。 否则,它无法创建任何渲染纹理。

我跟踪 SDL 代码并最终得到以下函数调用,该函数调用失败(返回 NULL):

data->hbm = CreateDIBSection(renderdata->memory_hdc, bmi, DIB_RGB_COLORS, &data->pixels, NULL, 0);

HDC 是由具有自己的 HWND 窗口句柄的控件所拥有的绘图上下文的有效句柄,该句柄已正确设置。 但是,当在屏幕外创建控件时(这在 Delphi 中很常见)(所有窗体及其控件都以隐藏状态创建,直到需要显示它们时),CreateDIBSection 调用将失败,直到控件实际可见。

另外,如果它是在屏幕上创建的,则隐藏并重新显示(例如,如果它在选项卡上并且我切换选项卡),我创建的任何纹理都会在此过程中被清空。

这让我抓狂。 有人知道发生了什么事以及我该如何解决它吗?

I'm building a Delphi component to embed an SDL rendering surface on a VCL form. It works just fine as long as the form is on-screen at the moment that the SDL surface is created. Otherwise, it's not able to create any rendering textures.

I traced into the SDL code and ended up with the following function call, which fails (returns NULL):

data->hbm = CreateDIBSection(renderdata->memory_hdc, bmi, DIB_RGB_COLORS, &data->pixels, NULL, 0);

The HDC is a valid handle to the drawing context owned by a control that has its own HWND window handle, that's been set up properly. But when the control is created offscreen, which commonly happens in Delphi, (all forms, with their controls, are created in a hidden state until it's time to display them,) the CreateDIBSection call will fail until the control is actually visible.

Also, if it's created onscreen, then hidden and re-shown (if it's on a tab sheet and I switch tabs, for example,) any textures I create get blanked during this process.

This is driving me nuts. Anyone know what's going on and how I can work around it?

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

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

发布评论

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

评论(1

简美 2024-07-22 05:32:27

绘图上下文仅在 Paint 处理期间有效。

The drawing context is only valid during Paint processing.

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