• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
phil67rpg

drawing to windows with the mouse

14 posts in this topic

I am attempting to draw to a window using DrawText and WM_PAINT. I want to use the mouse and the WM_LBUTTONDOWN message. I understand that to actually draw to the screen one must use the WM_PAINT message. I am using the Win21 API. I am using this API because I want to learn how to program in windows better.
-1

Share this post


Link to post
Share on other sites
You have: Your input, your rendering/drawing. You don't want your input to directly effect your rendering, but to effect the thing your rendering is displaying.

This is called the [url="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller"]Model View Controller[/url] pattern (MVC).

What is your window displaying? A picture? Some text? Your input (the [b]Controller[/b]) effects the data of the image (the [b]Model[/b]), and that data is displayed to the screen (the [b]View[/b]). Your painting shouldn't alter the data directly, just display it. Your input [i]should[/i] 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.
0

Share this post


Link to post
Share on other sites
here is the code I am working on.
[code]
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);
}
[/code]
0

Share this post


Link to post
Share on other sites
Well I looked this one up in a book and it appears to be correct, but it does not shut down the window when I click the left mouse button.
[code]
case WM_MOUSEMOVE:
{

int mouse_x = (int)LOWORD(lParam);
int mouse_y = (int)HIWORD(lParam);

if(wParam == VK_LBUTTON)
{
PostQuitMessage(0);
return 0;
}
[/code]
I will do more research on this problem.
0

Share this post


Link to post
Share on other sites
Win32 documentation says that WM_MOUSEMOVE's wParam attribute must be [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ms645616(v=vs.85).aspx"]one of these[/url] values.

Perhaps you want [b][u][color=#ff0000]M[/color][/u]K_LBUTTON[/b]? I'm not very familiar with Win32 as a API, so I might be mistaken here.

However, this would be saying, "[i]If the player moves the mouse AND has the left mouse button down, then close the program[/i]".

I think what you actually want is, "[i]If the player clicks the left mouse button, then close the program[/i]". 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
0

Share this post


Link to post
Share on other sites
for some reason the program is not reaching the vk code.I tried vk_space as well and it does not work either.
[code]
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);
}
[/code]
0

Share this post


Link to post
Share on other sites
[url="http://msdn.microsoft.com/en-us/library/windows/desktop/ms645616(v=vs.85).aspx"]WM_MOUSEMOVE[/url]'s wParam doesn't gjve VK_ values. WM_KEYDOWN does, though.
1

Share this post


Link to post
Share on other sites
You could also stop banging your head on the wall and leave the Win32 API behind for input and drawing and move to a modern system like SFML or even SDL for input/windowing.

But, we're been down this road, and you're going to continue to use that crappy API that is Win32.
0

Share this post


Link to post
Share on other sites
If you want to learn DX9, learn DX9. Don't get side-tracked with that seething pit of ugliness that is Win32 API. Most rational people these days use an abstraction layer so they don't have to deal with it that much.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0