Subject:
Re: MessageBox in Microwindows
From:
Jaswinder Singh ####@####.####
Date:
27 Nov 2000 01:14:22 -0000
Message-Id: <20001127011708.18260.qmail@web4001.mail.yahoo.com>
Dear Alan, Greg and others,
I am attaching test.c file , having MessageBox support
(function name is jMessageBox ).
Its limitation is :-
1 .Supporting only MB_OK
2. text and title of message box should be less than
80 characters
3. Display Text in Single line only.
I have tested this file in Windows only (not in
MicroWindows).
Please check this file and give your expert comments
:-)
Now i am porting this file to MicroWindows.
Thanks .
Best Regards,
Jaswinder.
--- Alan Cox ####@####.#### wrote:
> > Thanks , i will , but i think MessageBox is a must
> and
> > it would be good if you provide MessageBox in your
> > Microwindows.
>
> Add it and send in a patch.
__________________________________________________
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 */
char MessageBoxText[82];
LRESULT CALLBACK msgboxwproc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
int i;
switch (iMsg) {
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);
EndPaint(hwnd,&ps);
break;
default:
return DefWindowProc(hwnd,iMsg,wParam,lParam);
}
return (0);
}
int jMessageBox( 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;
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;
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,
0,
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);
jMessageBox(0, str , "NULL", MB_OK);
// jMessageBox(0, "1234567890123456" , "1234567890123456", MB_OK);
// jMessageBox(0, "123456789012345678901234567890" , "1234567890123456789012345678901234567890", MB_OK);
// jMessageBox(0, "12345678901234567890123456789012345678901234567890" , "12345678901234567890123456789012345678901234567890", MB_OK);
// jMessageBox(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);
}