I know there is a way to insert code with a schroll bar, but I haven't figured out how to do it. I tried attaching it, but I am not sure it worked. Here's the code:
#include <windows.h>
#include <stdio.h>
#define ID_MYBUTTON 101
#define ID_TAB 201
LPSTR szClassName = "MyClass";
HINSTANCE hInstance;
LRESULT CALLBACK MyWndProc(HWND, UINT, WPARAM, LPARAM);
HWND hwndText[3];
FILE *fp;
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow)
{
WNDCLASS wnd;
MSG msg;
HWND hwnd;
HWND hWndBtn1;
hInstance = hInst;
wnd.style = CS_HREDRAW | CS_VREDRAW; //we will explain this later
wnd.lpfnWndProc = MyWndProc;
wnd.cbClsExtra = 0;
wnd.cbWndExtra = 0;
wnd.hInstance = hInstance;
wnd.hIcon = LoadIcon(NULL, IDI_APPLICATION); //default icon
wnd.hCursor = LoadCursor(NULL, IDC_ARROW); //default arrow mouse cursor
wnd.hbrBackground = (HBRUSH)(COLOR_WINDOW);
wnd.lpszMenuName = NULL; //no menu
wnd.lpszClassName = szClassName;
if(!RegisterClass(&wnd)) //register the WNDCLASS
{
MessageBox(NULL, "This Program Requires Windows NT",
"Error", MB_OK);
return 0;
}
hwnd = CreateWindow(szClassName,
"Window Title",
WS_OVERLAPPEDWINDOW, //basic window style
CW_USEDEFAULT,
CW_USEDEFAULT, //set starting point to default value
CW_USEDEFAULT,
CW_USEDEFAULT, //set all the dimensions to default value
NULL, //no parent window
NULL, //no menu
hInstance,
NULL); //no parameters to pass
// create a text box and store the handle
hwndText[0] = CreateWindow(
TEXT("edit"), // The class name required is edit
TEXT("Enter text here"), // Default text.
WS_VISIBLE | WS_CHILD | WS_BORDER, // the styles
100,100, // the left and top co-ordinates
300,30, // width and height
hwnd, // parent window handle
(HMENU) ID_TAB, // the ID of your combobox
hInstance, // the instance of your application
NULL
); // extra bits you dont really need
hwndText[1] = CreateWindow(
TEXT("edit"), // The class name required is edit
TEXT("2nd field"), // Default text.
WS_VISIBLE | WS_CHILD | WS_BORDER , // the styles
100,200, // the left and top co-ordinates
300,30, // width and height
hwnd, // parent window handle
NULL, // the ID of your combobox
hInstance, // the instance of your application
NULL
); // extra bits you dont really need
SetWindowText(hwndText[0],"revised");
SetFocus(hwndText[0]);
CreateWindow(TEXT("STATIC"), TEXT("Text1:"), WS_CHILD|WS_VISIBLE, 25, 100, 55, 22, hwnd, 0, hInstance, 0);
hWndBtn1 = CreateWindow(TEXT("BUTTON"), TEXT("Update"), WS_CHILD|WS_VISIBLE, 5, 5, 55, 22, hwnd, (HMENU) ID_MYBUTTON, hInstance, 0);
ShowWindow(hwnd, iCmdShow); //display the window on the screen
UpdateWindow(hwnd); //make sure the window is updated correctly
while(GetMessage(&msg, NULL, 0, 0)) //message loop
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK MyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
char data[256];
switch(msg)
{
case WM_KEYDOWN:
if (wParam==27) SetFocus(hwndText[1]);
break;
case WM_COMMAND:
if(ID_MYBUTTON == LOWORD(wParam))
{
if (BN_CLICKED==HIWORD(wParam)) {
GetWindowText(hwndText[0],data,255);
MessageBox(hwnd,data,"notice",MB_OK);
if ((fp=fopen("tom","w"))==NULL)
MessageBox(hwnd,"could not open wikiwin.txt","error",MB_OK);
fprintf(fp,"%s\n",data);
fclose(fp);
}
}
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}