I'm making a simple database program for a friend and am stuck. The program has a small text box, a large multiline text box, and a button. When the user types a word or series of words(in this case, a dog breed) into the small text box and presses the button, the program takes the text from the small text box, puts it in a string variable fn, and calls a function that takes the file "data/" + fn + ".txt", gets the text from the file one line at a time, and puts the text into the large multiline text box.
It's going well so far. I made a simple console version that worked great and the only thing I'm having trouble with is trying to find WinAPI help that has nothing to do with Visual Studios. Specifically, what I'm having trouble with is:
1) How do I make a pointer to the contents of a text box and/or how do I put the contents of a text box into a string variable?
2) How do I clear, write, and append to a multiline text box?
Here's the code. I'm pretty new to WinAPI programming, so if you see any errors or bad practices don't hesitate to set me straight.
The program loads text files that are hundreds of lines long. When it loads them, the text box's scroll bar stays at the bottom making it so that when the file is done being paced into the text box, the user is looking at the bottom of the file. How do I make the program automatically scroll to the top of the text box when it's done loading the file?
Also, how do I change the default font of a text box? I'd like to use a mono-spaced font to make it easier on the eyes.
Not sure if I did that right, but it works. "static HFONT FONT_CourierNew;" is defined globally, CreateFont is right after the parent window is created in WinMain, and the WM_SETFONT message is sent to the edit box right after it is created in WM_CREATE. Is there anything I've done that will case problems in the future? I'm pretty much winging it at this point and learning from my mistakes since I'm programming in territory I've never touched before.
I do have another question that is on my mind. Is it possible to bind the width and height of child controls to the width and height of the parent window? I want the controls to be resized and redrawn when the user alters the size of the window either with the maximize/restore button or with dragging the edges.
My last question is, how do I integrate keypresses into the program? I've tried this:
Code:
...
...
case WM_KEYDOWN:
switch(wParam)
{
case VK_RETURN:
MessageBox(hwnd,"Enter Key Pressed ","Message",MB_OK);
return 0;
}
return 0;
case WM_COMMAND:
switch(wParam)
{
case ID_BUTTON:
{
...
...
and it compiles without error but nothing happens when I press the enter key. I've also tried different combinations of that with the same result of nothing when I press enter.
Last edited by Dispiacere; December 29th, 2009 at 04:10 AM.
Bookmarks