2012-10-17 3 views
2

나누기 내가 그 여러 개의 창을추가 코드는 코드

그대로이 코드가 구현
bool UISystem::HandleMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 
{ 
    UIWindow* target = NULL; 
    for(vector<UIWindow*>::iterator it = windowList.begin(); it < windowList.end(); it++) 
    { 
     if((*it)->windowHandle == hwnd) 
     { 
      target = *it; 
      break; 
     } 
    } 

    if(target == NULL) 
    { return false; } 

    switch(msg) 
    { 
    case WM_DESTROY: 

     return true; 

    case WM_PAINT: 

     return true; 

    default: 
     return false; 
    } 
} 

LRESULT WINAPI UISystem::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 
{ 
    /*if(UISYSTEM->HandleMessage(hwnd, msg, wParam, lParam)) 
    { 
    }*/ 
    return DefWindowProc(hwnd, msg, wParam, lParam); 
} 

이있을 것이다 만드는 오전 내 사용자 인터페이스 시스템의 일부인이 코드를 가지고, UISystem :: WndProc의 주석 블록을 포함하여 윈도우가 올바르게 표시되지만 UISystem :: WndProc에서이 블록의 주석 처리를 제거하면 잘못된 핸들이 CreateWindow에서 반환됩니다.이 도움말은 나를 혼란스럽게 만들기 때문에 도움이 될 것입니다. UISystem :: WndProc에서 다른 코드를 수행하기 전에 DefWindowProc을 호출하지만 모든 attemps가 실패했습니다.

이 UIWindow에 대한 생성자입니다 :

while(GetMessage(&msg, NULL, 0, 0)) 
{ 
    TranslateMessage(&msg); 
    DispatchMessage(&msg); 
} 

에서 :

UIWindow::UIWindow(int x, int y, int width, int height, string & text) 

이이 루트 문제가 있지만 해결해야 한 가지 제거하는 경우

UIWindow::UIWindow(int x, int y, int width, int height, string & text) 
{ 

    int frameWidth = GetSystemMetrics(SM_CXSIZEFRAME); 
    int frameHeight = GetSystemMetrics(SM_CYSIZEFRAME); 
    int menuHeight = GetSystemMetrics(SM_CYMENU); 
    int windowXPos = (GetSystemMetrics(SM_CXSCREEN) - width)/2; 
    int windowYPos = (GetSystemMetrics(SM_CYSCREEN) - height)/2; 
    int windowWidth = width + frameWidth * 2; 
    int windowHeight = height + frameHeight * 2 + menuHeight; 

    bounds.X = x; 
    bounds.Y = y; 
    bounds.Width = width; 
    bounds.Height = height; 
    title = text; 

    MSG msg; 

    WNDCLASSEX wc = {sizeof(WNDCLASSEX), CS_VREDRAW|CS_HREDRAW|CS_OWNDC, 
     &UISystem::WndProc, 0, 0, hInstance, NULL, NULL, (HBRUSH)(COLOR_WINDOW + 1), 
     NULL, "AurousWindow", NULL}; 

    RegisterClassEx(&wc); 


    windowHandle = CreateWindow("AurousWindow", title.c_str(), WS_OVERLAPPEDWINDOW, windowXPos, windowYPos, windowWidth, windowHeight, NULL, NULL, hInstance, NULL); 
    SetWindowRgn(windowHandle, CreateRectRgn(0, 0, width, height), TRUE); 
    ShowWindow(windowHandle, nShow); 
    UpdateWindow(windowHandle); 

    //RECT rec = {0, 0, width, height}; 

    while(GetMessage(&msg, NULL, 0, 0)) 
    { 
     TranslateMessage(&msg); 
     DispatchMessage(&msg); 
    } 
} 
+3

참고로 모든 창에 대한 전역 목록을 유지 관리하는 대신 GWL_USERDATA를 사용하여 SetWindowLong을 호출하여 창에 사용자 데이터를 저장할 수 있습니다. http://msdn.microsoft.com/en-us/library/windows/ desktop/ms633591 (v = vs.85) .aspx – avakar

답변

1

확실하지 않음 윈도우가 존재하는 한 루프가 발생하고 UIWindow가 제대로 구성되지 않습니다. 이 객체 (UIWindow)는 실제로 UISystem :: HandleMessage 내부에서 액세스되지만, 생성자가 끝나지 않으므로 NULL이거나 정의되지 않은 상태입니다.

+0

luskan, 전체 응용 프로그램을 닫지 않고 각 창마다 메시지 펌프를 유지하려면 어떻게해야합니까? – user1754209

+1

여기를보십시오 : http://msdn.microsoft.com/en-us/library/windows/desktop/ms644936%28v=vs.85%29.aspx, 스레드 당 하나의 메시지 루프가 있어야합니다. 당신 main() 함수와 괜찮을 것입니다. 초기화는이 루프 전에 수행됩니다. – marcinj

+0

실수로 내 댓글을 삭제했을 수도 있습니다. luskan, 죄송합니다! 어떻게 보이나요? http://pastebin.com/K9sFnJ3E – user1754209