ReactOS 0.4.15-dev-5666-gc548b97
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
29extern 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;
61 LPWORD lpw;
62 LPWSTR lpwsz;
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
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
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define DLGPROC
Definition: maze.c:62
#define CP_ACP
Definition: compat.h:109
#define CALLBACK
Definition: compat.h:35
#define MultiByteToWideChar
Definition: compat.h:110
#define ULONG_PTR
Definition: config.h:101
unsigned long DWORD
Definition: ntddk_ex.h:95
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
HGLOBAL NTAPI GlobalFree(HGLOBAL hMem)
Definition: heapmem.c:611
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190
HGLOBAL NTAPI GlobalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:368
LPWORD lpwAlign(LPWORD lpIn)
Definition: memdlg.c:41
LRESULT CALLBACK DialogWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: memdlg.c:36
LRESULT CreateMemoryDialog(HINSTANCE hinst, HWND hwndOwner, LPSTR lpszMessage)
Definition: memdlg.c:56
#define ID_HELP
Definition: memdlg.c:31
HINSTANCE hInst
Definition: dxdiag.c:13
#define ID_TEXT
Definition: memdlg.c:32
#define error(str)
Definition: mkdosfs.c:1605
static HINSTANCE hinst
Definition: edit.c:551
unsigned int UINT
Definition: ndis.h:50
#define WS_CHILD
Definition: pedump.c:617
#define WS_CAPTION
Definition: pedump.c:624
#define WS_SYSMENU
Definition: pedump.c:629
#define WS_BORDER
Definition: pedump.c:625
#define WS_POPUP
Definition: pedump.c:616
#define WS_VISIBLE
Definition: pedump.c:620
#define SS_LEFT
Definition: pedump.c:692
#define BS_PUSHBUTTON
Definition: pedump.c:651
#define BS_DEFPUSHBUTTON
Definition: pedump.c:652
#define TRACE(s)
Definition: solgame.cpp:4
WORD cdit
Definition: winuser.h:3051
short y
Definition: winuser.h:3053
short cy
Definition: winuser.h:3055
DWORD style
Definition: winuser.h:3049
short x
Definition: winuser.h:3052
short cx
Definition: winuser.h:3054
Definition: tftpd.h:60
uint16_t * LPWORD
Definition: typedefs.h:56
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define _T(x)
Definition: vfdio.h:22
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
#define GMEM_ZEROINIT
Definition: winbase.h:306
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define DialogBoxIndirect
Definition: winuser.h:5752
#define DS_MODALFRAME
Definition: winuser.h:375
#define IDOK
Definition: winuser.h:824
struct DLGITEMTEMPLATE * LPDLGITEMTEMPLATE
struct DLGTEMPLATE * LPDLGTEMPLATE
char * LPSTR
Definition: xmlstorage.h:182
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184