-
2 questions
1. In textout(), what do I use to do line breaks (like \n in cout)
2. my program has an very annoying glitch, when you hit north you must close the command toolbar to actually go north (for text-based rpg)
Code:
long room = 1;
long _north = 1;
long _south;
BOOL CALLBACK ToolDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_NORTH:
room = _north;
break;
case IDC_SOUTH:
room = _south;
break;
}
break;
default:
return FALSE;
}
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
char buff[2560] = {0}; // A character string for "filling" with text to print
HDC hdc = NULL; // An hdc to be "filled" if printing text to screen
RECT rect = {0}; // This will be used to "paint the window" to white
// (we need a RECT defining the windows dimensions to do this)
switch(Message)
{
case WM_CREATE:
g_hToolbar = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_TOOLBAR),
hwnd, ToolDlgProc);
if(g_hToolbar != NULL)
{
ShowWindow(g_hToolbar, SW_SHOW);
}
else
{
MessageBox(hwnd, "CreateDialog returned NULL", "Warning!",
MB_OK | MB_ICONINFORMATION);
}
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_FILE_EXIT:
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
case ID_DIALOG_SHOW:
ShowWindow(g_hToolbar, SW_SHOW);
break;
case ID_DIALOG_HIDE:
ShowWindow(g_hToolbar, SW_HIDE);
break;
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
DestroyWindow(g_hToolbar);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
while (room != 0) {
if (room == 1) {
hdc = GetDC(hwnd);
GetClientRect(hwnd,&rect);
FillRect(hdc,&rect,(HBRUSH)GetStockObject(WHITE_BRUSH));
sprintf(buff,"Your head...\r\nIt hurts, you can\'t feel your fingers, everything feels so numb, so cold...\r\nYou feel dizzy and sick, you wonder where you are...\r\nAll around you is white, it\'s cold, is this snow? You\'re surrounded by snow!\r\nYou can\'t remember mutch, all you remember is pain, a powerful pain in your back.\r\nWhy do you hurt so much, where you left here? Or are you travelling on your own?\r\nBut now is not the time to ponder, perhaps you should travel somewhere...\r\n");
SetTextColor(hdc,RGB(0,0,0));
TextOut(hdc,0,0,buff,istrlen(buff));
ReleaseDC(hwnd,hdc);
}
room = 0;
}
return 0;
}
-
Trying using DrawText instead of TextOut. I personally perfer using static multiline edit boxes when I'm dealing with a bunch of text. With DrawText I think \n is enough, but in the edit box you need \r\n.
About the glitch, I have no idea since I haven't been successful when it comes to dialog boxes.
-
how do I use drawtext()?
same way or what? I only saw examples of textout() :(
-
-
>>long _south;
No definition to south so i assume the problem will occur with south as well.
The reason you have to close the tool dlg (I think) is so the messages to the app will then (again) be routed to the WndProc() callback instead of the ToolDlgProc() .