Archived

This topic is now archived and is closed to further replies.

Drakon

A window question...

Recommended Posts

How do you make two windows open at once? And, how do you make text appear in a window at a keypress? Its not working for me... I''m trying to just make a simple window ready for when I put in my openGL stuff, but I figured I''d mess around with it now first... I basically want it to display PAUSED when I press P. Here is the code: #include #include HDC hDC; int active = 1; char string[] = "This is the advanced window!!!"; char paused[] = "PAUSED"; int WinClose(){ PostQuitMessage(0); return 0; } int WinCreate(){ return 0; } int OpenGLScene(){ SetTextColor(hDC, COLORREF(0x00FF0000)); TextOut(hDC, 50, 50, string, sizeof(string)-1); DWORD Final = timeGetTime() + 2; while(timeGetTime() < Final); if(active = 1){ SetTextColor(hDC, COLORREF(0x01FF0000)); TextOut(hDC, 35, 50, paused, sizeof(paused)-1); } return 0; } LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { PAINTSTRUCT ps; switch(msg){ case WM_CREATE: WinCreate(); break; case WM_CLOSE: WinClose(); break; case WM_PAINT: hDC = BeginPaint(hwnd, &ps); OpenGLScene(); EndPaint(hwnd, &ps); break; case WM_KEYDOWN: if( GetAsyncKeyState( ''P'' ) ) { //////////////////////////////////////////////////////////////////// active = 1; return 0; //////////////////////////////////////////////////////////////////// } return 0; case WM_KEYUP: if( GetAsyncKeyState( VK_SHIFT ) ) { PostQuitMessage( 0 ); } return 0; default: break; } return(DefWindowProc(hwnd, msg, wparam, lparam)); } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { WNDCLASSEX wc; HWND hwnd; MSG msg; bool done; wc.cbClsExtra = 0; wc.cbSize = sizeof(WNDCLASSEX); wc.cbWndExtra = 0; wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.hCursor = LoadCursor(NULL, IDC_CROSS); wc.hIcon = LoadIcon(NULL, NULL); wc.hIconSm = LoadIcon(NULL, NULL); wc.hInstance = hInstance; wc.lpfnWndProc = WndProc; wc.lpszClassName = "WCClass"; wc.lpszMenuName = NULL; wc.style = CS_HREDRAW | CS_VREDRAW; if(!RegisterClassEx(&wc)) return 0; hwnd = CreateWindowEx(NULL, "WCClass", "Advanced Window", WS_VISIBLE | WS_OVERLAPPEDWINDOW, 50, 50, 250, 250, NULL, NULL, hInstance, NULL); ShowWindow(hwnd, nShowCmd); UpdateWindow(hwnd); if(!hwnd) return 0; done = false; while(!done) { PeekMessage(&msg, hwnd, NULL, NULL, PM_REMOVE); if(msg.message == WM_QUIT) { done = true; } else { TranslateMessage(&msg); DispatchMessage(&msg); } if( GetAsyncKeyState( VK_ESCAPE ) ) PostQuitMessage( 0 ); } return msg.wParam; }

Share this post


Link to post
Share on other sites
Just call CreateWindow/CreateWindowEx multiple times if you want more than one window.

To make text appear at a keypress you can simply respond to a WM_KEYDOWN or WM_KEYUP message in your window-procedure: set a flag indicating that the app is paused, and then when you render your window (in response to a WM_PAINT, or in your main game-loop), check the flag, and write the text if it''s set.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
At first I would recommend doing TextOut(hDC, 50, 50, string, strlen(string));.
To detect the key, you can try the following:

...
case WM_KEYDOWN:
if( wParam == VK_P )
{
/////////////////////////////////////////////////////////////// /////
active = 1;
return 0;
TextOut((HDC)GetDC(hwnd), 50, 50, paused, strlen(paused));
/////////////////////////////////////////////////////////////// /////
}
return 0;
...

It worked for me.

baumep


Share this post


Link to post
Share on other sites
Where would I put this to have it open another window when I press Q? I can put it in other places that either don't work or the close the program for some reason...

if( GetAsyncKeyState('Q') )
{
hwnd = CreateWindowEx(NULL,
"WCClass", "The Addon Window",
WS_VISIBLE | WS_OVERLAPPEDWINDOW,
60, 60, 60, 60, NULL, NULL, hInstance, NULL);
return 0;
}

Edited by - Drakon on October 23, 2001 9:19:46 PM

Share this post


Link to post
Share on other sites