مهدي 2190 مدیر انجمن
تاريخ عضويت: جمعه 26 فروردين 1384 تعداد ارسالها: 402 محل سكونت: تهران
جمعه 14 بهمن 1384 - 15:48 |
|
|
سلام
نه نه نه دوست من این راحش نیست .
من خودم یک راه حل بنا به ایده خودم می گم ، ولی اینو بدونید سی پلاس پلاس خیلی انعطاف پذیر هست و شما می تونید نوع دیگری که دوست دارید کار کنید
به این کد توجه کنید :
كد: |
// Creates two windows based on the same
// Multiple Windows
// Hassan Mehdi Asl
// INCLUDES ///////////////////////////////////////////////
#define WIN32_LEAN_AND_MEAN // just say no to MFC
#include <windows.h> // include all the windows headers
#include <windowsx.h> // include useful macros
#include <stdio.h>
#include <math.h>
// DEFINES ////////////////////////////////////////////////
// defines for windows
#define WINDOW_CLASS_NAME "WINCLASS1"
#define WINDOW_CLASS_NAME2 "WINCLASS2"
// these are my int////////////////////////////////////////
int aa=0;
int bb=0;
// GLOBALS ////////////////////////////////////////////////
// FUNCTIONS //////////////////////////////////////////////
//start winproc1
LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam)
{
// this is the main message handler of the system
PAINTSTRUCT ps; // used in WM_PAINT
HDC hdc; // handle to a device context
// what is the message
switch(msg)
{
case WM_CREATE:
{
// do initialization stuff here
// return success
return(0);
} break;
case WM_PAINT:
{
// simply validate the window
hdc = BeginPaint(hwnd,&ps);
// you would do all your painting here
EndPaint(hwnd,&ps);
// return success
return(0);
} break;
case WM_DESTROY:
{
//check for closed windows
aa=1;
if(aa&&bb==1){
// kill the application, this sends a WM_QUIT message
PostQuitMessage(0);
}
// return success
return(0);
} break;
default:break;
} // end switch
// process any messages that we didn't take care of
return (DefWindowProc(hwnd, msg, wparam, lparam));
} // end WinProc1
//start winproc2
LRESULT CALLBACK WindowProc1(HWND hwnd1,
UINT msg1,
WPARAM wparam,
LPARAM lparam)
{
// this is the main message handler of the system
PAINTSTRUCT ps; // used in WM_PAINT
HDC hdc; // handle to a device context
// what is the message
switch(msg1)
{
case WM_CREATE:
{
// do initialization stuff here
// return success
return(0);
} break;
case WM_PAINT:
{
// simply validate the window
hdc = BeginPaint(hwnd1,&ps);
// you would do all your painting here
EndPaint(hwnd1,&ps);
// return success
return(0);
} break;
case WM_DESTROY:
{
//check for closed windows
bb=1;
if(aa&&bb==1){
// kill the application, this sends a WM_QUIT message
PostQuitMessage(0);
}
// return success
return(0);
} break;
default:break;
} // end switch
// process any messages that we didn't take care of
return (DefWindowProc(hwnd1, msg1, wparam, lparam));
}
//end winproc2
// WINMAIN ////////////////////////////////////////////////
int WINAPI WinMain( HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
{
WNDCLASSEX winclass; // these will hold the classs we create
WNDCLASSEX winclass1;
HWND hwnd; // generic window handles
HWND hwnd1;
MSG msg; // generic messages
MSG msg1;
// first fill in the window class stucture
winclass.cbSize = sizeof(WNDCLASSEX);
winclass.style = CS_DBLCLKS | CS_OWNDC |
CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinstance;
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = WINDOW_CLASS_NAME;
winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
// register the window class
if (!RegisterClassEx(&winclass))
return(0);
winclass1.cbSize = sizeof(WNDCLASSEX);
winclass1.style = CS_DBLCLKS | CS_OWNDC |
CS_HREDRAW | CS_VREDRAW;
winclass1.lpfnWndProc = WindowProc1;
winclass1.cbClsExtra = 0;
winclass1.cbWndExtra = 0;
winclass1.hInstance = hinstance;
winclass1.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass1.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass1.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
winclass1.lpszMenuName = NULL;
winclass1.lpszClassName = WINDOW_CLASS_NAME2;
winclass1.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
// register the window class
if (!RegisterClassEx(&winclass1))
return(0);
// create the first window
if (!(hwnd = CreateWindowEx(NULL, // extended style
WINDOW_CLASS_NAME, // class
"Window 1 Based on WINCLASS", // title
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0,0, // initial x,y
400,400, // initial width, height
NULL, // handle to parent
NULL, // handle to menu
hinstance,// instance of this application
NULL))) // extra creation parms
return(0);
// create the second window
if (!(hwnd = CreateWindowEx(NULL, // extended style
WINDOW_CLASS_NAME2, // class
"Window 2 Based on WINCLASS1", // title
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
400,400, // initial x,y
400,400, // initial width, height
NULL, // handle to parent
NULL, // handle to menu
hinstance,// instance of this application
NULL))) // extra creation parms
return(0);
// enter main event loop, but this time we use PeekMessage()
while(TRUE)
{
// test if there is a message in queue, if so get it
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
// test if this is a quit
if(msg.message == WM_QUIT)
break;
// translate any accelerator keys
TranslateMessage(&msg);
// send the message to the window proc
DispatchMessage(&msg);
}
if(PeekMessage(&msg1,NULL,0,0,PM_REMOVE))
{
if(msg1.message ==WM_QUIT)
break;
TranslateMessage(&msg1);
DispatchMessage(&msg1);// end if
}
// main game processing goes here
} // end while
// return to Windows like this
return(msg.wParam);
return(msg1.wParam);
if(aa&&bb==1){
return(0);
}
} // end WinMain
//goodluck my friend
|
من دو تا متغیر از نوع اینتجر تعریف کردم تا در بستن پنجره ها و فرستادن پیام ها کمکم کنند و در ابتدا مقدار اونا رو به 0 تعریف کردم
بعد دو تا کلاس و دو تا winproc تعریف کردم که برای این نوع پروژه ها لازمه چون باید هر پنجره ای به طور مستقل همه اعضایش مدیریت شوند
بعد در مرحله بعد کلاس دوم رو فیلد lpfnwndproc رو به winproc دوم نسبت دادم
سپس در هر دو winproc در قسمت destroy تعریف کردم که هر موقع هر پنجره بسته شد متغیر کمکی خودشو برابر با 1 قرار بده و اگر هر دو متغیر برابر 1 شدند پیام بستن رو ارسال کنه
و برای هر پنجره یک تابع peekmessage جداگانه برای مدیریت پیامهای ارسالی تعریف کردم
و در پایان باز هم از متغیرهای کمکی برای خروج از winmain استفاده کردم
بازم می گم این روش منه شاید روشهای بهتر و مطمئن تر هم وجود داشته باشه ،این دیگه بستگی به خلاقیت هر کسی داره
موفق و پیروز باشید
----------------------
hassan mehdiasl |
_________________ به امید روزی که کلمه ای کاش را نگوئیم ....
وبلاگ تیم توسعه سورنا
www.gamedev.ir
ادیتور سورنا
http://sourena.gamedev.ir/
ادیتور سیمرغ
http://simorgh.SourenaGames.com
بازی دوازده رخ - 12 رخ (سیاوش)
www.SourenaGames.com
شرکت نرم افزاری سورنا پردازش
WWW.SOURENACO.IR
|
|