-
User input edit box
I don't understand the examples of dialogs I've seen using the search feature.
Would one of you Guru's please explain to me how to get floats or doubles from my hEditX and Y boxes to variables so that I can utilize them.
I am beginning to think I'll never get this, or perhaps I need a different book.
Code:
#include <windows.h>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
HINSTANCE hInstGlobal;
HWND hEdit;
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
hInstGlobal = hInstance;
WNDCLASS WndClass;
WndClass.style = 0;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.lpfnWndProc = WndProc;
WndClass.hInstance = hInstance;
WndClass.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
WndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
WndClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
WndClass.lpszMenuName = 0;
WndClass.lpszClassName = "WinProg";
RegisterClass(&WndClass);
HWND hWindow;
hWindow = CreateWindow("WinProg", "Edit Field",
WS_OVERLAPPEDWINDOW,
0,0,640,400,NULL,NULL,
hInstance, NULL);
ShowWindow (hWindow, nCmdShow);
UpdateWindow (hWindow);
MSG Message;
while (GetMessage(&Message, NULL, 0, 0))
{
DispatchMessage(&Message);
}
return (Message.wParam);
}
LRESULT CALLBACK WndProc (HWND hWnd, UINT uiMessage,
WPARAM wParam, LPARAM lParam)
{
switch(uiMessage)
{
case WM_CREATE:
HWND hEditX, hEditY, hButtonExit, hButtonGroupBox, hButtonXCoord, hButtonYCoord;
hButtonGroupBox = CreateWindow("BUTTON", "Center",
WS_CHILD | WS_VISIBLE | BS_GROUPBOX,
5,5,225,90,
hWnd, (HMENU) 6,
hInstGlobal, NULL);
hButtonXCoord = CreateWindow("BUTTON", "X Coord",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | ES_READONLY, // Dont let user mess with this.
10,30,80, 20,
hWnd, (HMENU) 5,
hInstGlobal, NULL);
hButtonYCoord = CreateWindow("BUTTON", "Y Coord",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | ES_READONLY, // Dont let user mess with this.
10,60,80, 20,
hWnd, (HMENU) 4,
hInstGlobal, NULL);
hButtonExit = CreateWindow("BUTTON","EXIT",
WS_CHILD | WS_VISIBLE |BS_PUSHBUTTON,
480,320,140,20,
hWnd, (HMENU) 3,
hInstGlobal, NULL);
hEditX = CreateWindow("EDIT","",
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER | BS_DEFPUSHBUTTON, // Only digits does this allow floats?
100,30,120,20,
hWnd, (HMENU) 2,
hInstGlobal, NULL);
hEditY = CreateWindow("EDIT","",
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER,
100,60,120,20,
hWnd, (HMENU) 1,
hInstGlobal, NULL);
return 0;
case WM_COMMAND:
if(HIWORD(wParam) == BN_CLICKED) // BN = Button Notification. BS_PUSHBUTTON returns BN_CLICKED
{
if(LOWORD(wParam) == 1) // Store the Y coord. to variable.
{
/* char *string1;
string1 = new char[255]; // new float???
SendMessage (hEdit, WM_GETTEXT, 256,(LPARAM) string1); */
}
if(LOWORD(wParam) == 2) // Store the X coord. to variable.
{
}
if (LOWORD(wParam) == 3)
{
SendMessage (GetParent((HWND) lParam), // hWnd is the handle of a window object to which the message is sent.
WM_DESTROY ,0 ,0); // Msg is the value which identifies the message.
} // wParam is the first parameter of the message.
} // lParam is the second parameter of the message.
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc (hWnd, uiMessage, wParam, lParam);
}
}
-
How about:
GetDlgItemText(hWnd, IDC_A, buffer, sizeof(buffer) / sizeof(TCHAR));
I found this at : http://sunlightd.virtualave.net/Windows/GUI/
I think I shall throw away my book and just do the tutorial on this site.