
Новичок
Профиль
Группа: Участник
Сообщений: 43
Регистрация: 18.8.2006
Репутация: нет Всего: нет
|
Ребят тут возникла вот такая проблемка ... | Код | // XML.cpp : Defines the entry point for the application. //
#include "stdafx.h" #include "XML.h" #include <string.h> #include <direct.h> #define MAX_LOADSTRING 100 #define MAXPATH 256 #define MAXREAD 8129
// Global Variables: HINSTANCE hInst; // current instance TCHAR szTitle[MAX_LOADSTRING]; // The title bar text TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
// Forward declarations of functions included in this code module: ATOM MyRegisterClass(HINSTANCE hInstance); BOOL InitInstance(HINSTANCE, int); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { // TODO: Place code here. MSG msg; HACCEL hAccelTable;
// Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_XML, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance);
// Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; }
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_XML);
// Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } }
return (int) msg.wParam; }
// // FUNCTION: MyRegisterClass() // // PURPOSE: Registers the window class. // // COMMENTS: // // This function and its usage are only necessary if you want this code // to be compatible with Win32 systems prior to the 'RegisterClassEx' // function that was added to Windows 95. It is important to call this function // so that the application will get 'well formed' small icons associated // with it. // ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_XML); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1) ; wcex.lpszMenuName = (LPCTSTR)IDC_XML; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
return RegisterClassEx(&wcex); }
// // FUNCTION: InitInstance(HANDLE, int) // // PURPOSE: Saves instance handle and creates main window // // COMMENTS: // // In this function, we save the instance handle in a global variable and // create and display the main program window. // BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd) { return FALSE; }
ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd);
return TRUE; }
// // FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // // PURPOSE: Processes messages for the main window. // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; TEXTMETRIC tm; static RECT rect ; static HWND hWndList, hWndText, hWndEdit, hWndButtonEdit; char szBuffer[MAXPATH + 1]; static BOOL bValidFile ; static char sReadBuffer[MAXREAD], szFile[MAXPATH] ; static OFSTRUCT ofs ; int i ; static int cyChar, cxChar; HANDLE /*int*/ iHandle;
OVERLAPPED gOverlapped;
// Set up overlapped structure fields. gOverlapped.Offset = 0; gOverlapped.OffsetHigh = 0;
switch (message) { case WM_CREATE:
hdc = GetDC(hWnd); SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT)); GetTextMetrics(hdc, &tm); ReleaseDC (hWnd, hdc); rect.left = 20* tm.tmAveCharWidth; rect.top = 3*tm.tmHeight;
cxChar = tm.tmAveCharWidth; cyChar = tm.tmHeight + tm.tmExternalLeading; hWndList = CreateWindow (_TEXT("listbox"),NULL, WS_CHILDWINDOW | WS_VISIBLE | LBS_STANDARD, tm.tmAveCharWidth, 3*tm.tmHeight, 13*tm.tmAveCharWidth + GetSystemMetrics(SM_CXVSCROLL), 10*tm.tmHeight, hWnd, (HMENU)1, hInst, NULL);
hWndText = CreateWindow(_TEXT("static"), NULL, WS_CHILDWINDOW | WS_VISIBLE | SS_LEFT | WS_HSCROLL | WS_VSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL, tm.tmAveCharWidth, tm.tmHeight, tm.tmAveCharWidth*MAXPATH, tm.tmHeight, hWnd, (HMENU)2, hInst, NULL);
SendMessage (hWndList, LB_DIR, 0x37, (LPARAM) "*.*") ;
hWndEdit = CreateWindow(_TEXT("edit"), NULL, WS_CHILDWINDOW | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | WS_BORDER | ES_LEFT | ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_READONLY, 0, 0, 0, 0, hWnd, (HMENU)3, hInst, NULL);
hWndButtonEdit = CreateWindow("button", "Edit", WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, tm.tmAveCharWidth, 23*tm.tmAveCharWidth + GetSystemMetrics(SM_CXVSCROLL), 7 * cxChar, 7 * cyChar / 4, hWnd, (HMENU) 5, hInst, NULL);
return 0 ; case WM_SIZE:
MoveWindow (hWndEdit, rect.left, rect.top, LOWORD (lParam)- rect.left, HIWORD(lParam)- rect.top, TRUE); return 0; case WM_SETFOCUS: SetFocus (hWndList); return 0;
case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); if(LOWORD(wParam)==1 && HIWORD(wParam)==LBN_DBLCLK) { if (LB_ERR==(i= SendMessage(hWndList,LB_GETCURSEL, 0, 0L))) break; SendMessage (hWndList, LB_GETTEXT, i, (LPARAM) szBuffer) ;
if (NULL!=CreateFile(szBuffer, FILE_ALL_ACCESS, GENERIC_READ |GENERIC_WRITE | FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_FLAG_OVERLAPPED , NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) { bValidFile = TRUE; strcpy (szFile, szBuffer) ; getcwd (szBuffer, MAXPATH); if(szBuffer[strlen(szBuffer)-1]!='\\') strcat(szBuffer,"\\"); SetWindowText (hWndText, strcat (szBuffer, szFile)) ; } else { bValidFile = FALSE; szBuffer [strlen (szBuffer) - 1] = '\0' ; chdir(szBuffer + 1); getcwd (szBuffer, MAXPATH) ; SetWindowText (hWndText, szBuffer) ; SendMessage (hWndList, LB_RESETCONTENT, 0, 0L) ; SendMessage (hWndList, LB_DIR, 0x37, (LONG) "*.*") ; } InvalidateRect (hWnd, NULL, TRUE) ; }
return 0;
case WM_PAINT: hdc = BeginPaint(hWnd, &ps); SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT)) ; SetTextColor (hdc, GetSysColor (COLOR_BTNTEXT)) ; SetBkColor (hdc, GetSysColor (COLOR_BTNFACE)) ;
if (bValidFile && NULL!=(iHandle= //OpenFile(szFile, &ofs, OF_REOPEN | OF_READ) CreateFile(szFile, FILE_ALL_ACCESS, GENERIC_READ |GENERIC_WRITE | FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_FLAG_OVERLAPPED , NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL) ))
{ //i=_lread (iHandle,sReadBuffer, MAXREAD); ReadFile(iHandle, &sReadBuffer, MAXREAD, NULL, &gOverlapped);
//_lclose (iHandle); SetWindowText (hWndEdit,sReadBuffer); } else bValidFile = FALSE ;
EndPaint (hWnd, &ps) ; // TODO: Add any drawing code here... EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
// Message handler for about box. LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: return TRUE;
case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, LOWORD(wParam)); return TRUE; } break; } return FALSE; }
|
Функция ReadFile должна копировать содерживое файла в sReadBuffer (строка 299) | Код | ReadFile(iHandle, &sReadBuffer, MAXREAD, NULL,&gOverlapped);
|
а потом отобразить содержимое в окне | Код | SetWindowText (hWndEdit,sReadBuffer);
|
... но почему то это не происходиот ... помогите пожалуйста Это сообщение отредактировал(а) Logit - 21.8.2006, 09:04
|