nanogui: MessageBox in Microwindows


Previous by date: 27 Nov 2000 02:46:26 -0000 Re: MessageBox in Microwindows, WEI Yongming
Next by date: 27 Nov 2000 02:46:26 -0000 Re: MessageBox in Microwindows, Greg Haerr
Previous in thread: 27 Nov 2000 02:46:26 -0000 Re: MessageBox in Microwindows, WEI Yongming
Next in thread: 27 Nov 2000 02:46:26 -0000 Re: MessageBox in Microwindows, Greg Haerr

Subject: Re: MessageBox in Microwindows
From: Jaswinder Singh ####@####.####
Date: 27 Nov 2000 02:46:26 -0000
Message-Id: <20001127024910.23687.qmail@web4005.mail.yahoo.com>

Dear Alan , Greg and others,

--- Alan Cox ####@####.#### wrote:
> Looks a good basis to me. And OK/Cancel seems to
> come naturally from your
> existing code
> 

is it good or not !

I am facing some problems in porting this code to
MicroWindows :-

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 .

2.
                DrawText(hdc, MessageBoxText, -1,
&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);

is not aligned in the middle of Window .

How can i overcome this problems.

I am attaching mtest.c file , you can test this in
microwindows.

Thanks .

Best Regards,

Jaswinder.



__________________________________________________
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 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;

        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);
				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);
}

Previous by date: 27 Nov 2000 02:46:26 -0000 Re: MessageBox in Microwindows, WEI Yongming
Next by date: 27 Nov 2000 02:46:26 -0000 Re: MessageBox in Microwindows, Greg Haerr
Previous in thread: 27 Nov 2000 02:46:26 -0000 Re: MessageBox in Microwindows, WEI Yongming
Next in thread: 27 Nov 2000 02:46:26 -0000 Re: MessageBox in Microwindows, Greg Haerr


Powered by ezmlm-browse 0.20.