4 * Copyright 2000 Mike McCormack <Mike_McCormack@looksmart.com.au>
5 * Copyright 1997,98 Marcel Baur <mbaur@g26.ethz.ch>
6 * To be distributed under the Wine License
9 * - Use wine Heap instead of malloc/free (done)
10 * - use scroll bars (vertical done)
11 * - cut 'n paste (clipboard)
15 * - encapsulate data structures (?) - half done
16 * - free unused memory
17 * - solve Open problems
18 * - smoother scrolling
19 * - separate view code and document code
21 * This program is intended as a testbed for winelib as much as
22 * a useful application.
33 extern BOOL FileExists(LPCSTR szFilename);
34 extern BOOL DoCloseFile(void);
35 extern void DoOpenFile(LPCSTR szFileName);
37 NOTEPAD_GLOBALS Globals;
40 /* Using a pointer to pointer data structure to
41 achieve a little more efficiency. Hopefully
42 it will be worth it, because it complicates the
43 code - mjm 26 Jun 2000 */
45 #define BUFFERCHUNKSIZE 0xe0
46 typedef struct TAGLine {
52 /* FIXME: make this info into a structure */
53 /* typedef struct tagBUFFER { */
58 DWORD dwXpos=0,dwYpos=0; /* position of caret in char coords */
59 DWORD dwCaretXpos=0,dwCaretYpos=0; /* position of caret in pixel coords */
60 TEXTMETRIC tm; /* textmetric for current font */
61 RECT rectClient; /* client rectangle of the window we're drawing in */
62 /* } BUFFER, *LPBUFFER */
64 VOID InitFontInfo(HWND hWnd)
66 HDC hDC = GetDC(hWnd);
70 GetTextMetrics(hDC, &tm);
84 /* convert x,y character co-ords into x pixel co-ord */
85 DWORD CalcStringWidth(HDC hDC, DWORD x, DWORD y)
97 if(lpBuffer[y].lpLine == NULL)
99 len = (x<lpBuffer[y].dwWidth) ?
100 x : lpBuffer[y].dwWidth;
101 GetTextExtentPoint(hDC, lpBuffer[y].lpLine, len, &size);
106 void CalcCaretPos(HDC hDC, DWORD dwXpos, DWORD dwYpos)
108 dwCaretXpos = CalcStringWidth(hDC, dwXpos, dwYpos);
109 dwCaretYpos = tm.tmHeight*(dwYpos-dwVOffset);
110 SetCaretPos(dwCaretXpos,dwCaretYpos);
113 DWORD GetLinesPerPage(HWND hWnd)
115 return (rectClient.bottom/tm.tmHeight); /* round down */
118 /* render one line of text and blank space */
119 void RenderLine(HDC hDC, DWORD lineno)
127 /* erase the space at the end of a line using a white rectangle */
128 rect.top = tm.tmHeight*(lineno-dwVOffset);
129 rect.bottom = tm.tmHeight*(lineno-dwVOffset+1);
131 if(lpBuffer && (lineno<dwLines))
132 rect.left = CalcStringWidth(hDC, lpBuffer[lineno].dwWidth,lineno);
135 rect.right = rectClient.right;
137 /* use the white pen so there's not outline */
138 hPrev = SelectObject(hDC, GetStockObject(WHITE_PEN));
139 Rectangle(hDC, rect.left, rect.top, rect.right, rect.bottom);
140 SelectObject(hDC, hPrev);
142 if(lpBuffer && lpBuffer[lineno].lpLine)
144 TextOut(hDC, 0, rect.top, lpBuffer[lineno].lpLine,
145 lpBuffer[lineno].dwWidth);
150 * Paint the buffer onto the window.
152 void RenderWindow(HDC hDC) {
158 /* FIXME: render only necessary lines */
159 for(i = dwVOffset; i < (dwVOffset+GetLinesPerPage(0)); i++)
166 * Check that correct buffers exist to access line y pos x
167 * Only manages memory.
169 * Returns TRUE if the line is accessable
170 * FALSE if there is a problem
172 BOOL ValidateLine(DWORD y,DWORD x)
176 /* check to see that the BUFFER has enough lines */
178 if( (max<=y) || (lpBuffer == NULL))
181 max += BUFFERCHUNKSIZE;
182 /* use GlobalAlloc first time round */
184 lpBuffer = (LPLINE) GlobalReAlloc((HGLOBAL)lpBuffer,GMEM_FIXED,
187 lpBuffer = (LPLINE) GlobalAlloc(GMEM_FIXED, max*sizeof(LINE));
190 ZeroMemory(&lpBuffer[dwLines], sizeof(LINE)*(max-dwLines) );
194 /* check to see that the LINE is wide enough */
195 max = lpBuffer[y].dwMaxWidth;
196 if( (max <= x) || (lpBuffer[y].lpLine == NULL) )
199 max += BUFFERCHUNKSIZE;
200 /* use GlobalAlloc first */
201 if(lpBuffer[y].lpLine)
202 lpBuffer[y].lpLine = (LPSTR)GlobalReAlloc((HGLOBAL)lpBuffer[y].lpLine,
205 lpBuffer[y].lpLine = (LPSTR)GlobalAlloc( GMEM_FIXED, max);
206 if(lpBuffer[y].lpLine == NULL)
208 lpBuffer[y].dwWidth = 0;
209 lpBuffer[y].dwMaxWidth = max;
214 /* inserts a new line into the buffer */
215 BOOL DoNewLine(HDC hDC)
220 /* check to see if we need more memory for the buffer pointers */
221 if(!ValidateLine(dwLines,0))
224 /* shuffle up all the lines */
225 for(i=dwLines; i>(dwYpos+1); i--)
227 lpBuffer[i] = lpBuffer[i-1];
230 ZeroMemory(&lpBuffer[dwYpos+1],sizeof(LINE));
232 /* copy the characters after the carat (if any) to the next line */
233 src = &lpBuffer[dwYpos].lpLine[dwXpos];
234 cnt = lpBuffer[dwYpos].dwWidth-dwXpos;
235 if(!ValidateLine(dwYpos+1,cnt)) /* allocates the buffer */
236 return FALSE; /* FIXME */
237 dst = &lpBuffer[dwYpos+1].lpLine[0];
238 memcpy(dst, src, cnt);
239 lpBuffer[dwYpos+1].dwWidth = cnt;
240 lpBuffer[dwYpos].dwWidth -= cnt;
242 /* move the cursor */
247 /* update the window */
248 RenderLine(hDC, dwYpos-1);
249 RenderLine(hDC, dwYpos);
250 CalcCaretPos(hDC, dwXpos, dwYpos);
251 /* FIXME: don't use globals */
252 SetScrollRange(Globals.hMainWnd, SB_VERT, 0, dwLines, TRUE);
258 * Attempt a basic edit buffer
260 BOOL AddCharToBuffer(HDC hDC, char ch)
262 /* we can use lpBuffer[dwYpos] */
263 if(!ValidateLine(dwYpos,0))
266 /* shuffle the rest of the line*/
267 if(!ValidateLine(dwYpos, lpBuffer[dwYpos].dwWidth))
269 lpBuffer[dwYpos].dwWidth++;
270 memmove(&lpBuffer[dwYpos].lpLine[dwXpos+1],
271 &lpBuffer[dwYpos].lpLine[dwXpos],
272 lpBuffer[dwYpos].dwWidth-dwXpos);
274 /* add the character */
275 lpBuffer[dwYpos].lpLine[dwXpos] = ch;
280 /* update the window and cursor position */
281 RenderLine(hDC,dwYpos);
282 CalcCaretPos(hDC,dwXpos,dwYpos);
288 /* erase a character */
289 BOOL DoBackSpace(HDC hDC)
295 if(lpBuffer[dwYpos].lpLine && (dwXpos>0))
298 /* FIXME: use memmove */
299 for(i=dwXpos; i<(lpBuffer[dwYpos].dwWidth-1); i++)
300 lpBuffer[dwYpos].lpLine[i]=lpBuffer[dwYpos].lpLine[i+1];
302 lpBuffer[dwYpos].dwWidth--;
303 RenderLine(hDC, dwYpos);
304 CalcCaretPos(hDC,dwXpos,dwYpos);
308 /* Erase a newline. To do this we join two lines */
315 oldlen = lpBuffer[dwYpos-1].dwWidth;
316 if(lpBuffer[dwYpos-1].lpLine&&lpBuffer[dwYpos].lpLine)
318 /* concatonate to the end of the line above line */
319 src = &lpBuffer[dwYpos].lpLine[0];
320 dest = &lpBuffer[dwYpos-1].lpLine[lpBuffer[dwYpos-1].dwWidth];
321 len = lpBuffer[dwYpos].dwWidth;
323 /* check the length of the new line */
324 if(!ValidateLine(dwYpos-1,lpBuffer[dwYpos-1].dwWidth + len))
327 memcpy(dest,src,len);
328 lpBuffer[dwYpos-1].dwWidth+=len;
329 GlobalFree( (HGLOBAL)lpBuffer[dwYpos].lpLine);
331 else if (!lpBuffer[dwYpos-1].lpLine)
333 lpBuffer[dwYpos-1]=lpBuffer[dwYpos];
334 } /* else both are NULL */
335 RenderLine(hDC,dwYpos-1);
337 /* don't zero - it's going to get trashed anyhow */
339 /* shuffle up all the lines below this one */
340 for(i=dwYpos; i<(dwLines-1); i++)
342 lpBuffer[i] = lpBuffer[i+1];
346 /* clear the last line */
347 ZeroMemory(&lpBuffer[dwLines-1],sizeof (LINE));
348 RenderLine(hDC,dwLines-1);
351 /* adjust the cursor position to joining point */
355 CalcCaretPos(hDC,dwXpos,dwYpos);
356 SetScrollRange(Globals.hMainWnd, SB_VERT, 0, dwLines, TRUE);
361 /* as used by File->New */
362 void TrashBuffer(void)
366 /* variables belonging to the buffer */
369 for(i=0; i<dwLines; i++)
371 if(lpBuffer[i].lpLine)
372 GlobalFree ((HGLOBAL)lpBuffer[i].lpLine);
373 ZeroMemory(&lpBuffer[i],sizeof (LINE));
375 GlobalFree((HGLOBAL)lpBuffer);
381 /* variables belonging to the view */
385 /* FIXME: don't use globals */
386 SetScrollPos(Globals.hMainWnd, SB_VERT, dwVOffset, FALSE);
387 SetScrollRange(Globals.hMainWnd, SB_VERT, 0, dwLines, TRUE);
392 * Add a line to the buffer
394 /* FIXME: this breaks lines longer than BUFFERCHUNKSIZE */
396 LPSTR buffer, /* pointer to buffer with file data */
397 DWORD size, /* number of bytes available in buffer */
405 for(i=0; i<size; i++)
409 if(ValidateLine(dwLines,i))
411 memcpy(&lpBuffer[dwLines].lpLine[0],&buffer[0],i);
412 lpBuffer[dwLines].dwWidth = i;
419 /* make a line of the rest */
420 if( (i == BUFFERCHUNKSIZE) || nomore )
422 if(ValidateLine(dwLines,i))
424 memcpy(&lpBuffer[dwLines].lpLine[0],&buffer[0],i);
425 lpBuffer[dwLines].dwWidth = i;
436 * This is probably overcomplicated by lpBuffer data structure...
437 * Read blocks from the file, then add each line from the
438 * block to the buffer until there is none left. If all
439 * a slab isn't used, try load some more data from the file.
441 void LoadBufferFromFile(LPCSTR szFileName)
445 DWORD size,i,len,bytes_left,bytes_read;
447 hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
448 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
449 if(hFile == INVALID_HANDLE_VALUE)
451 size = BUFFERCHUNKSIZE;
452 pTemp = (LPSTR) GlobalAlloc(GMEM_FIXED, size);
455 bytes_read = 1; /* anything non-zero */
464 bytes_left+=bytes_read;
466 /* add strings to buffer */
469 (len = CreateLine(&pTemp[i], bytes_left, !bytes_read));
470 i+= len,bytes_left-=len );
472 /* move leftover to front of buffer */
474 memmove(&pTemp[0],&pTemp[i], bytes_left);
479 BOOL DoInput(HDC hDC, WPARAM wParam, LPARAM lParam)
484 return DoBackSpace(hDC);
486 return DoNewLine(hDC);
488 return AddCharToBuffer(hDC,wParam);
492 BOOL GotoHome(HWND hWnd)
500 BOOL GotoEndOfLine(HWND hWnd)
502 dwXpos = lpBuffer[dwYpos].dwWidth;
506 BOOL GotoDown(HWND hWnd)
508 if((dwYpos+1) >= dwLines)
513 if (dwXpos>lpBuffer[dwYpos].dwWidth)
518 BOOL GotoUp(HWND hWnd)
523 if (dwXpos>lpBuffer[dwYpos].dwWidth)
528 BOOL GotoLeft(HWND hWnd)
536 return GotoEndOfLine(hWnd);
540 BOOL GotoRight(HWND hWnd)
542 if(dwXpos<lpBuffer[dwYpos].dwWidth)
553 /* check the caret is still on the screen */
554 BOOL ScrollABit(HWND hWnd)
561 if(dwYpos>(dwVOffset+GetLinesPerPage(hWnd)))
563 dwVOffset = dwYpos - GetLinesPerPage(hWnd) + 1;
569 /* FIXME: move the window around so we can still see the caret */
570 VOID DoEdit(HWND hWnd, WPARAM wParam, LPARAM lParam)
578 case VK_HOME: GotoHome(hWnd);
581 case VK_END: GotoEndOfLine(hWnd);
584 case VK_LEFT: GotoLeft(hWnd);
587 case VK_RIGHT: GotoRight(hWnd);
590 case VK_DOWN: GotoDown(hWnd);
593 case VK_UP: GotoUp(hWnd);
603 CalcCaretPos(hDC, dwXpos, dwYpos);
607 InvalidateRect(hWnd, NULL, FALSE);
610 void ButtonDownToCaretPos(HWND hWnd, WPARAM wParam, LPARAM lParam)
612 DWORD x, y, caretx, carety;
613 BOOL refine_guess = TRUE;
619 caretx = x/tm.tmAveCharWidth; /* guess */
620 carety = dwVOffset + y/tm.tmHeight;
628 refine_guess = FALSE;
631 /* if the cursor is past the bottom, put it after the last char */
632 if(refine_guess && (carety>=dwLines) )
635 caretx=lpBuffer[carety].dwWidth;
636 refine_guess = FALSE;
639 /* cursor past end of line? */
640 if(refine_guess && (x>CalcStringWidth(hDC,lpBuffer[carety].dwWidth,carety)))
642 caretx = lpBuffer[carety].dwWidth;
643 refine_guess = FALSE;
646 /* FIXME: doesn't round properly */
649 if(CalcStringWidth(hDC,caretx,carety)<x)
651 while( (caretx<lpBuffer[carety].dwWidth) &&
652 (CalcStringWidth(hDC,caretx+1,carety)<x))
657 while((caretx>0)&&(CalcStringWidth(hDC,caretx-1,carety)>x))
662 /* set the caret's position */
665 CalcCaretPos(hDC, caretx, carety);
669 void DoScroll(HWND hWnd, WPARAM wParam, LPARAM lParam)
671 DWORD dy = GetLinesPerPage(hWnd);
673 switch(wParam) /* vscroll code */
680 if(dwVOffset<dwLines)
684 if( (dy+dwVOffset) > dwLines)
685 dwVOffset = dwLines - 1;
692 /* position scroll */
693 SetScrollPos(hWnd, SB_VERT, dwVOffset, TRUE);
696 /***********************************************************************
698 * NOTEPAD_MenuCommand
700 * All handling of main menu events
703 int NOTEPAD_MenuCommand (WPARAM wParam)
706 case NP_FILE_NEW: DIALOG_FileNew(); break;
707 case NP_FILE_OPEN: DIALOG_FileOpen(); break;
708 case NP_FILE_SAVE: DIALOG_FileSave(); break;
709 case NP_FILE_SAVEAS: DIALOG_FileSaveAs(); break;
710 case NP_FILE_PRINT: DIALOG_FilePrint(); break;
711 case NP_FILE_PAGESETUP: DIALOG_FilePageSetup(); break;
712 case NP_FILE_PRINTSETUP: DIALOG_FilePrinterSetup();break;
713 case NP_FILE_EXIT: DIALOG_FileExit(); break;
715 case NP_EDIT_UNDO: DIALOG_EditUndo(); break;
716 case NP_EDIT_CUT: DIALOG_EditCut(); break;
717 case NP_EDIT_COPY: DIALOG_EditCopy(); break;
718 case NP_EDIT_PASTE: DIALOG_EditPaste(); break;
719 case NP_EDIT_DELETE: DIALOG_EditDelete(); break;
720 case NP_EDIT_SELECTALL: DIALOG_EditSelectAll(); break;
721 case NP_EDIT_TIMEDATE: DIALOG_EditTimeDate();break;
722 case NP_EDIT_WRAP: DIALOG_EditWrap(); break;
724 case NP_SEARCH_SEARCH: DIALOG_Search(); break;
725 case NP_SEARCH_NEXT: DIALOG_SearchNext(); break;
727 case NP_HELP_CONTENTS: DIALOG_HelpContents(); break;
728 case NP_HELP_SEARCH: DIALOG_HelpSearch(); break;
729 case NP_HELP_ON_HELP: DIALOG_HelpHelp(); break;
730 case NP_HELP_LICENSE: DIALOG_HelpLicense(); break;
731 case NP_HELP_NO_WARRANTY: DIALOG_HelpNoWarranty(); break;
732 case NP_HELP_ABOUT_WINE: DIALOG_HelpAboutWine(); break;
734 /* Handle languages */
736 LANGUAGE_DefaultHandle(wParam);
743 /***********************************************************************
748 LRESULT WINAPI NOTEPAD_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
752 HANDLE hDrop; /* drag & drop */
753 CHAR szFileName[MAX_STRING_LEN];
756 lstrcpy(szFileName, "");
761 GetClientRect(hWnd, &rectClient);
766 CreateCaret(Globals.hMainWnd, 0, 1, tm.tmHeight);
767 SetCaretPos(dwCaretXpos, dwCaretYpos);
768 ShowCaret(Globals.hMainWnd);
776 GetClientRect(hWnd, &rectClient);
777 hContext = BeginPaint(hWnd, &ps);
778 RenderWindow(hContext);
783 DoEdit(hWnd, wParam, lParam);
787 GetClientRect(hWnd, &rectClient);
789 hContext = GetDC(hWnd);
790 DoInput(hContext,wParam,lParam);
791 ReleaseDC(hWnd,hContext);
796 /* figure out where the mouse was clicked */
797 ButtonDownToCaretPos(hWnd, wParam, lParam);
801 DoScroll(hWnd, wParam, lParam);
802 InvalidateRect(hWnd, NULL, FALSE); /* force a redraw */
806 /* FIXME: this is a bit messy */
807 NOTEPAD_MenuCommand(wParam);
808 InvalidateRect(hWnd, NULL, FALSE); /* force a redraw */
809 hContext = GetDC(hWnd);
810 CalcCaretPos(hContext,dwXpos,dwYpos);
811 ReleaseDC(hWnd,hContext);
814 case WM_DESTROYCLIPBOARD:
815 MessageBox(Globals.hMainWnd, "Empty clipboard", "Debug", MB_ICONEXCLAMATION);
829 GetClientRect(Globals.hMainWnd, &Windowsize);
833 /* User has dropped a file into main window */
834 hDrop = (HANDLE) wParam;
835 DragQueryFile(hDrop, 0, (CHAR *) &szFileName, sizeof(szFileName));
837 DoOpenFile(szFileName);
841 return DefWindowProc (hWnd, msg, wParam, lParam);
846 int AlertFileDoesNotExist(LPSTR szFileName) {
849 CHAR szMessage[MAX_STRING_LEN];
850 CHAR szRessource[MAX_STRING_LEN];
852 LoadString(Globals.hInstance, IDS_DOESNOTEXIST, szRessource,
853 sizeof(szRessource));
854 wsprintf(szMessage, szRessource, szFileName);
856 LoadString(Globals.hInstance, IDS_ERROR, szRessource, sizeof(szRessource));
858 nResult = MessageBox(Globals.hMainWnd, szMessage, szRessource,
859 MB_ICONEXCLAMATION | MB_YESNO);
864 void HandleCommandLine(LPSTR cmdline)
867 while (*cmdline && (*cmdline == ' ' || *cmdline == '-'))
872 if (*cmdline++ == ' ') continue;
875 if (option) cmdline++;
876 while (*cmdline && *cmdline == ' ') cmdline++;
881 case 'P': printf("Print file: ");
882 /* Not yet able to print a file */
889 /* file name is passed in the command line */
894 if (FileExists(cmdline))
901 /* try to find file with ".txt" extention */
902 if (!strcmp(".txt", cmdline + strlen(cmdline) - strlen(".txt")))
909 strncpy(buf, cmdline, MAX_PATH - strlen(".txt") - 1);
912 file_exists = FileExists(buf);
918 DoOpenFile(file_name);
919 InvalidateRect(Globals.hMainWnd, NULL, FALSE);
923 switch (AlertFileDoesNotExist(file_name)) {
925 DoOpenFile(file_name);
936 /***********************************************************************
941 int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
945 char className[] = "NPClass"; /* To make sure className >= 0x10000 */
946 char winName[] = "Notepad";
953 Globals.lpszIniFile = "notepad.ini";
954 Globals.lpszIcoFile = "notepad.ico";
956 Globals.hInstance = hInstance;
959 Globals.hMainIcon = ExtractIcon(Globals.hInstance,
960 Globals.lpszIcoFile, 0);
962 if (!Globals.hMainIcon) {
963 Globals.hMainIcon = LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
966 lstrcpy(Globals.szFindText, "");
967 lstrcpy(Globals.szFileName, "");
968 lstrcpy(Globals.szMarginTop, "25 mm");
969 lstrcpy(Globals.szMarginBottom, "25 mm");
970 lstrcpy(Globals.szMarginLeft, "20 mm");
971 lstrcpy(Globals.szMarginRight, "20 mm");
972 lstrcpy(Globals.szHeader, "&n");
973 lstrcpy(Globals.szFooter, "Page &s");
974 lstrcpy(Globals.Buffer, "Hello World");
977 class.style = CS_HREDRAW | CS_VREDRAW;
978 class.lpfnWndProc = NOTEPAD_WndProc;
979 class.cbClsExtra = 0;
980 class.cbWndExtra = 0;
981 class.hInstance = Globals.hInstance;
982 class.hIcon = LoadIcon (0, IDI_APPLICATION);
983 class.hCursor = LoadCursor (0, IDC_ARROW);
984 class.hbrBackground = GetStockObject (WHITE_BRUSH);
985 class.lpszMenuName = 0;
986 class.lpszClassName = className;
989 if (!RegisterClass (&class)) return FALSE;
994 Globals.hMainWnd = CreateWindow (className, winName,
995 WS_OVERLAPPEDWINDOW + WS_HSCROLL + WS_VSCROLL,
996 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0,
997 LoadMenu(Globals.hInstance, STRING_MENU_Xx),
998 Globals.hInstance, 0);
1000 Globals.hFindReplaceDlg = 0;
1002 LANGUAGE_SelectByNumber(0);
1004 SetMenu(Globals.hMainWnd, Globals.hMainMenu);
1006 ShowWindow (Globals.hMainWnd, show);
1007 UpdateWindow (Globals.hMainWnd);
1009 /* Set up dialogs */
1011 /* Identify Messages originating from FindReplace */
1013 Globals.nCommdlgFindReplaceMsg = RegisterWindowMessage("commdlg_FindReplace");
1014 if (Globals.nCommdlgFindReplaceMsg==0) {
1015 MessageBox(Globals.hMainWnd, "Could not register commdlg_FindReplace window message",
1016 "Error", MB_ICONEXCLAMATION);
1019 HandleCommandLine(cmdline);
1021 /* Set up Drag&Drop */
1023 DragAcceptFiles(Globals.hMainWnd, TRUE);
1025 /* now enter mesage loop */
1027 while (GetMessage (&msg, 0, 0, 0)) {
1028 if (IsDialogMessage(Globals.hFindReplaceDlg, &msg)!=0) {
1029 /* Message belongs to FindReplace dialog */
1030 /* We just let IsDialogMessage handle it */
1034 /* Message belongs to the Notepad Main Window */
1035 TranslateMessage (&msg);
1036 DispatchMessage (&msg);