ReactOS  0.4.14-dev-1007-g90d795b
memdlg.c
Go to the documentation of this file.
1 /*
2  * ReactOS Standard Dialog Application Template
3  *
4  * memdlg.c
5  *
6  * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22 
23 #define WIN32_LEAN_AND_MEAN
24 #include <windows.h>
25 #include <tchar.h>
26 #include "trace.h"
27 
28 
29 extern HINSTANCE hInst;
30 
31 #define ID_HELP 150
32 #define ID_TEXT 200
33 
35 
37 {
38  return 0;
39 }
40 
42 {
43  ULONG_PTR ul;
44 
45  ul = (ULONG_PTR)lpIn;
46  ul += 3;
47  ul >>= 2;
48  ul <<= 2;
49  return (LPWORD)ul;
50 }
51 
53 // Create an in memory dialog resource and display.
54 // Note: this doesn't work
55 //
57 {
58  HGLOBAL hgbl;
59  LPDLGTEMPLATE lpdt;
60  LPDLGITEMTEMPLATE lpdit;
61  LPWORD lpw;
62  LPWSTR lpwsz;
63  LRESULT ret;
64  int nchar;
65 
66  hgbl = GlobalAlloc(GMEM_ZEROINIT, 1024);
67  if (!hgbl)
68  return -1;
69 
70  lpdt = (LPDLGTEMPLATE)GlobalLock(hgbl);
71 
72  // Define a dialog box.
74  lpdt->cdit = 3; // number of controls
75  lpdt->x = 10; lpdt->y = 10;
76  lpdt->cx = 100; lpdt->cy = 100;
77  lpw = (LPWORD)(lpdt + 1);
78  *lpw++ = 0; // no menu
79  *lpw++ = 0; // predefined dialog box class (by default)
80 
81  lpwsz = (LPWSTR)lpw;
82  nchar = 1 + MultiByteToWideChar(CP_ACP, 0, "My Dialog", -1, lpwsz, 50);
83  lpw += nchar;
84 
85  //-----------------------
86  // Define an OK button.
87  //-----------------------
88  lpw = lpwAlign(lpw); // align DLGITEMTEMPLATE on DWORD boundary
89  lpdit = (LPDLGITEMTEMPLATE)lpw;
90  lpdit->x = 10; lpdit->y = 70;
91  lpdit->cx = 80; lpdit->cy = 20;
92  lpdit->id = IDOK; // OK button identifier
94 
95  lpw = (LPWORD)(lpdit + 1);
96  *lpw++ = 0xFFFF;
97  *lpw++ = 0x0080; // button class
98 
99  lpwsz = (LPWSTR)lpw;
100  nchar = 1 + MultiByteToWideChar(CP_ACP, 0, "OK", -1, lpwsz, 50);
101  lpw += nchar;
102  lpw = lpwAlign(lpw); // align creation data on DWORD boundary
103  *lpw++ = 0; // no creation data
104 
105  //-----------------------
106  // Define a Help button.
107  //-----------------------
108  lpw = lpwAlign(lpw); // align DLGITEMTEMPLATE on DWORD boundary
109  lpdit = (LPDLGITEMTEMPLATE)lpw;
110  lpdit->x = 55; lpdit->y = 10;
111  lpdit->cx = 40; lpdit->cy = 20;
112  lpdit->id = ID_HELP; // Help button identifier
113  lpdit->style = WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON;
114 
115  lpw = (LPWORD)(lpdit + 1);
116  *lpw++ = 0xFFFF;
117  *lpw++ = 0x0080; // button class atom
118 
119  lpwsz = (LPWSTR)lpw;
120  nchar = 1 + MultiByteToWideChar(CP_ACP, 0, "Help", -1, lpwsz, 50);
121  lpw += nchar;
122  lpw = lpwAlign(lpw); // align creation data on DWORD boundary
123  *lpw++ = 0; // no creation data
124 
125  //-----------------------
126  // Define a static text control.
127  //-----------------------
128  lpw = lpwAlign(lpw); // align DLGITEMTEMPLATE on DWORD boundary
129  lpdit = (LPDLGITEMTEMPLATE)lpw;
130  lpdit->x = 10; lpdit->y = 10;
131  lpdit->cx = 40; lpdit->cy = 20;
132  lpdit->id = ID_TEXT; // text identifier
133  lpdit->style = WS_CHILD | WS_VISIBLE | SS_LEFT;
134 
135  lpw = (LPWORD)(lpdit + 1);
136  *lpw++ = 0xFFFF;
137  *lpw++ = 0x0082; // static class
138 
139  for (lpwsz = (LPWSTR)lpw;
140  *lpwsz++ == (WCHAR)*lpszMessage++;
141  );
142  lpw = (LPWORD)lpwsz;
143  lpw = lpwAlign(lpw); // align creation data on DWORD boundary
144  *lpw++ = 0; // no creation data
145 
146  GlobalUnlock(hgbl);
148  if (ret == 0) {
149  TRACE(_T("DialogBoxIndirect() failed due to invalid handle to parent window: 0x%08X"), hwndOwner);
150  } else if (ret == -1) {
152  TRACE(_T("DialogBoxIndirect() failed, GetLastError returned 0x%08X"), error);
153  }
154  GlobalFree(hgbl);
155  return ret;
156 }
157 
HINSTANCE hInst
Definition: dxdiag.c:13
Definition: tftpd.h:59
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
#define IDOK
Definition: winuser.h:824
#define error(str)
Definition: mkdosfs.c:1605
#define CP_ACP
Definition: compat.h:99
#define CALLBACK
Definition: compat.h:27
#define BS_DEFPUSHBUTTON
Definition: pedump.c:652
DWORD style
Definition: winuser.h:3034
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
UINT_PTR WPARAM
Definition: windef.h:207
#define WS_CHILD
Definition: pedump.c:617
char * LPSTR
Definition: xmlstorage.h:182
WPARAM wParam
Definition: combotst.c:138
uint32_t ULONG_PTR
Definition: typedefs.h:64
#define DS_MODALFRAME
Definition: winuser.h:375
#define SS_LEFT
Definition: pedump.c:692
LONG_PTR LPARAM
Definition: windef.h:208
struct DLGTEMPLATE * LPDLGTEMPLATE
#define WS_CAPTION
Definition: pedump.c:624
#define _T(x)
Definition: vfdio.h:22
#define DialogBoxIndirect
Definition: winuser.h:5737
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
LPWORD lpwAlign(LPWORD lpIn)
Definition: memdlg.c:41
int ret
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
short x
Definition: winuser.h:3037
short y
Definition: winuser.h:3038
#define BS_PUSHBUTTON
Definition: pedump.c:651
WORD cdit
Definition: winuser.h:3036
INT_PTR(CALLBACK * DLGPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2871
uint16_t * LPWORD
Definition: typedefs.h:55
LRESULT CALLBACK DialogWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: memdlg.c:36
#define WS_BORDER
Definition: pedump.c:625
#define ID_HELP
Definition: memdlg.c:31
#define WS_POPUP
Definition: pedump.c:616
unsigned int UINT
Definition: ndis.h:50
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
short cy
Definition: winuser.h:3040
#define MultiByteToWideChar
Definition: compat.h:100
struct DLGITEMTEMPLATE * LPDLGITEMTEMPLATE
static HINSTANCE hinst
Definition: edit.c:551
#define ULONG_PTR
Definition: config.h:101
#define ID_TEXT
Definition: memdlg.c:32
WCHAR * LPWSTR
Definition: xmlstorage.h:184
LONG_PTR LRESULT
Definition: windef.h:209
short cx
Definition: winuser.h:3039
#define WS_VISIBLE
Definition: pedump.c:620
#define WS_SYSMENU
Definition: pedump.c:629
LRESULT CreateMemoryDialog(HINSTANCE hinst, HWND hwndOwner, LPSTR lpszMessage)
Definition: memdlg.c:56
LPARAM lParam
Definition: combotst.c:139
#define GMEM_ZEROINIT
Definition: winbase.h:303