Original Post
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;
}