Win32窗口显示问题. [英] Win32- window display issue.

查看:181
本文介绍了Win32窗口显示问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

win32 api的新手,


我尽可能快地学到了东西,而且我对它的基本知识至少是核心.

在这本关于opengl编程的书之后,我将win32 api链接为设备上下文.

这里的问题是我需要创建一个图形界面(菜单对话框等)以选择全屏/窗口模式.

[code] bool fullscreen = false;
全局声明的标志.

如果是(全屏),则////全屏?
{{br> DEVMODE dmScreenSettings; //设备模式
memset(& dmScreenSettings,0,sizeof(dmScreenSettings));
dmScreenSettings.dmSize = sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth = windowWidth; //屏幕宽度
dmScreenSettings.dmPelsHeight = windowHeight; //屏幕高度
dmScreenSettings.dmBitsPerPel = windowBits; //每像素位数
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;

//设置显示模式失败,切换到窗口
MessageBox(NULL,``显示模式失败'',NULL,MB_OK);
fullscreen = FALSE;
}
}

如果(全屏),//我们是否仍处于全屏模式? //窗口扩展样式
dwStyle = WS_POPUP; //Windows样式
ShowCursor(FALSE); //隐藏鼠标指针
}
else
{{br> dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; //窗口扩展样式
dwStyle = WS_OVERLAPPEDWINDOW; //Windows样式
}

AdjustWindowRectEx(& windowRect,dwStyle,FALSE,dwExStyle); //将窗口调整为真正的请求大小

//注册了类,因此现在创建我们的窗口[/code]


^^这是紧接windowclass定义的源. br>
如我所见,我有两个选择:创建一个优先于窗口的无模式对话框,并在创建实际窗口之前更改值-这是失败的. ?即使是与我的问题有关,我在运行时也会遇到相同的问题.

第二个是从一开始就从wm_create msg创建一个对话框,并根据选择更改值,我做到了但是现在我似乎无法更新对我的主窗口所做的更改.我知道我们有UpdateWindow(到窗口的句柄),但如果正确,我应该在哪里放置它?

[code] BOOL CALLBACK AboutDlgProc(HWND hwnd,UINT消息,WPARAM wParam,LPARAM lParam)
{
开关(消息)
case WM_INITDIALOG:

返回TRUE;
case WM_COMMAND:
>情况下ID1:结果的EndDialog(HWND,ID1);结果,断裂;结果,壳体ID2:结果的EndDialog(HWND,ID2);结果,断裂;结果,}结果,打破;
默认值:
返回FALSE;
}
返回TRUE;
}







代码]

^^创建对话框.并在选择选项后结束.

[代码]

LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg, WPARAM wParam,LPARAM lParam)
{
静态HDC hDC;
静态HGLRC hRC;
int高度,宽度; h消息
开关(uMsg)
{case
case WM_COMMAND:
break; NULL),
MAKEINTRESOURCE(IDD_SCREEN),hWnd,AboutDlgProc);
if(ret == ID1){
if(ret == ID2){
fullscreen = true;
UpdateWindow(NULL);失败!",错误",
.MB_OK | MB_ICONINFORMATION);
}
}

[/code]

^^在主窗口msging函数中进行处理.
我使用了UpdateWindow(NULL)希望null表示父窗口.



我使用/创建了框布局的资源模板.

有没有办法重绘/刷新我的窗口? ,还是我再次明确地编写代码?
如果将其放置在什么位置以及在哪里放置?

我们将不胜感激!

A newbie to the win32  api ,


I learned as much as quickly I could, and I have a basic understanding of it, the core at least.

I'm following this book on opengl programming in which I'm linking up with the win32 api as device context.

The problem here is I need to create a graphical interface(menu dialog box ect) to select either fullscreen/windowed mode.

[code]bool fullscreen=false;
A globally declared flag.

if (fullscreen)                             // fullscreen?
    {
        DEVMODE dmScreenSettings;                   // device mode
        memset(&dmScreenSettings,0,sizeof(dmScreenSettings));
        dmScreenSettings.dmSize = sizeof(dmScreenSettings);
        dmScreenSettings.dmPelsWidth = windowWidth;         // screen width
        dmScreenSettings.dmPelsHeight = windowHeight;           // screen height
        dmScreenSettings.dmBitsPerPel = windowBits;             // bits per pixel
        dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

        //
        if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
        {
            // setting display mode failed, switch to windowed
            MessageBox(NULL, "Display mode failed", NULL, MB_OK);
            fullscreen = FALSE;
        }
    }

    if (fullscreen)                             // Are We Still In Fullscreen Mode?
    {
        dwExStyle=WS_EX_APPWINDOW;                  // Window Extended Style
        dwStyle=WS_POPUP;                       // Windows Style
        ShowCursor(FALSE);                      // Hide Mouse Pointer
    }
    else
    {
        dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;   // Window Extended Style
        dwStyle=WS_OVERLAPPEDWINDOW;                    // Windows Style
    }

    AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle);     // Adjust Window To True Requested Size

    // class registered, so now create our window [/code]


^^ This is the source immediately following the windowclass definitions.

As i see it i have two options, to create a modeless dialog box which takes precedence over the window, and changes the values before the actual window is created - that was a failure.
Or is it possible? Even if it were with my issue, I'd face the same problem at run time.

The 2nd one is to create a dialog box at the inception from the wm_create msg and according to the choices change the values, I did that. But now i cant seem to update the changes to my main window. I know we have the UpdateWindow(handle to window) but if it is right, where do i place it?

[code]BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
    switch(Message)
    {
        case WM_INITDIALOG:

        return TRUE;
        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                case ID1:
                    EndDialog(hwnd, ID1);
                break;
                case ID2:
                    EndDialog(hwnd, ID2);
                break;
            }
        break;
        default:
            return FALSE;
    }
    return TRUE;
}







[/code]

^^Creating the dialog box.And ending it when a choice has been selected.

[code]

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    static HDC hDC;
    static HGLRC hRC;
    int height, width;

    // dispatch messages
    switch (uMsg)
    {  
    case WM_COMMAND:
break;
   
   
    case WM_CREATE:
        {
            int ret = DialogBox(GetModuleHandle(NULL),
                MAKEINTRESOURCE(IDD_SCREEN), hWnd, AboutDlgProc);
            if(ret == ID1){
                fullscreen=false;
                UpdateWindow(NULL);
            }
            else if(ret == ID2){
                fullscreen=true;
                UpdateWindow(NULL);
            }
            else if(ret == -1){
                MessageBox(hWnd, "Dialog failed!", "Error",
                    MB_OK | MB_ICONINFORMATION);
            }
        }

[/code]

^^where I do my processing within the main window msging function.
I used UpdateWindow(NULL) in hopes that null refers to the parent window.



I used/created a resource template for the box layout.

Is there a way to redraw/refresh my window, or do i have explicitly write code again?
if either what and where do i place it?

Help would be much appreciated!

推荐答案

Hi
如果您进行OpenGL编程,建议您访问下面的网站.

http://nehe.gamedev.net/lesson.asp?index=01

这将指导您如何在窗口/全屏模式下创建窗口.这将从地面零开始,并向您提供示例代码.您还将获得win32代码.

我想告诉您的有关OpenGL的主要内容是,您需要具有一个不断更新窗口区域的循环.在本教程中,您将看到如何修改主消息循环并窃取一些CPU周期以绘制窗口.
Hi
In case you doing OpenGL programming I would suggest you to please visit the site below.

http://nehe.gamedev.net/lesson.asp?index=01

This will guide you how to create windows in windowed/fullscreen mode etc. This will start from ground zero and will provide you sample code also along with it. You will get win32 code also.

The main this i wanna tell you about the OpenGL is that, you need to have a loop which continuously updates the window area. In the tutorial you would see how you modify the main message loop and steal some CPU cycles to paint the window. 


这篇关于Win32窗口显示问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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