Subject:
Re: MessageBox in Microwindows
From:
Jaswinder Singh ####@####.####
Date:
28 Nov 2000 02:43:48 -0000
Message-Id: <20001128024634.6461.qmail@web4003.mail.yahoo.com>
Dear Greg and others,
i have made some changes . second problem is some how
resolved but first problem still exist .
Can you please help me in rectifying this problem .
Thanks ,
Best Regards,
Jaswinder.
--- Greg Haerr ####@####.#### wrote:
> : 1. If i uncomment MwRegisterButtonControl(NULL);
> : I got OK Botton but Enter key does not work :-
> :
> : case WM_CHAR:
> : i = (int)wParam;
> : if ((i == 13 /* OK */) || (i == 27 /* ESC */)){
> : DestroyWindow(hwnd);
> : PostQuitMessage(0);
> : }
> :
> : and if i comment MwRegisterButtonControl(NULL);
> : then Button dont display .
> :
>
> The reason for this is a bit subtle. The problem is
> that when the OK button is active, it's got focus,
> and
> it doesn't send keystrokes to it's parent, so your
> MessageBoxProc never gets them.
>
> You should probably changed the button control
> so that either a space or Enter causes it to be
> pressed,
> and then it sends a CLICK event to it's parent,
> which
> dismisses the dialog box. Planning on having the
> controls
> send you their keystrokes isn't the way that Win32
> does
> it, so we probably shouldn't here.
>
> In the full-blown windows, the IsDialogMessage()
> function provides all sorts of trickyness that ends
> up keeping some keystrokes, and also implements
> the EndDialog() functionality that MessageBox should
> use, but isn't implemented yet.
>
>
>
> : 2.
> : DrawText(hdc, MessageBoxText, -1,
> : &rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
> :
> : is not aligned in the middle of Window .
>
>
> I can't remember if I hacked DT_CENTER yet
> or not. You might have to add it into
> src/mwin/wingdi.c. In
> addition, I'm sure that DT_VCENTER isn't done yet.
>
> I'd suggest adding them.
>
> Regards,
>
> Greg
>
__________________________________________________
Do You Yahoo!?
Yahoo! Shopping - Thousands of Stores. Millions of Products.
http://shopping.yahoo.com/
#include <windows.h>
#define FONTWIDTH 6 // Font width in pixels
#define OKBUTTONWIDTH 140 // OK button width in pixels
#define OKBUTTONHIGHT 40 // OK button height in pixels
#define X1 100 // half of default MessageBox width in pixels
#define Y1 100 // half of default MessageBox height in pixels
/*
* MessageBox() Flags
*/
#define MB_OK 0x00000000L /* supported */
#define MB_OKCANCEL 0x00000001L /* not supported */
#define MB_ABORTRETRYIGNORE 0x00000002L /* not supported */
#define MB_YESNOCANCEL 0x00000003L /* not supported */
#define MB_YESNO 0x00000004L /* not supported */
#define MB_RETRYCANCEL 0x00000005L /* not supported */
/*
* Dialog Box Command IDs
*/
#define IDOK 1
#define IDCANCEL 2
#define IDABORT 3
#define IDRETRY 4
#define IDIGNORE 5
#define IDYES 6
#define IDNO 7
#define IDCLOSE 8
#define IDHELP 9
char MessageBoxText[82];
int hic;
LRESULT CALLBACK msgboxwproc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
int i;
switch (iMsg) {
case WM_COMMAND:
if (LOWORD(wParam) == IDOK)
{
DestroyWindow(hwnd);
PostQuitMessage(0);
}
break;
case WM_CHAR:
i = (int)wParam;
if ((i == 13 /* OK */) || (i == 27 /* ESC */)){
DestroyWindow(hwnd);
PostQuitMessage(0);
}
break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
// DrawText(hdc, MessageBoxText, -1, &rect,
// DT_SINGLELINE|DT_CENTER|DT_VCENTER);
TextOut(hdc, hic - (strlen(MessageBoxText) * 4) , Y1/2, MessageBoxText , strlen(MessageBoxText));
EndPaint(hwnd,&ps);
break;
default:
return DefWindowProc(hwnd,iMsg,wParam,lParam);
}
return (0);
}
int MessageBox( HWND hWnd, // handle of owner window
LPCTSTR lpText, // address of text in message box
LPCTSTR lpCaption, // address of title of message box
UINT uType // style of message box
){
static char szAppName[]="MessageBox";
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
char Caption[82];
int it , ic;
int width, height;
RECT r;
GetWindowRect(GetDesktopWindow(), &r);
width = r.right / 2;
height = r.bottom / 2;
// MwRegisterButtonControl(NULL);
wndclass.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = (WNDPROC)msgboxwproc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = 0;
wndclass.hIcon = 0;
wndclass.hCursor = 0;
wndclass.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if (lpText == 0){
strcpy(MessageBoxText , "");
it = 0;
}
else{
strcpy(MessageBoxText , lpText);
it = (strlen(MessageBoxText) - 16) * FONTWIDTH;
}
if (lpCaption == 0){
strcpy(Caption , "MessageBox");
ic = 0;
}
else{
strcpy(Caption , lpCaption);
ic = (strlen(Caption) - 16) * FONTWIDTH;
}
if (it > ic)
ic = it;
if (ic < 0)
ic = 0;
hic = X1 + ic;
RegisterClass(&wndclass);
hwnd=CreateWindowEx(0L,
szAppName,
Caption,
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
width - X1 - ic,
height - Y1,
(X1 + ic)* 2,
Y1 * 2,
0,
0,
NULL,
NULL);
CreateWindowEx(0L,
"BUTTON",
"OK",
WS_CHILD | WS_VISIBLE,
X1 + ic - (OKBUTTONWIDTH)/2,
110,
OKBUTTONWIDTH, /* OK Button width */
OKBUTTONHIGHT, /* OK Button height */
hwnd,
(HMENU)IDOK,
NULL,
NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
while (GetMessage(&msg,NULL,0,0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK wproc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static char szAppName[]="HolaWin";
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = (WNDPROC)wproc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = 0;
wndclass.hIcon = 0;
wndclass.hCursor = 0;
wndclass.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
RegisterClass(&wndclass);
hwnd=CreateWindowEx(0L,
szAppName,
"Hola",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
0,
0,
NULL,
NULL);
ShowWindow(hwnd,iCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg,NULL,0,0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK wproc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
char str[82] , ch ;
int i;
switch (iMsg) {
case WM_CREATE:
break;
case WM_CHAR:
ch = (char)wParam;
i = (int)wParam;
if (i == 27 /*ESC*/){
DestroyWindow(hwnd);
PostQuitMessage(0);
}
else{
sprintf(str , "%c %d", ch , i);
MessageBox(0, str , "NULL", MB_OK);
// MessageBox(0, "1234567890123456" , "1234567890123456", MB_OK);
// MessageBox(0, "123456789012345678901234567890" , "1234567890123456789012345678901234567890", MB_OK);
// MessageBox(0, "12345678901234567890123456789012345678901234567890" , "12345678901234567890123456789012345678901234567890", MB_OK);
// MessageBox(0, "1234567890123456789012345678901234567890123456789012345678901234567890" , "1234567890123456789012345678901234567890123456789012345678901234567890", MB_OK);
}
break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
DrawText(hdc, "Press any key to see MessageBox, Press ESC to EXIT", -1, &rect,
DT_SINGLELINE|DT_CENTER|DT_VCENTER);
EndPaint(hwnd,&ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,iMsg,wParam,lParam);
}
return (0);
}