0
votes

Using C++ Win32 API, I've created a window ( CreateWindow() ) instead of a dialogue box. Are there any commands similar to "GetDlgItemInt" or "SetDlgItemInt" that is used for getting and setting data in an edit window for Win 32 API instead? Otherwise I'll have to make a dialogue box or do a heap of code for converting INTs to a string then back again.

The idea is that the user specifies the window width and height by typing in the two edit dialogue boxes within the window I have created. There are nice easy tutorials that basically tell me how to do that through a dialogue box, but I would like to know if there are similar functions that I can use that are not dependent on a dialogue box?

I'm hoping to have something like this...

xVal = 1280;
yVal = 720;
hwndResoX = CreateWindow("edit",xVal, WS_CHILD|WS_VISIBLE|WS_BORDER|ES_NUMBER,20,20,40,20, _hwnd, NULL, NULL, NULL);
hwndResoY = CreateWindow("edit",yVal, WS_CHILD|WS_VISIBLE|WS_BORDER|ES_NUMBER,80,20,40,20, _hwnd, NULL, NULL, NULL);

But as you can imagine, I can not use the xVal or yVal in the CreateWindow() because I get a compile error stating I can not convert from INT to CHAR*

2
I really don't understand you question. You start by talking about GetDlgItemInt and then you show code that only contains a call to CreateWindow? In any case the GetDlgItemInt API will work for any window hwnd provided the window hwnd has a child with the ID specified.mrsheen

2 Answers

0
votes

Simplest way to do this:

// Create the window. Note that for edits, the caption is not the same as its contents,
// so we leave that empty here:
hwndResoX = CreateWindow("edit","", WS_CHILD|WS_VISIBLE|WS_BORDER|ES_NUMBER,20,20,40,20, _hwnd, NULL, NULL, NULL);

// Now create a string to use to set as the content:
char content[32];
sprintf(content, "%d", xVal); // Recommend using StringCchPrintf if there's any chance that the buffer size might be too small
SetWindowText(hwndResoX, content);

See also this MSDN page on Using Edit Controls.

For getting the data back, use GetWindowText to get a string, then parse that using whichever string-to-int parsing function you want (eg. strtol, atoi, sscanf, etc.)

While you do have to convert manually between int and string, it's not all that much code, just a couple of extra lines, so a lot less hassle than converting to use a dialog.

Having said that, if you use a proper dialog here, you get a couple of extra benefits: notably the user can tab from field to field automatically, which you have to do extra work to enable in a non-dialog.

0
votes

You can use GetDlgItemInt, just specify an int ID for the HMENU parameter in CreateWindow.