求助:OpenGL创建无边框无标题窗口后变成了黑边

sheuchenko 2014-07-21 05:52:26
我想使用OpenGL生成一个无标题无边框的窗口,代码是这样的



#include<glut.h>
#include<stdio.h>
#include<stdlib.h>
#include <Windows.h>
#include<time.h>

#include "cv.h"
#include "highgui.h"

#include <iostream>
using namespace std;
#define FileName "lena.bmp"

static GLint imagewidth=512;
static GLint imageheight=512;
static GLint pixellength;
static GLubyte* pixeldata;
static GLubyte* pixeldata1;

int cnt=0;

void idleCB()
{
glutPostRedisplay();
}

void timerCB(int millisec)
{
glutPostRedisplay();
glutTimerFunc(10, timerCB, 1);
}


void display(void)
{
double runtime = (double)clock();
if(cnt%2==0)
glDrawPixels(imagewidth,imageheight,GL_BGR_EXT,GL_UNSIGNED_BYTE,pixeldata);
else
glDrawPixels(imagewidth,imageheight,GL_BGR_EXT,GL_UNSIGNED_BYTE,pixeldata1);
//---------------------------------
cnt++;

runtime=(double)clock()-runtime;
cout<< runtime << " ms"<<endl;
//cout<<cnt<<endl;
glFlush();
glutSwapBuffers();

}
int main(int argc,char* argv[])
{
//打开文件
FILE* pfile=fopen("D:\\lena.bmp","rb");
if(pfile == 0) exit(0);

//计算像素数据长度
pixellength=imagewidth*3;
while(pixellength%4 != 0)pixellength++;
pixellength *= imageheight;

//读取像素数据
pixeldata = (GLubyte*)malloc(pixellength);
if(pixeldata == 0) exit(0);
fseek(pfile,54,SEEK_SET);
fread(pixeldata,pixellength,1,pfile);

FILE* pfile1=fopen("D:\\pug.bmp","rb");
pixeldata1 = (GLubyte*)malloc(pixellength);
if(pixeldata1 == 0) exit(0);
fseek(pfile1,54,SEEK_SET);
fread(pixeldata1,pixellength,1,pfile1);

//关闭文件
fclose(pfile);
//初始化glut运行
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA); //双缓存
glutInitWindowPosition(0,0);
glutInitWindowSize(imagewidth,imageheight);
glutCreateWindow(FileName);
glutDisplayFunc(&display);

LONG style;HWND hWnd;
//////////////////////////////////////
hWnd = FindWindow(NULL,FileName);
if(!hWnd)
cout<<"NO!"<<endl;

style = GetWindowLong(hWnd, GWL_STYLE);
style = style & (~WS_CAPTION) & ~(WS_BORDER) & ~WS_THICKFRAME ;
SetWindowLong( hWnd, GWL_STYLE, style); //无边框无标题


//////////////////////////////////////////////////////////////////////

//glutTimerFunc(10, timerCB, 1);
glutIdleFunc(idleCB);
glutMainLoop();
//-------------------------------------
// free(pixeldata);
return 0;
}


可是最后生成的窗口是这样的,虽然标题栏和边框没有了,但是变成了黑色,无法去掉。求问各位牛人,如何完整地去除这些黑色,只显示一个图片方块?先谢谢大家啦~
...全文
1228 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hlx_beat 2014-12-02
  • 打赏
  • 举报
回复
窗体为什么不自己创建非得使用工具库
赵4老师 2014-07-21
  • 打赏
  • 举报
回复
用Windows项目,别用Console项目。再试试。参考下面:
#pragma comment(lib,"user32")
#pragma comment(lib,"gdi32")
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
    PAINTSTRUCT ps;
    HDC hdc;
    HFONT hfont,ohfont;
    RECT r;
    COLORREF oc;

    switch(message) {
    case WM_CLOSE://按Alt+F4退出
        PostQuitMessage(0);
        break;
    case WM_PAINT:
        BeginPaint(hWnd, &ps);
        hdc = ps.hdc; // the device context to draw in
        GetClientRect(hWnd, &r); // Obtain the window's client rectangle
        hfont = CreateFont(240, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "华文楷体");
        ohfont=SelectObject(hdc,hfont);
        oc=SetTextColor(hdc,0x00C080FF);
        SetBkMode(hdc, TRANSPARENT);
        TextOut(hdc,r.left+r.right/2-720, r.top+r.bottom/2-120,"最短画图程序",12);
        SelectObject(hdc,ohfont);
        SetTextColor(hdc,oc);
        DeleteObject(hfont);
        EndPaint(hWnd, &ps);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
    MSG msg             = {0};
    WNDCLASS wc         = {0};
    HBRUSH hbrh;
    hbrh=CreateSolidBrush(0x00000000);
    wc.lpfnWndProc      = WndProc;
    wc.hInstance        = hInstance;
    wc.hbrBackground    = hbrh;
    wc.lpszClassName    = "minwindowsapp";
    wc.hCursor          = LoadCursor(NULL,IDC_ARROW);
    if( FAILED(RegisterClass(&wc)) ) return 1;

    if(FAILED(CreateWindow(wc.lpszClassName,
                        "Minimal Windows Application",
                        WS_POPUP|WS_VISIBLE,
                        0,
                        0,
                        GetSystemMetrics(SM_CXSCREEN),
                        GetSystemMetrics(SM_CYSCREEN),
                        0,
                        0,
                        hInstance,
                        NULL)))
        return 2;

    while( GetMessage( &msg, NULL, 0, 0 ) > 0 ) {
        DispatchMessage( &msg );
    }
    DeleteObject(hbrh);
    return 0;
}
sheuchenko 2014-07-21
  • 打赏
  • 举报
回复
引用 1 楼 zhao4zhong1 的回复:
WS_POPUP WS_DLGFRAME
赵老师好,我直接使用style &= WS_POPUP; 得到的效果和style = style & (~WS_CAPTION) & ~(WS_BORDER) & ~WS_THICKFRAME ;是一样的,依然有黑色的东西。 再加入style &= WS_DLGFRAME;效果也没有改变 恳请赵老师再指教一下~
sheuchenko 2014-07-21
  • 打赏
  • 举报
回复
赵老师好,我直接使用style &= WS_POPUP; 得到的效果和style = style & (~WS_CAPTION) & ~(WS_BORDER) & ~WS_THICKFRAME ;是一样的,依然有黑色的东西。 再加入style &= WS_DLGFRAME;效果也没有改变 恳请赵老师再指教一下~
赵4老师 2014-07-21
  • 打赏
  • 举报
回复
WS_POPUP WS_DLGFRAME

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧