#1 GDNet+ - Reputation: 512
Posted 18 November 2012 - 07:03 PM
#2 Marketplace Seller - Reputation: 8951
Posted 18 November 2012 - 07:54 PM
This is called the Model View Controller pattern (MVC).
What is your window displaying? A picture? Some text? Your input (the Controller) effects the data of the image (the Model), and that data is displayed to the screen (the View). Your painting shouldn't alter the data directly, just display it. Your input should effect the data, but the data should not be dependent on either the input or the rendering.
In this case, you have what as data? Several groups of text? So your input effects the text, and then the text is drawn on the screen. Your input should not draw text to the screen itself.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal
#3 GDNet+ - Reputation: 512
Posted 18 November 2012 - 07:58 PM
LRESULT CALLBACK WndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT ps;
RECT rect;
HBRUSH newbrush;
HPEN hPen;
HFONT font;
WORD x,y;
switch (msg)
{
case WM_PAINT:
{
// Draw some text centered in the client area of the main window
hDC = BeginPaint(hWindow, &ps);
GetClientRect(hWindow, &rect);
SetBkColor(hDC,RGB(0,0,0));
SetTextColor(hDC,RGB(255,0,0));
DrawText(hDC, TEXT("Tic Tac Toe"), -1, &rect,DT_SINGLELINE | DT_CENTER);
font = CreateFont(30,30,0,0,FW_DONTCARE,FALSE,FALSE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,CLIP_DEFAULT_PRECIS,CLEARTYPE_NATURAL_QUALITY,
VARIABLE_PITCH,TEXT(""));
SelectObject(hDC,font);
RECT rect_one;
rect_one.left=500;
rect_one.right=540;
rect_one.top=220;
rect_one.bottom=260;
DrawText(hDC, TEXT("X"), -1, &rect_one,DT_SINGLELINE | DT_CENTER);
hPen = CreatePen(PS_SOLID,1,RGB(0,255,0));
SelectObject(hDC,hPen);
//draw first vertical line
MoveToEx(hDC,560,200,NULL);
LineTo(hDC,560,400);
//draw second vertical line
MoveToEx(hDC,600,200,NULL);
LineTo(hDC,600,400);
//draw first horizontal line
MoveToEx(hDC,480,280,NULL);
LineTo(hDC,680,280);
//draw second horizontal line
MoveToEx(hDC,480,320,NULL);
LineTo(hDC,680,320);
DeleteObject(hPen);
ReleaseDC(hWindow,hDC);
EndPaint(hWindow, &ps);
break;
}
case WM_LBUTTONDOWN:
{
break;
}
case WM_CHAR:
if(wParam==VK_ESCAPE)
{
PostQuitMessage(0);
break;
}
return 0;
case WM_DESTROY:
{
// Exit the application
PostQuitMessage(0);
break;
}
}
return DefWindowProc(hWindow, msg, wParam, lParam);
}
#5 GDNet+ - Reputation: 512
Posted 18 November 2012 - 09:05 PM
case WM_MOUSEMOVE:
{
int mouse_x = (int)LOWORD(lParam);
int mouse_y = (int)HIWORD(lParam);
if(wParam == VK_LBUTTON)
{
PostQuitMessage(0);
return 0;
}
I will do more research on this problem.
#6 Marketplace Seller - Reputation: 8951
Posted 18 November 2012 - 09:08 PM
Perhaps you want MK_LBUTTON? I'm not very familiar with Win32 as a API, so I might be mistaken here.
However, this would be saying, "If the player moves the mouse AND has the left mouse button down, then close the program".
I think what you actually want is, "If the player clicks the left mouse button, then close the program". You probably want WM_KEYDOWN, not WM_MOUSEMOVE (Actually, if this is for drawing code, you'll want to handle both).
Edited by Servant of the Lord, 18 November 2012 - 09:11 PM.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal
#8 GDNet+ - Reputation: 512
Posted 18 November 2012 - 09:20 PM
LRESULT CALLBACK WndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT ps;
RECT rect;
HBRUSH newbrush;
HPEN hPen;
HFONT font;
WORD x,y;
switch (msg)
{
case WM_PAINT:
{
// Draw some text centered in the client area of the main window
hDC = BeginPaint(hWindow, &ps);
GetClientRect(hWindow, &rect);
SetBkColor(hDC,RGB(0,0,0));
SetTextColor(hDC,RGB(255,0,0));
DrawText(hDC, TEXT("Tic Tac Toe"), -1, &rect,DT_SINGLELINE | DT_CENTER);
hPen = CreatePen(PS_SOLID,1,RGB(0,255,0));
SelectObject(hDC,hPen);
//draw first vertical line
MoveToEx(hDC,560,200,NULL);
LineTo(hDC,560,400);
//draw second vertical line
MoveToEx(hDC,600,200,NULL);
LineTo(hDC,600,400);
//draw first horizontal line
MoveToEx(hDC,480,280,NULL);
LineTo(hDC,680,280);
//draw second horizontal line
MoveToEx(hDC,480,320,NULL);
LineTo(hDC,680,320);
DeleteObject(hPen);
ReleaseDC(hWindow,hDC);
EndPaint(hWindow, &ps);
break;
}
case WM_MOUSEMOVE:
{
int mouse_x = (int)LOWORD(lParam);
int mouse_y = (int)HIWORD(lParam);
if(wParam == VK_SPACE)
{
PostQuitMessage(0);
return 0;
}
hDC = GetDC(hWindow);
SetBkColor(hDC,RGB(0,0,0));
SetTextColor(hDC,RGB(255,0,0));
font = CreateFont(30,30,0,0,FW_DONTCARE,FALSE,FALSE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,CLIP_DEFAULT_PRECIS,CLEARTYPE_NATURAL_QUALITY,
VARIABLE_PITCH,TEXT(""));
SelectObject(hDC,font);
RECT rect_one;
rect_one.left=500;
rect_one.right=540;
rect_one.top=220;
rect_one.bottom=260;
DrawText(hDC, TEXT("X"), -1, &rect_one,DT_SINGLELINE | DT_CENTER);
break;
}
case WM_CHAR:
if(wParam==VK_ESCAPE)
{
PostQuitMessage(0);
break;
}
return 0;
case WM_DESTROY:
{
// Exit the application
PostQuitMessage(0);
break;
}
}
return DefWindowProc(hWindow, msg, wParam, lParam);
}
#9 Marketplace Seller - Reputation: 8951
Posted 18 November 2012 - 09:53 PM
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal
#12 Members - Reputation: 1560
Posted 18 November 2012 - 11:48 PM
But, we're been down this road, and you're going to continue to use that crappy API that is Win32.
---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)






