Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/158.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ (c+;+;win32)窗口在运行时仍不显示_C++_Winapi_Window - Fatal编程技术网

C++ (c+;+;win32)窗口在运行时仍不显示

C++ (c+;+;win32)窗口在运行时仍不显示,c++,winapi,window,C++,Winapi,Window,我试图对一个按钮进行子类化,但我的窗口没有显示出来,每次我都必须重新启动visual studio才能运行该应用程序。目前什么也没有显示:当我运行应用程序时,它什么也没有显示。我认为这与函数RegisterClass1有关。请帮助 这是我的密码: // CustomButton.cpp : Defines the entry point for the application. // #include "framework.h" #include "CustomButton.h" #inclu

我试图对一个按钮进行子类化,但我的窗口没有显示出来,每次我都必须重新启动visual studio才能运行该应用程序。目前什么也没有显示:当我运行应用程序时,它什么也没有显示。我认为这与函数RegisterClass1有关。请帮助

这是我的密码:

// CustomButton.cpp : Defines the entry point for the application.
//

#include "framework.h"
#include "CustomButton.h"
#include "SkinClass/skin.h"
#include <commctrl.h>
#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst;                                // current instance
WCHAR szTitle[MAX_LOADSTRING];                  // The title bar text
WCHAR szWindowClass[MAX_LOADSTRING];            // the main window class name
const char g_szClassName[] = "MyClassName";

// Forward declarations of functions included in this code module:
ATOM                MyRegisterClass(HINSTANCE hInstance);
BOOL                InitInstance(HINSTANCE, int);
LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);
void                RegisterClass1(HINSTANCE);

int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPWSTR    lpCmdLine,
                     _In_ int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    // TODO: Place code here.

    // Initialize global strings
    LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    LoadStringW(hInstance, IDC_CUSTOMBUTTON, szWindowClass, MAX_LOADSTRING);
    //MyRegisterClass(hInstance);
    RegisterClass1(hInstance);










    // Perform application initialization:
    /*if (!InitInstance (hInstance, nCmdShow))
    {
        return FALSE;
    }*/
    /*HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);*/

    HWND hWnd = CreateWindowExA(WS_EX_LAYERED, g_szClassName, "Scenes", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL,
        hInstance, NULL);



    CSkin aa(IDR_CR, ID_CIRCLE);
    RECT rect;
    GetWindowRect(hWnd, &rect);

    HWND hButton = CreateWindow(TEXT("BUTTON"), TEXT("START EDITING!"), WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, ((rect.right - rect.left) / 2) - 90, 500, aa.Width(), aa.Height(),
        hWnd, (HMENU)NULL, NULL, NULL);




    HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_CUSTOMBUTTON));





    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);










    MSG msg;

    // Main message loop:
    while (GetMessage(&msg, nullptr, 0, 0))
    {
        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
    aa.Destroy();
    return (int) msg.wParam;
}



//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
    WNDCLASSEXW wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);

    wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = hInstance;
    wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_CUSTOMBUTTON));
    wcex.hCursor        = LoadCursor(nullptr, IDC_ARROW);
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName   = MAKEINTRESOURCEW(IDC_CUSTOMBUTTON);
    wcex.lpszClassName  = szWindowClass;
    wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

    return RegisterClassExW(&wcex);
}

//
//   FUNCTION: RegisterClass1()
//
//   PURPOSE: Registers the class
//
//   COMMENTS:
//
//
//
//

void RegisterClass1(HINSTANCE hInstance) {
    WNDCLASSEXA wc;
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    wc.hInstance = hInstance;
    wc.lpfnWndProc = WndProc;
    wc.lpszClassName = g_szClassName;
    wc.lpszMenuName = "MENU";
    wc.style = CS_HREDRAW | CS_VREDRAW;


}

//
//   FUNCTION: InitInstance(HINSTANCE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   hInst = hInstance; // Store instance handle in our global variable

   HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}

LRESULT CALLBACK ButtonProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
    switch (Msg)
    {
    case WM_PAINT: {
        PAINTSTRUCT ps;
        HDC hdc = BeginPaint(hWnd, &ps);
        HDC hdc_x = CreateCompatibleDC(0);
        HINSTANCE hInstance = GetModuleHandle(NULL);
        HBITMAP hBitmap = (HBITMAP)LoadBitmap(hInstance, MAKEINTRESOURCE(ID_CIRCLE)); //Load the bitmap
        HBITMAP holdbmp;
        holdbmp=(HBITMAP)SelectObject(hdc_x, hBitmap); //Put the bitmap into the hdc_x
        SelectObject(hdc_x, holdbmp);
        BitBlt(hdc, 0, 0, 180, 50, hdc_x, 0, 0, SRCCOPY); //Draw it.
        EndPaint(hWnd, &ps);
        DeleteObject(hBitmap);
        DeleteDC(hdc_x);
        break;
    }

    default:
        return DefSubclassProc(hWnd, Msg, wParam, lParam);
    }
    return 0;
}
















//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE: Processes messages for the main window.
//
//  WM_COMMAND  - process the application menu
//  WM_PAINT    - Paint the main window
//  WM_DESTROY  - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case WM_CREATE:

    case WM_COMMAND:
        {
            int wmId = LOWORD(wParam);
            // Parse the menu selections:
            switch (wmId)
            {
            case IDM_ABOUT:
                DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
                break;
            case IDM_EXIT:
                DestroyWindow(hWnd);
                break;
            default:
                return DefWindowProc(hWnd, message, wParam, lParam);
            }
        }
        break;
    case WM_PAINT:
        {
            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hWnd, &ps);
            // TODO: Add any drawing code that uses hdc here...
            EndPaint(hWnd, &ps);
        }
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    UNREFERENCED_PARAMETER(lParam);
    switch (message)
    {
    case WM_INITDIALOG:
        return (INT_PTR)TRUE;

    case WM_COMMAND:
        if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
        {
            EndDialog(hDlg, LOWORD(wParam));
            return (INT_PTR)TRUE;
        }
        break;
    }
    return (INT_PTR)FALSE;
}
//CustomButton.cpp:定义应用程序的入口点。
//
#包括“framework.h”
#包括“CustomButton.h”
#包括“SkinClass/skin.h”
#包括
#定义最大加载字符串100
//全局变量:
HINSTANCE hInst;//当前实例
WCHAR szTitle[MAX_LOADSTRING];//标题栏文本
WCHAR szWindowClass[最大加载字符串];//主窗口类名称
const char g_szClassName[]=“MyClassName”;
//转发此代码模块中包含的函数声明:
ATOM MyRegisterClass(HINSTANCE HINSTANCE);
BOOL InitInstance(HINSTANCE,int);
LRESULT回调WndProc(HWND、UINT、WPARAM、LPARAM);
INT_PTR回调关于(HWND、UINT、WPARAM、LPARAM);
无效注册类别1(HINSTANCE);
国际货币基金组织,
_在当前情况下,
_在LPWSTR lpCmdLine中,
_In_uuint(nCmdShow)
{
未引用的_参数(HPPreInstance);
未引用的_参数(lpCmdLine);
//TODO:将代码放在这里。
//初始化全局字符串
LoadStringW(hInstance、IDS\U APP\U TITLE、szTitle、MAX\U LOADSTRING);
LoadStringW(hInstance、IDC_CUSTOMBUTTON、szWindowClass、MAX_LOADSTRING);
//MyRegisterClass(hInstance);
注册类别1(hInstance);
//执行应用程序初始化:
/*如果(!InitInstance(hInstance,nCmdShow))
{
返回FALSE;
}*/
/*HWND HWND=CreateWindowW(szWindowClass,szTitle,WS_OVERLAPPEDWINDOW,
CW_usefault,0,CW_usefault,0,nullptr,nullptr,hInstance,nullptr)*/
HWND HWND=CreateWindowExA(WS_EX_LAYERED,g_szClassName,“场景”,WS_重叠窗口,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,
hInstance,NULL);
CSkin aa(IDR_CR,ID_圆圈);
RECT-RECT;
GetWindowRect(hWnd和&rect);
HWND hButton=CreateWindow(文本(“按钮”)、文本(“开始编辑”)、WS|u CHILD | WS|u VISIBLE | BS|u OWNERDRAW、((rect.right-rect.left)/2)-90500、aa.Width()、aa.Height(),
hWnd,(HMENU)空,空,空);
HACCEL hAccelTable=装载加速器(hInstance、MAKEINTRESOURCE(IDC_CUSTOMBUTTON));
显示窗口(hWnd、nCmdShow);
更新窗口(hWnd);
味精;
//主消息循环:
while(GetMessage(&msg,nullptr,0,0))
{
if(!TranslateAccelerator(msg.hwnd、hAccelTable和msg))
{
翻译信息(&msg);
发送消息(&msg);
}
}
aa.销毁();
返回(int)msg.wParam;
}
//
//函数:MyRegisterClass()
//
//目的:注册窗口类。
//
ATOM MyRegisterClass(HINSTANCE HINSTANCE)
{
WNDCLASSEXW wcex;
wcex.cbSize=sizeof(WNDCLASSEX);
wcex.style=CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc=WndProc;
wcex.cbClsExtra=0;
wcex.cbWndExtra=0;
wcex.hInstance=hInstance;
wcex.hIcon=LoadIcon(hInstance,MAKEINTRESOURCE(IDI_CUSTOMBUTTON));
wcex.hCursor=LoadCursor(nullptr,IDC_箭头);
wcex.hbrBackground=(HBRUSH)(彩色窗口+1);
wcex.lpszMenuName=MAKEINTRESOURCEW(IDC_自定义按钮);
wcex.lpszClassName=szWindowClass;
wcex.hIconSm=LoadIcon(wcex.hInstance,MAKEINTRESOURCE(IDI_SMALL));
返回寄存器CLASSEXW(&wcex);
}
//
//函数:RegisterClass1()
//
//目的:注册班级
//
//评论:
//
//
//
//
无效注册表类别1(HINSTANCE HINSTANCE){
Wndclassaxa wc;
wc.cbSize=sizeof(WNDCLASSEX);
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hbrBackground=(HBRUSH)(彩色窗口+1);
wc.hCursor=LoadCursor(空,IDC_箭头);
wc.hIcon=LoadIcon(空,IDI_应用程序);
wc.hIconSm=LoadIcon(空,IDI_应用程序);
wc.hInstance=hInstance;
wc.lpfnWndProc=WndProc;
wc.lpszClassName=g_szClassName;
wc.lpszMenuName=“菜单”;
wc.style=CS_HREDRAW | CS_VREDRAW;
}
//
//函数:InitInstance(HINSTANCE,int)
//
//用途:保存实例句柄并创建主窗口
//
//评论:
//
//在这个函数中,我们将实例句柄保存在一个全局变量中,然后
//创建并显示主程序窗口。
//
BOOL InitInstance(HINSTANCE HINSTANCE,int nCmdShow)
{
hInst=hInstance;//将实例句柄存储在全局变量中
HWND HWND=CreateWindowW(szWindowClass,szTitle,WS_OVERLAPPEDWINDOW,
CW_usefault,0,CW_usefault,0,nullptr,nullptr,hInstance,nullptr);
如果(!hWnd)
{
返回FALSE;
}
显示窗口(hWnd、nCmdShow);
更新窗口(hWnd);
返回TRUE;
}
LRESULT回调按钮proc(HWND HWND,UINT Msg,WPARAM WPARAM,LPARAM LPARAM,UINT_PTR uIdSubclass,DWORD_PTR dwRefData)
{
开关(Msg)
{
案例WM_油漆:{
PAINTSTRUCT-ps;
HDC HDC=开始喷漆(hWnd和ps);
HDC HDC_x=CreateCompatibleDC(0);
HINSTANCE HINSTANCE=GetModuleHandle(NULL);
HBITMAP HBITMAP=(HBITMAP)加载位图(hInstance,MAKEINTRESOURCE(ID_CIRCLE));//加载位图
HBITMAP-holdbmp;
holdbmp=(HBITMAP)选择对象(hdc_x,HBITMAP);//将位图放入hdc_x
选择对象(hdc_x,holdbmp);
BitBlt(hdc,0,0,180,50,hdc_x,0,0,SRCCOPY);//绘制它。
端漆(hWnd和ps);
删除对象(hBitmap);
DeleteDC(hdc_x);
打破
}
违约:
返回DefSubclassProc(hWnd、Msg、wParam、lParam);
}
返回0;
}
//
//功能:WndProc(HWND、UINT、WPARAM、LPARAM)
//
//用途:处理主窗口的消息。
//
//WM_命令
   HWND hWnd = CreateWindowExA(WS_EX_LAYERED, g_szClassName, "Scenes", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL,
       hInstance, NULL);

   SetLayeredWindowAttributes(hWnd, NULL, 255, LWA_ALPHA);

   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);