1 Dialog window and 1 Window...???
First of all I''m new to programming windows stuff...only thing I used to do was create a window either for windowed or fullscreen directX applications.
now I''m trying to get 2 windows open at the same time (1 Dialog and 1 window to draw in with either openGL or DirectX) I included my 3 functions two get the 2 windows onscreen the functions WindowProc() and mainDlgProc() below, I only left in the important case statement. Now for my problem and question. when I start my Application the Dialog gets the highlight and switching to the other window by clicking on it won''t activate it, I just hear the windows beep that I can''t do that...so what am I doing wrong? I just want to be able to switch focus to the other window and back etc...I want to be able to manipulate data, fill in editboxes etc...in my dialog and make the other DirectX/OpenGL window respond to it visually...how do I do that????
Chris
HWND hwndCurrent = NULL;
MSG msg;
LRESULT CALLBACK WindowProc(HWND hwnd2,
UINT msg,
WPARAM wparam,
LPARAM lparam)
{
switch(msg)
{
case WM_ACTIVATE:
if (0 == wparam)
hwndCurrent = NULL;
else
hwndCurrent = hwnd2;
return FALSE;
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
break;
default:break;
}
return (DefWindowProc(hwnd2, msg, wparam, lparam));
}
int APIENTRY WinMain( HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
{
HWND hwnd;
WNDCLASSEX winclass;
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(GRAY_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = WINDOW_CLASS_NAME;
winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&winclass))
return(0);
if(!(hwnd = CreateWindowEx(NULL,
WINDOW_CLASS_NAME,
"MY Application",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
400, 400,
400, 400,
NULL,
NULL,
hinstance,
NULL)))
return(0);
// Display the main dialog box.
DialogBox( hinstance, MAKEINTRESOURCE(IDD_DIALOG), hwnd, MainDlgProc );
while(GetMessage(&msg, NULL, 0, 0))
{
if (NULL == hwndCurrent || !IsDialogMessage(hwndCurrent, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return(msg.wParam);
return (0);
}
INT_PTR CALLBACK MainDlgProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_ACTIVATE:
if (0 == wParam)
hwndCurrent = NULL;
else
hwndCurrent = hDlg;
return FALSE;
break;
}
return FALSE; // Message not handled
}
You''re creating a modal dialog box. Modal means that you cannot change your current window until it''s destroyed.
You need to switch to modeless. Rather than DialogBox, use CreateDialog.
You need to switch to modeless. Rather than DialogBox, use CreateDialog.
Well I stopped using DialogBox() and instead using CreateDialog() now keeping all of my source the same now, I don''t hear the ''error beep'' anymore when I click on the inactive window but when I do so...my application closes now...what''s going wrong? there''s obviously something wrong in my code...can someone tell me what please....
Chris
Chris
while(GetMessage(&msg, NULL, 0, 0))
{
if (NULL == hwndCurrent || !IsDialogMessage(hwndCurrent, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
Change this too
That should fix the problem
{
if (NULL == hwndCurrent || !IsDialogMessage(hwndCurrent, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
Change this too
while(GetMessage(&msg, NULL, 0, 0)){if (!IsDialogMessage(hwndCurrent, &msg)){TranslateMessage(&msg);DispatchMessage(&msg);}}
That should fix the problem
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement