显示在&QUOT位图按钮"在WIN32类窗口 [英] Displaying a bitmap on a "BUTTON" class window in WIN32

查看:119
本文介绍了显示在&QUOT位图按钮"在WIN32类窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

修改我想创建子窗口(即我的按钮)中未发送WM_CREATE消息。因此,通过WM_CREATE中调用SendMessage,我将消息发送到已尚未创建一个窗口。对于现在的解决方案是WM_SHOWWINDOW消息时调用的SendMessage()。做子窗口在创建?发送WM_CREATE消息

I think the WM_CREATE message isn't sent during the creation of child windows (namely my button). So by calling SendMessage during WM_CREATE, I'm sending a message to a window that hasn't been created yet. The solution for now is to call SendMessage() during the WM_SHOWWINDOW message. Do child windows send WM_CREATE messages at creation?

为什么不显示在按钮上的位图?位图是180x180像素。

Why isn't the bitmap displaying on the button? The bitmap is 180x180 pixels.

我有一个资源文件:

Bit BITMAP bit.bmp

我然后创建主窗口,并与孩子的按钮窗口:

I then create the main window and a child "BUTTON" window with:

HWND b, d;

b = CreateWindow(L"a", NULL, WS_OVERLAPPEDWINDOW, 0, 0, 500, 500, 0, 0, 
                  hInstance, 0);

d = CreateWindow(L"BUTTON", NULL, WS_CHILD | WS_VISIBLE | BS_BITMAP, 
                 10, 10, 180, 180, b, 200, hInstance, 0);

然后,在我的Windows程序,我发送按钮窗口中的BM_SETIMAGE消息:

Then, in my windows procedure, I send the "BUTTON" window the "BM_SETIMAGE" message with:

HBITMAP hbit; 

case WM_CREATE:    // It works if I change this to: case WM_SHOWWINDOW 

hbit = LoadBitmap(hInstance, L"Bit");

SendMessage(d, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hbit);

LoadBitmap()返回一个有效的处理,因为它不返回NULL,而我能够显示使用的BitBlt()函数客户区位图。所以我要么不正确地发送消息,或者说我没有正确创建按钮窗口。

LoadBitmap() is returning a valid handle because It isn't returning NULL, and I'm able to display the bitmap in the client area using the BitBlt() function. So I'm either not sending the message correctly, or I'm not creating the "BUTTON" window correctly.

我在做什么错了?

谢谢!

推荐答案

为您的窗口类A被称为与 WM_CREATE 的,当一个窗口的窗口过程类创建。这是在你的第一个的来电的CreateWindow ,这是您创建子前按钮窗口。 WM_CREATE 表示正在创造 - 这并不意味着一个孩子正在创建

The window procedure for for your window class "a" gets called with WM_CREATE when a window of that class is created. This is during your first call to CreateWindow, which is before you create the child BUTTON window. WM_CREATE means "you are being created" - it doesn't mean "a child is being created".

解决方法是调用 D = CreateWindow的(L按钮...) WM_CREATE 处理程序为A类:

The solution is to call d = CreateWindow(L"BUTTON"...) in the WM_CREATE handler for class "a":

case WM_CREATE:
    d = CreateWindow(L"BUTTON", NULL, WS_CHILD | WS_VISIBLE | BS_BITMAP, 
                     10, 10, 180, 180, hwnd, 200, hInstance, 0);
    hbit = LoadBitmap(hInstance, L"Bit");
    SendMessage(d, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hbit);

这篇关于显示在&QUOT位图按钮"在WIN32类窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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