使用win32 API重新绘制子窗口的控件

时间:2014-01-09 23:06:55

标签: c++ winapi

我有一个主窗口,它有一个子窗口,而子窗口又有一个子窗口和一个按钮。当我从任务栏恢复窗口时,按钮和第三个子窗口拒绝显示。我尝试首先在孩子身上使用RedrawWindow(),然后是大孩子和按钮但是没有用。到目前为止,看起来子窗口与其子窗口之间没有任何联系,因为父母负责重新绘制其子女,但孩子没有义务。在父(主窗口)重绘期间,如何重新绘制子窗口的控件/子窗口(子窗口)。这是在使用Win32 API恢复父级之后。

我创建了一个控件类作为应用程序的入口点并监督所有其他类(Screen类 - 用于GUI,数据库类......),Screen类中包含所有子创建代码。这个怎么做:

//MainControl Class

#include <tchar.h>
#include "Screen.h"
#include <stdlib.h>
#include "FreeImage.h"
#pragma comment(lib, "user32")
#pragma comment(lib,"gdi32.lib")
#pragma comment(lib,"FreeImage.lib")




const char g_szClassName[] = "myWindowClass";
Screen display;
HWND welcomScreenHndl, menuScreenHndl, butt;

// Function prototypes
LRESULT CALLBACK WndProc(HWND hwnd, UINT messages, WPARAM wParam, LPARAM lParam);




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

WNDCLASSEX wc;
HWND hwnd;
MSG Msg;

// Registering the Window Class.
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);


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

// Creating the Window.
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, g_szClassName,
    "Prison Management System",
    WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_CLIPCHILDREN,
    100, 30, 750, 700, NULL, NULL, hInstance, NULL);

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


// Creating Other Windows with Scree class object.
welcomScreenHndl = display.welcomeScreen(hwnd, hInstance);//Child to Main Window
menuScreenHndl = display.menuScreen(welcomScreenHndl, hInstance);//grand child


ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);

// The message loop.
while(GetMessage(&Msg, NULL, 0, 0) > 0){
    TranslateMessage(&Msg);
    DispatchMessage(&Msg);
}
return Msg.wParam;
}

这是Screen类:// Screen Class

#include <tchar.h>
#include <windows.h>



class Screen{

char winClassName[20];
public:

HWND welcomeScreen(HWND parent, HINSTANCE hInstance);
HWND menuScreen(HWND parent, HINSTANCE hInstance);

};



HWND Screen::welcomeScreen(HWND parent, HINSTANCE hInstance){

    GetClassName(parent, winClassName, 20);

    HWND hwndpan = CreateWindowEx( WS_EX_CLIENTEDGE,
            winClassName,
            "",
            WS_CHILD | WS_VISIBLE | CS_HREDRAW | CS_VREDRAW,
            0, 20, 745, 695,
            parent, NULL, hInstance/*GetModuleHandle(NULL)*/, NULL);


    return hwndpan;
}

HWND Screen::menuScreen(HWND parent, HINSTANCE hInstance){

    HWND hwndpan = CreateWindowEx( WS_EX_CLIENTEDGE,
            winClassName,
            "",
            WS_CHILD | WS_VISIBLE | CS_HREDRAW | CS_VREDRAW,
            0, 100, 745, 695,
            parent, NULL, hInstance/*GetModuleHandle(NULL)*/, NULL);

    return hwndpan;
}

0 个答案:

没有答案