Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
End Users
Pocket PCActiveSyncMultimediaEBooksWirelessSmartPhones
Developers
Windows MobileSmartPhonesWinCE ProgrammingVB for WinCEVC++ for WinCEPlatform BuilderTest Tools
PocketPC DirectoryFree SoftwareWeb Resources
Related Topics
PalmMobile PhonesMore Topics ...

Pocket PC Forum / Developers / SmartPhones / July 2008

Tip: Looking for answers? Try searching our database.

GetDlgItemInt and GetDlgItemText fails reading spinner list box

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dennisgr@algonet.se - 15 Jun 2008 12:09 GMT
I have a problem with GetDlgItemInt not working as expected on the
Smartphone platform. Here is my code:

.rc
LISTBOX IDC_166_INTERVAL, 104,  17,  17,  12, WS_TABSTOP |
CBS_DROPDOWN | WS_VSCROLL & ~LBS_SORT
CONTROL "",IDC_BUDDY_1,UPDOWN_CLASS,UDS_AUTOBUDDY|UDS_HORZ|
UDS_ARROWKEYS|UDS_SETBUDDYINT|UDS_WRAP|UDS_EXPANDABLE, 120, 17, 14, 12

.c
case WM_INITDIALOG:
...
for (iUpdateRateIdx=0;iUpdateRateIdx<NUM_UPDATE_RATES;iUpdateRateIdx+
+)
 SendDlgItemMessage (hWnd, IDC_166_INTERVAL, LB_ADDSTRING, 0,
(LPARAM)tszUpdateRate[iUpdateRateIdx]);
...
case WM_COMMAND:
...
iTmp = GetDlgItemInt(hWnd,IDC_166_INTERVAL,&Translated,TRUE);
if (Translated && 0 <= iTmp && iTmp <=30)

Translated is always false and iTmp subsequently 0 regardless of if I
selected 1, 2, 5, 10 or whatever. If I try using GetDlgItemText
instead it returns an empty string. How can this be? Aren't these
functions properly supported on the Smartphone platform?

I build my release versions in eVC3 for supporting all Pocket PC 2000
and later and Smartphone in one exe file. This is where I got the
error report from. For testing I use eVC4 and Smartphone emulator and
the symptom is exactly the same.

BR
Dennis Gröning
dennisgr@algonet.se - 06 Jul 2008 23:02 GMT
Problem solved. I hadn't realised that GetDlgItemText and thereby also
GetDlgItemInt doesn't work on list boxes.

The reason I got into this trouble was that I first developed a Pocket
PC application with combo boxes for selecting options. When trying it
in the smartphone emulator I found that combo boxes doesn't work on
the Smartphone platform. So I replaced the combo boxes with spinner
controls, that is a list box with a buddy control. Unfortunatly I
found that the old code using GetDlgItemText or GetDlgItemInt didn't
work. Further I also wanted the same executable to work both on Pocket
PC and Smartphone.

So my work-around was to make my own list box compatible functions.

UINT MyGetDlgItemText (HWND hDlg, int nIDDlgItem, LPTSTR lpString, int
nMaxCount)
{
    int iIdx, iTextLen;

    iIdx = SendDlgItemMessage (hDlg, nIDDlgItem, usCB_LB_GETCURSEL, 0,
0);
    if (iIdx == usCB_LB_ERR)
        return 0;
    iTextLen = SendDlgItemMessage (hDlg, nIDDlgItem,
(UINT)usCB_LB_GETTEXTLEN, (WPARAM)iIdx, 0);
    if (iTextLen == usCB_LB_ERR || iTextLen + 1 > nMaxCount)
        return 0;
    iTextLen = SendDlgItemMessage (hDlg, nIDDlgItem, usCB_LB_GETTEXT,
(WPARAM)iIdx, (LPARAM)lpString);
    if (iTextLen == usCB_LB_ERR)
        return 0;
    return iTextLen;
}

UINT MyGetDlgItemInt (HWND hDlg, int nIDDlgItem, BOOL *lpTranslated,
BOOL bSigned)
{
    int iTextLen, iVal;
    #define  nMaxCount 256
    TCHAR lpString[nMaxCount];

    iTextLen = MyGetDlgItemText (hDlg, nIDDlgItem, lpString, nMaxCount);
    if (iTextLen == 0) {
        *lpTranslated = FALSE;
        return 0;
    }

    *lpTranslated = TRUE;
    iVal = _ttoi(lpString);

    return iVal;
}

To use different but similarly named resources for smartphone I
created a second .rc with all related resource dialog templates
numbered with a fixed offset (ucRcOffset) in the header file but
control numbers identical. To avoid duplicating code I also assign
message macros to variables dependent on platform.

        case WM_CREATE:
            if (IsSmartPhone()) {
                ucRcOffset           = IDM_MENU_SP - IDM_MENU;
                usCB_LB_DELETESTRING = LB_DELETESTRING;
                usCB_LB_INSERTSTRING = LB_INSERTSTRING;
                usCB_LB_ADDSTRING    = LB_ADDSTRING;
                usCB_LB_SETCURSEL    = LB_SETCURSEL;
                usCB_LB_GETCURSEL    = LB_GETCURSEL;
                usCB_LB_GETTEXTLEN   = LB_GETTEXTLEN;
                usCB_LB_GETTEXT      = LB_GETTEXT;
                usCB_LB_ERR          = LB_ERR;
            }
            else
            {
                usCB_LB_DELETESTRING = CB_DELETESTRING;
                usCB_LB_INSERTSTRING = CB_INSERTSTRING;
                usCB_LB_ADDSTRING    = CB_ADDSTRING;
                usCB_LB_SETCURSEL    = CB_SETCURSEL;
                usCB_LB_GETCURSEL    = CB_GETCURSEL;
                usCB_LB_GETTEXTLEN   = CB_GETLBTEXTLEN;
                usCB_LB_GETTEXT      = CB_GETLBTEXT;
                usCB_LB_ERR          = CB_ERR;
            }

I think this should be useful for others trying to build a common
executable for Pocket PC and Smartphone.

Best Regards
Dennis Gröning
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.