Computer Games Forum
 

Go Back   Computer Games Forum > Tech > The Workshop > Limbaje de programare

Notices

Căutare produse PC Garage: Şterge căutarea

Reply
 
LinkBack Thread Tools
Old 08-11-2007, 11:36   #1 (permalink)
Registered User
 
adimisu's Avatar
 
Join Date: Jul 2007
Location: Buttsylvania
Help pls - Create child windows

Help pls. Am luat exemplul asta din MSDN care creaza o fereastra si in interiorul ei 3 ferestre copil. Problema e ca atunci cand il rulez imi omoara calculatorul si trebuie sa-l inchid din TaskManager. Ce nu fac bine?
[code]#include <windows.h>

#define ID_FIRSTCHILD 100
#define ID_SECONDCHILD 101
#define ID_THIRDCHILD 102

HINSTANCE ghInstance;

BOOL CALLBACK EnumChildProc(HWND hwndChild, LPARAM lParam)
{
LPRECT rcParent;
int i, idChild;

// Retrieve the child-window identifier. Use it to set the
// position of the child window.

idChild = GetWindowLong(hwndChild, GWL_ID);

if (idChild == ID_FIRSTCHILD)
i = 0;
else if (idChild == ID_SECONDCHILD)
i = 1;
else
i = 2;

// Size and position the child window.

rcParent = (LPRECT) lParam;
MoveWindow(hwndChild,
(rcParent->right / 3) * i,
0,
rcParent->right / 3,
rcParent->bottom,
TRUE);

// Make sure the child window is visible.

ShowWindow(hwndChild, SW_SHOW);

return TRUE;
}

LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
RECT rcClient;
int i;
HWND hwnd1;

switch(uMsg)
{
case WM_CREATE: // creating main window

// Create three invisible child windows.

for (i = 0; i < 3; i++)
{
hwnd1 = CreateWindowEx(0,
TEXT("ChildWClass"),
TEXT("Bla Bla"),
WS_CHILD | WS_BORDER,
0, 0, 0, 0,
hwnd,
(HMENU) (int) (ID_FIRSTCHILD + i),
//NULL
ghInstance,
NULL);
//ShowWindow(hwnd1, SW_SHOW);
}

return 0;

case WM_SIZE: // main window changed size

// Get the dimensions of the main window's client
// area, and enumerate the child windows. Pass the
// dimensions to the child windows during enumeration.

GetClientRect(hwnd, &rcClient);
EnumChildWindows(hwnd, EnumChildProc, (LPARAM) &rcClient);
return 0;

// Process other messages.
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
HWND hWnd;
MSG message;
WNDCLASSEX mywindow;

mywindow.cbClsExtra = 0;
mywindow.cbSize = sizeof(mywindow);
mywindow.cbWndExtra = 0;
mywindow.hbrBackground = GetStockObject(WHITE_BRUSH);
mywindow.hCursor = LoadCursor(NULL, IDC_ARROW);
mywindow.hIcon = LoadIcon(NULL, IDI_APPLICATION);
mywindow.hIconSm = NULL;
mywindow.lpfnWndProc = MainWndProc;
mywindow.hInstance = hInstance;
mywindow.lpszClassName = TEXT("ChildWClass");
mywindow.lpszMenuName = NULL;
mywindow.style = CS_HREDRAW | CS_VREDRAW;

RegisterClassEx(&mywindow);

hWnd = CreateWindowEx(0L,
TEXT("ChildWClass"),
TEXT("Bla bla"),
WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);

ghInstance = hInstance;

ShowWindow(hWnd, nShowCmd);
UpdateWindow(hWnd);

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

return(message.wParam);
}[/code]
__________________
Keep buttwalking.
 
adimisu is offline    Reply With Quote
Old 08-11-2007, 12:18   #2 (permalink)
Registered User
 
Join Date: Nov 2001
la prima vedere (n-am mai lucrat de mult cu API windows) folosesti aceeasi clasa si pentru fereastra principala si pentru ferestrele copil. din cauza ca ai pus pe WM_CREATE-ul ferestrei respective sa-ti creeze alte 3 ferestre, care folosesc aceeasi MainWndProc, fiecare din cele 3 ferestre incearca sa creeze alte 3 ferestre, care la randul lor fac fiecare inca 3 si asa ai obtinut un algoritm recursiv infinit.


Fie iti creezi o alta clasa de ferestre pentru copii fie gasesti alt mod de a le identifica, astfel incat in MainWndProc ferestrele copil sa nu mai incerce sa creeze si ele alte ferestre copil.
__________________
Who forgot to close the gate? Who let me out?
 
Smiley is offline    Reply With Quote
Old 08-11-2007, 12:40   #3 (permalink)
Subterranean infiltrator
 
Karg's Avatar
 
Join Date: Apr 1999
muta codul care creeaza cele 3 ferestre din WM_CREATE in WinMain, dupa ce creezi fereastra principala. din ceva motiv, CreateWindowEx pentru child windows trimite mesaj WM_CREATE care ajunge in acelasi loc, practic ai un soi de recursivitate.

apoi, adauga si asa ceva in MainWndProc, altfel iti ramine duda agatata in pom:
[code]
// Process other messages.
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
return 0;
[/code]
__________________
red birds will fly out of the east and destroy paris in a night
 
Karg is offline    Reply With Quote
Old 26-01-2008, 00:14   #4 (permalink)
Registered User
 
DeceaseD's Avatar
 
Join Date: Oct 2004
Location: in cimitir, pe stanga.
chiar urasc metoda Microsoft de GUI development. Traiasca QT si niste baieti destepti care s-au gandit la SIGNALS & SLOTS.
__________________
"Ele vin starnite de o primejdie ca de sfarsit de veac, si in spaima lor de necunoscutul barbat, se cred miresele mortii."
 
DeceaseD is offline    Reply With Quote
Advertisment
Reply

  Computer Games Forum > Tech > The Workshop > Limbaje de programare

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +2. The time now is 07:40.


Advertisement System V2.5 By   Branden
This site is copyrighted ©1997 - 2008, Computer Games Online SRL