Multiple Fenetres enfants

Messages postés
184
Date d'inscription
lundi 31 juillet 2006
Statut
Membre
Dernière intervention
26 mai 2016
-
Bonjour,

J'ai crée une fenêtre avec deux fenêtres enfants,ca marche mais quand les deux ce superposent,visuellement ca bug.Comme ci le repaint avait un problème.Ou est mon problème s.v.p.Voici mon code:
#include <windows.h>
#include "resource.h"

LPCWSTR g_szClassName = L"myWindowClass";
HWND hWnd;
HWND hCreator = NULL;
HWND hTools = NULL;
HINSTANCE ToolInstance = NULL;
HINSTANCE CreatorInstance = NULL;

bool InitCreator(HINSTANCE hInstance);
bool InitTool(HINSTANCE hInstance);

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CLOSE:
DestroyWindow(hCreator);
DestroyWindow(hTools);
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}

LRESULT CALLBACK CreatorProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CLOSE:

break;
case WM_DESTROY:
// PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}

LRESULT CALLBACK ToolsProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CLOSE:

break;
case WM_DESTROY:
// PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
MSG Msg;

//Step 1: Registering the Window Class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC;
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 );
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

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

hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, g_szClassName, L"3D CREATOR", WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL);

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

ShowWindow(hWnd, TRUE);
UpdateWindow(hWnd);

if (InitCreator(hInstance) == false)
return 0;
ShowWindow(hCreator, TRUE);
UpdateWindow(hCreator);
if (InitTool(hInstance) == false)
return 0;
ShowWindow(hTools, TRUE);
UpdateWindow(hTools);
while (GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}

bool InitTool(HINSTANCE hInstance){
WNDCLASSEX wcChild;
wcChild.cbSize = sizeof(WNDCLASSEX);
wcChild.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC;
wcChild.lpfnWndProc = ToolsProc;
wcChild.cbClsExtra = 0;
wcChild.cbWndExtra = 0;
wcChild.hInstance = ToolInstance;
wcChild.hIcon = NULL;
wcChild.hCursor = LoadCursor(NULL, IDC_ARROW);
wcChild.hbrBackground = CreateSolidBrush(RGB(0, 0, 0));
wcChild.lpszMenuName = NULL;
wcChild.lpszClassName = L"Tools";
wcChild.hIconSm = NULL;
RegisterClassEx(&wcChild);
hTools = CreateWindowEx(0, L"Tools", L"Tools", WS_OVERLAPPEDWINDOW | WS_CHILD | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, hWnd, NULL, ToolInstance, NULL);
if (!hTools)return false;
ShowWindow(hTools,TRUE);
UpdateWindow(hTools);
return true;
}

bool InitCreator(HINSTANCE hInstance){
WNDCLASSEX wcChild;
wcChild.cbSize = sizeof(WNDCLASSEX);
wcChild.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC;
wcChild.lpfnWndProc = CreatorProc;
wcChild.cbClsExtra = 0;
wcChild.cbWndExtra = 0;
wcChild.hInstance = CreatorInstance;
wcChild.hIcon = NULL;
wcChild.hCursor = LoadCursor(NULL, IDC_ARROW);
wcChild.hbrBackground = CreateSolidBrush(RGB(0, 0, 0));
wcChild.lpszMenuName = NULL;
wcChild.lpszClassName = L"Creator";
wcChild.hIconSm = NULL;
RegisterClassEx(&wcChild);
hCreator = CreateWindowEx(0, L"Creator", L"Creator", WS_OVERLAPPEDWINDOW | WS_CHILD | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480,hWnd, NULL, CreatorInstance, NULL);
if (!hCreator)return false;
ShowWindow(hCreator, TRUE);
UpdateWindow(hCreator);
return true;
}

--
Afficher la suite