Dev C ++ - 透明框架上的不透明文本

时间:2015-04-27 11:27:09

标签: dev-c++

我是一名初学c ++图形程序员,并使用dev c ++作为IDE。我创建了一个带有文本框和按钮的简单框架,并从dwmapi.dll中调用DwmExtendFrameIntoClientArea 但文本框和按钮显示丑陋的透明文本。我想要文本框和按钮上的不透明文本。我四处搜索但找到了.NET c ++的答案而不是dev c ++。所以请帮我用dev c ++处理这个问题。我们将不胜感激。

以下是代码:

#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <uxtheme.h>
HWND tb;
HWND btn;

typedef struct _DWM_BLURBEHIND
{
    DWORD dwFlags;
    BOOL fEnable;
    HRGN hRgnBlur;
    BOOL fTransitionOnMaximized;
} DWM_BLURBEHIND, *PDWM_BLURBEHIND;

HINSTANCE DLL = LoadLibrary("dwmapi.dll"); 
typedef HRESULT (*_DwmExtendFrameIntoClientArea)(HWND hwnd,MARGINS* margins);

_DwmExtendFrameIntoClientArea DwmExtendFrameIntoClientArea = (_DwmExtendFrameIntoClientArea)GetProcAddress(DLL,"DwmExtendFrameIntoClientArea");

LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {

    switch(Message) {


        case WM_CREATE: {

            ShowWindow(GetConsoleWindow(),SW_HIDE);

            MARGINS margins = {-1,-1,-1,-1};
            DwmExtendFrameIntoClientArea(hwnd,&margins);

            tb = CreateWindow("EDIT","Text",WS_CHILD | WS_VISIBLE,5,5,574,30,hwnd,NULL,NULL,NULL);
            btn = CreateWindow("BUTTON","Button",WS_CHILD | WS_VISIBLE,5,50,80,30,hwnd,NULL,NULL,NULL);                             
            break;

        }   

        case WM_DESTROY: {
            PostQuitMessage(0);
            break;
        }

        default:
            return DefWindowProc(hwnd, Message, wParam, lParam);
    }
    return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {



    WNDCLASSEX wc; /* A properties struct of our window */
    HWND hwnd; /* A 'HANDLE', hence the H, or a pointer to our window */
    MSG Msg; /* A temporary location for all messages */

    /* zero out the struct and set the stuff we want to modify */
    memset(&wc,0,sizeof(wc));
    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.lpfnWndProc   = WndProc; /* This is where we will send messages to */
    wc.hInstance     = hInstance;
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);


    /* White, COLOR_WINDOW is just a #define for a system color, try Ctrl+Clicking it */

    wc.hbrBackground = (HBRUSH)(COLOR_WINDOWTEXT);
    wc.lpszClassName = "WindowClass";
    wc.hIcon         = LoadIcon(NULL,IDI_APPLICATION); /* Load a standard icon */
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION); /* use the name "A" to use the project icon */

    if(!RegisterClassEx(&wc)) {
        MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
        return 0;
    }

    hwnd = CreateWindowEx(WS_EX_WINDOWEDGE,"WindowClass","Frame",WS_VISIBLE | WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, /* x */
        CW_USEDEFAULT, /* y */
        600, /* width */
        350, /* height */
        NULL,NULL,hInstance,NULL);

    if(hwnd == NULL) {
        MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
        return 0;
    }

    /*
        This is the heart of our program where all input is processed and 
        sent to WndProc. Note that GetMessage blocks code flow until it receives something, so
        this loop will not produce unreasonably high CPU usage
    */
    while(GetMessage(&Msg, NULL, 0, 0) > 0) { /* If no error is received... */
        TranslateMessage(&Msg); /* Translate key codes to chars if present */
        DispatchMessage(&Msg); /* Send it to WndProc */
    }
    return (int) Msg.wParam;

}

0 个答案:

没有答案