Click here to Skip to main content
14,662,846 members
Home » Discussions » C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to stop flickering of controls in my Dialog window Pin
mo14921-Mar-19 3:33
Membermo14921-Mar-19 3:33 
AnswerRe: How to stop flickering of controls in my Dialog window Pin
leon de boer1-Mar-19 6:48
Memberleon de boer1-Mar-19 6:48 
QuestionDialog box margins Pin
Alexander Kindel21-Feb-19 0:24
MemberAlexander Kindel21-Feb-19 0:24 
AnswerRe: Dialog box margins Pin
Richard MacCutchan21-Feb-19 1:04
mveRichard MacCutchan21-Feb-19 1:04 
AnswerRe: Dialog box margins Pin
mo149221-Feb-19 8:45
Membermo149221-Feb-19 8:45 
GeneralRe: Dialog box margins Pin
Alexander Kindel21-Feb-19 9:30
MemberAlexander Kindel21-Feb-19 9:30 
GeneralRe: Dialog box margins Pin
mo149221-Feb-19 10:02
Membermo149221-Feb-19 10:02 
GeneralRe: Dialog box margins Pin
leon de boer22-Feb-19 6:05
Memberleon de boer22-Feb-19 6:05 
A blank empty dialog template centred in it's parent at runtime and done the way speedbump is suggesting is coded below. It is pretty straight forward you just need to allocate global memory block as the template and you can fill the controls in at initialization
int DialogFromTemplate (HWND parent, int DialogWth, int DialogHt, char* DlgTitle, DLGPROC handler)
{
   int nchar, ret;
   int x, y;
   RECT r;
   HGLOBAL hgbl;
   LPDLGTEMPLATE lpdt;
   LPWORD lpw;
   LPWSTR lpwsz;

   GetClientRect(parent, &r);	 	                                      // Get parent client area
   x =  ((r.right+r.left)/2);		                                     // Calc x client centre position
   y = ((r.bottom+r.top)/2);		                                     // Calc y client centre position

    /* from the client centre the dialog left is half width and top half height less */
    x -= DialogWth/2;
    y -= DialogHt/2;

   /* template size and position are in multiples of 2 .. yeah its weird */
    x /= 2;				                                       // X client left position in template units
    y /= 2;				                                       // Y client top position in template units
	
   hgbl = GlobalAlloc(GMEM_ZEROINIT, 1024);                               // Allocate memory
   if (!hgbl) return -1;		 	                                      // If allocate fail exit
   lpdt = (LPDLGTEMPLATE)GlobalLock(hgbl);                              // Lock the allocated memory
   lpdt->style = WS_POPUP | WS_CAPTION | WS_SYSMENU;  // Window style
   lpdt->cdit = 0;					  // Number of controls
   lpdt->x  = x;					  // X position
   lpdt->y  = y;					  // Y psoition
   lpdt->cx = DialogWth/2;				  // Window width (template units)
   lpdt->cy = DialogHt/2;				  // Window height (template units)
   lpw = (LPWORD)(lpdt + 1);				  // Set pointer address
   *lpw++ = 0;					  // No menu
   *lpw++ = 0;					  // Predefined dialog box class (by default)
   lpwsz = (LPWSTR)lpw;				  // Typecast pointer
   nchar = 1 + MultiByteToWideChar(CP_ACP, 0, DlgTitle, 
	  -1, lpwsz, 50);				  // Title of dialog
   lpw += nchar;					  // Increment by size of name
   *lpw++ = 0;					  // No creation data
   GlobalUnlock(hgbl);				  // Release lock on the memory block 
   ret = (int)DialogBoxIndirectParam(GetModuleHandle(0), 
     (LPDLGTEMPLATE)hgbl, parent, Handler,  0);		  // Create the dialog from template
   GlobalFree(hgbl);					  // Free the allocated memory
    return ret;				 	  // Return result
}

In vino veritas


modified 22-Feb-19 12:16pm.

GeneralRe: Dialog box margins Pin
mo149222-Feb-19 10:01
Membermo149222-Feb-19 10:01 
AnswerRe: Dialog box margins Pin
Maximilien22-Feb-19 4:23
MemberMaximilien22-Feb-19 4:23 
GeneralRe: Dialog box margins Pin
leon de boer22-Feb-19 5:39
Memberleon de boer22-Feb-19 5:39 
GeneralRe: Dialog box margins Pin
Maximilien23-Feb-19 1:49
MemberMaximilien23-Feb-19 1:49 
GeneralRe: Dialog box margins Pin
leon de boer23-Feb-19 4:30
Memberleon de boer23-Feb-19 4:30 
AnswerRe: Dialog box margins Pin
leon de boer22-Feb-19 5:37
Memberleon de boer22-Feb-19 5:37 
GeneralRe: Dialog box margins Pin
Alexander Kindel22-Feb-19 9:04
MemberAlexander Kindel22-Feb-19 9:04 
GeneralRe: Dialog box margins Pin
leon de boer22-Feb-19 10:00
Memberleon de boer22-Feb-19 10:00 
SuggestionRe: Dialog box margins Pin
David Crow24-Feb-19 16:23
MemberDavid Crow24-Feb-19 16:23 
QuestionTraceability of Dynamic Memory Allocation Faults Pin
HS_C_Student16-Feb-19 22:24
MemberHS_C_Student16-Feb-19 22:24 
AnswerRe: Traceability of Dynamic Memory Allocation Faults Pin
leon de boer17-Feb-19 20:53
Memberleon de boer17-Feb-19 20:53 
AnswerRe: Traceability of Dynamic Memory Allocation Faults Pin
Stefan_Lang18-Feb-19 0:15
mveStefan_Lang18-Feb-19 0:15 
AnswerRe: Traceability of Dynamic Memory Allocation Faults Pin
jschell23-Feb-19 10:41
Memberjschell23-Feb-19 10:41 
QuestionCeratingNameePipe Server Application Using C++ Classes Pin
Member 1271142615-Feb-19 0:23
MemberMember 1271142615-Feb-19 0:23 
AnswerRe: CeratingNameePipe Server Application Using C++ Classes Pin
Victor Nijegorodov15-Feb-19 1:03
MemberVictor Nijegorodov15-Feb-19 1:03 
GeneralRe: CeratingNameePipe Server Application Using C++ Classes Pin
Member 1271142615-Feb-19 4:53
MemberMember 1271142615-Feb-19 4:53 
GeneralRe: CeratingNameePipe Server Application Using C++ Classes Pin
Richard Andrew x6415-Feb-19 13:48
professionalRichard Andrew x6415-Feb-19 13:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.