| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2636 人关注过本帖
标题:求助C++WIN32窗口背景图片添加问题
只看楼主 加入收藏
cxiaomubiao
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2017-3-12
收藏
 问题点数:0 回复次数:0 
求助C++WIN32窗口背景图片添加问题
窗口背景图片不显示,各位给看看,源码:
#include <windows.h>
#include <string>
using namespace std;

#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment(lib,"Gdiplus.lib")
#include "resource.h"



LRESULT CALLBACK mainWndProc(HWND hwnd, UINT message, WPARAM wparam,

LPARAM lparam)
{
    switch (message)
    {
        case WM_CREATE:
        {
            CREATESTRUCT* ps;
            ps = (CREATESTRUCT*)lparam;
            
            HWND GAMEbutton;
            GAMEbutton = CreateWindow("button", "NEW

GAME", WS_CHILD, 320-64, 0,128, 48, hwnd, (HMENU)IDM_NEWGAME, ps-

>hInstance, 0);
            //动态设定窗口ID函数
            //SetWindowLong(GAMEbutton, GWL_ID,

IDM_NEWGAME);
            ShowWindow(GAMEbutton, SW_NORMAL);

            
            
            
            return 0;
        }
        case WM_PAINT:
        {
            PAINTSTRUCT ps1;
            HDC hdc;
            hdc = BeginPaint(hwnd, &ps1);
            RECT rc;
            GetClientRect(hwnd, &rc);
            
            Graphics gra(hdc);
            Pen redpen(Color::Gray,8);
            Rect rct;
            rct.X = rc.left;
            rct.Y = rc.top;
            rct.Width = rc.right - rc.left;
            rct.Height = rc.bottom - rc.top;        

   
            gra.DrawRectangle(&redpen,rct);
            //gra.DrawEllipse(&redpen, rct);
            SolidBrush sbr(Color::Gray);
            //gra.FillRectangle(&sbr, rct);
            
        
            EndPaint(hwnd, &ps1);
            
            return 0;
        }
        case WM_COMMAND:
            switch (LOWORD(wparam))
            {
                case IDM_NEWGAME:
                    MessageBox(hwnd,"开始新游戏","

提示",MB_YESNO);
                    break;
                case IDM_OPENGAME:
                    MessageBox(hwnd, "打开游戏存档

", "提示", MB_YESNO);
                    break;
                case IDM_SAVEGAME:
                    MessageBox(hwnd, "保存游戏存档

", "提示", MB_YESNO);
                    break;
            }
            return 0;
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
   
    }
    return DefWindowProc(hwnd, message, wparam,lparam);
}
int APIENTRY WinMain(HINSTANCE hinst, HINSTANCE hprevinst, LPTSTR

lpcmdline, int ncmdshow)
{
    GdiplusStartupInput gpsi;
    ULONG_PTR token;
    GdiplusStartup(&token,&gpsi,0);
    WNDCLASSEX wecx;
    wecx.cbClsExtra = 0;
    wecx.cbSize = sizeof(WNDCLASSEX);
    wecx.cbWndExtra = 0;
    wecx.hbrBackground = (HBRUSH)COLOR_WINDOWFRAME;
    wecx.hCursor = LoadCursor(NULL,IDC_ARROW);
    wecx.hIcon = 0;
    wecx.hIconSm = 0;
    wecx.hInstance = hinst;
    wecx.lpfnWndProc = mainWndProc;
    wecx.lpszMenuName = 0;
    string cs_name = "onewindowclass";
    wecx.lpszClassName = cs_name.c_str();
    wecx.style = CS_HREDRAW | CS_VREDRAW;
    RegisterClassEx(&wecx);
    HWND mainWND = CreateWindow(cs_name.c_str(), "onewindow",

WS_OVERLAPPEDWINDOW, 128, 128, 640, 480, 0,LoadMenu

(hinst,MAKEINTRESOURCE(IDM_MAIN)),hinst,0);
   
    HDC dc, dcmap;
    dc = GetDC(mainWND);
    dcmap = CreateCompatibleDC(dc);

    HBITMAP bmp;
    bmp = LoadBitmap(hinst, MAKEINTRESOURCE(IDB_BITMAP));

    //bmp = (HBITMAP)LoadImage(hinst, MAKEINTRESOURCE(IDB_BITMAP),

IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_SHARED);



    SelectObject(dcmap, bmp);
    BitBlt(dc, 0, 0, 640, 480, dcmap, 0, 0, SRCCOPY);

    ShowWindow(mainWND,SW_NORMAL);
    UpdateWindow(mainWND);
    MSG msg;
    while (GetMessage(&msg,0,0,0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }









    GdiplusShutdown(token);

    return 0;
}
搜索更多相关主题的帖子: message comment include 背景图片 
2017-03-12 15:45
快速回复:求助C++WIN32窗口背景图片添加问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017413 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved