• Advertisement
Sign in to follow this  

Sizing edit controls in DialogBoxIndirectParam

This topic is 3319 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm creating a dialog box from a template using DialogBoxIndirectParam. It mostly works except that I can't get the size of the edit controls correct. The link below is a picture of the result. The edit controls are too wide and they look like they are too tall also. I have read threads that say you don't really need to use dialog box units, so I'm trying to use pixels as the units. Can someone explain how to get the edit controls to be the right width and height for 32 characters? The first row allowed more than 32 characters. The second row shows how the highlighting looks. Does anyone know how to size the edit controls properly? http://www.mccourry.net/pic.jpg WORD *p; int nchar, k, col1, col2, dy, iy, len, size; int w, h, bw, bh, max_label_len, max_edit_len; int avgWidth, avgHeight; int fontsize; float pct = 1.2f; long lstyle; char str[32]; HDC hdc; SIZE sz; HFONT hFontOld, hfont; char face[16] = "Arial"; phwnd = _phwnd; strncpy(title, _title, sizeof(title)-1); n = _n; ec = _ec; hInstance = GetModuleHandle(NULL); exit_status = 0; max_label_len = -1; max_edit_len = -1; hdc = GetDC(phwnd); fontsize = 10; hfont = CreateFont( -fontsize, 0, 0, 0, 100, TRUE, 0, 0, ANSI_CHARSET, OUT_STRING_PRECIS, CLIP_TT_ALWAYS, PROOF_QUALITY, FIXED_PITCH | FF_SWISS, face ); hFontOld = (HFONT)SelectObject(hdc, hfont); strcpy(str, "x"); GetTextExtentPoint32(hdc, str, strlen(str), &sz); avgWidth = sz.cx; avgHeight = sz.cy; DeleteObject(hfont); hfont = NULL; SelectObject(hdc, hFontOld); dy = ROUND(pct*avgHeight); for(k=0;k<n;k++) { len = strlen(ec[k].label); max_label_len = MAX(max_label_len, len); len = strlen(ec[k].str); max_edit_len = MAX(max_edit_len, len); } size = 78 + n*42; size *= 4; int ii = sizeof(ec[0].str); col1 = 10; col2 = col1 + max_label_len*avgWidth + 5; w = col1 + avgWidth*max_label_len + 5 + avgWidth*ii + col1; h = ROUND(n*pct*avgHeight + 50); pdlgtemplate = p = (PWORD) LocalAlloc (LPTR, size); lstyle = WS_CAPTION | WS_SYSMENU | DS_SETFONT | WS_VISIBLE | DS_MODALFRAME | WS_POPUP ; *p++ = LOWORD (lstyle); *p++ = HIWORD (lstyle); *p++ = 0; *p++ = 0; *p++ = 2 + n*2; *p++ = 0; *p++ = 0; *p++ = w; *p++ = h; *p++ = 0; *p++ = 0; nchar = nCopyAnsiToWideChar(p, TEXT(title)); p += nchar; *p++ = fontsize; nchar = nCopyAnsiToWideChar (p, TEXT("Arial")); p += nchar; p = lpwAlign (p); iy = -dy + 10; //---------------- // //---------------- for(k=0;k<n;k++) { //------------ // the label //------------ iy += dy; GetTextExtentPoint32(hdc, ec[k].label, strlen(ec[k].label), &sz); lstyle = WS_VISIBLE | WS_CHILD; *p++ = LOWORD (lstyle); *p++ = HIWORD (lstyle); *p++ = 0; *p++ = 0; *p++ = col1; *p++ = iy; *p++ = (WORD)sz.cx; *p++ = (WORD)sz.cy; *p++ = 0; nchar = nCopyAnsiToWideChar (p, TEXT("STATIC")); p += nchar; nchar = nCopyAnsiToWideChar (p, TEXT(ec[k].label)); p += nchar; *p++ = 0; p = lpwAlign (p); //----------------------------------------- // edit control //----------------------------------------- int ew = avgWidth*sizeof(ec[0].str); int eh = avgHeight; lstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP; *p++ = LOWORD (lstyle); *p++ = HIWORD (lstyle); *p++ = 0; *p++ = 0; *p++ = col2; *p++ = iy; *p++ = ew; *p++ = eh; *p++ = 99+k; nchar = nCopyAnsiToWideChar (p, TEXT("EDIT")); p += nchar; nchar = nCopyAnsiToWideChar (p, TEXT("")); p += nchar; *p++ = 0; p = lpwAlign (p); } // for(k.... p = lpwAlign (p); iy += 2*dy; //----------------------------------------- // ok button //----------------------------------------- bw = 30; bh = 15; col1 = ROUND(.28f*w - .5*bw); col2 = ROUND(.71f*w - .5*bw); lstyle = BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | WS_TABSTOP; *p++ = LOWORD (lstyle); *p++ = HIWORD (lstyle); *p++ = 0; *p++ = 0; *p++ = col1; *p++ = iy; *p++ = bw; *p++ = bh; *p++ = IDOK; nchar = nCopyAnsiToWideChar (p, TEXT("BUTTON")); p += nchar; nchar = nCopyAnsiToWideChar (p, TEXT("OK")); p += nchar; *p++ = 0; p = lpwAlign (p); //----------------------------------------- // cancel button //----------------------------------------- lstyle = BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | WS_TABSTOP; *p++ = LOWORD (lstyle); *p++ = HIWORD (lstyle); *p++ = 0; *p++ = 0; *p++ = col2; *p++ = iy; *p++ = bw; *p++ = bh; *p++ = IDCANCEL; nchar = nCopyAnsiToWideChar (p, TEXT("BUTTON")); p += nchar; nchar = nCopyAnsiToWideChar (p, TEXT("Cancel")); p += nchar; *p++ = 0; exit_status = DialogBoxIndirectParam(hInstance, (LPDLGTEMPLATE) pdlgtemplate, phwnd, (DLGPROC) dlg, (LPARAM)this); LocalFree (LocalHandle (pdlgtemplate));

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement