Ребята у меня к вам такой вопрос
Код | // 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
LRESULT CALLBACK ListProc(HWND, UINT, WPARAM, LPARAM);
WNDPROC fnOldList;
// 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);
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) { PAINTSTRUCT ps; HDC hdc; TEXTMETRIC tm; static RECT rect ; static HWND hWndList, hWndText, hWndEdit; TCHAR szBuffer[MAXPATH + 1]; static BOOL bValidFile ; static TCHAR sReadBuffer[MAXREAD], szFile[MAXPATH] ; static OFSTRUCT ofs ; int i, iHandle; static int cyChar, cxChar; DWORD dw; 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);
dw = GetLastError();
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)22, hInst, NULL);
fnOldList =(WNDPROC) SetWindowLong(hWndList, GWL_WNDPROC, (LPARAM) ListProc);
if(LB_ERR == SendMessage (hWndList, LB_DIR, 0x37, (LPARAM) "*.*")) Beep(1500, 50);
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); break;
case WM_SIZE: MoveWindow (hWndEdit, rect.left, rect.top, LOWORD (lParam)- rect.left, HIWORD(lParam)- rect.top, TRUE); break; case WM_SETFOCUS: SetFocus (hWndList); break;
case WM_COMMAND: if(LOWORD(wParam)==1 && HIWORD(wParam)==LBN_DBLCLK) { if (LB_ERR==(i= SendMessage(hWndList,LB_GETCURSEL, 0, 0L))) break; SendMessage (hWndText, LB_GETTEXT, i, (LPARAM) szBuffer) ;
if (NULL!=OpenFile((LPCSTR)szBuffer, &ofs, OF_EXIST | OF_READ)) { bValidFile = TRUE; _tcscpy (szFile, szBuffer) ; _tgetcwd (szBuffer, MAXPATH); if(szBuffer[_tcslen(szBuffer)-1]!='\\') _tcscat(szBuffer,TEXT("\\")); SetWindowText (hWndText, (LPCWSTR)_tcscat (szBuffer, szFile)) ; } else { bValidFile = FALSE; szBuffer [_tcslen (szBuffer) - 1] = '\0' ; _tchdir(szBuffer + 1); _tgetcwd (szBuffer, MAXPATH) ; SetWindowText(hWndText, (LPCWSTR)szBuffer) ; SendMessage (hWndList, LB_RESETCONTENT, 0, 0L) ; SendMessage (hWndList, LB_DIR, 0x37, (LONG) "*.*") ; } InvalidateRect (hWnd, NULL, TRUE) ; }
break;
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 && -1 != (iHandle = OpenFile ((LPCSTR)szFile, &ofs, OF_REOPEN | OF_READ))) { i = _lread (iHandle, sReadBuffer, MAXREAD) ; _lclose (iHandle) ; DrawText (hdc, sReadBuffer, i, &rect, DT_WORDBREAK | DT_EXPANDTABS | DT_NOCLIP | DT_NOPREFIX) ; } else bValidFile = FALSE ; EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }
LRESULT CALLBACK ListProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { if(iMsg == WM_KEYDOWN && wParam == VK_RETURN) SendMessage(GetParent(hwnd), WM_COMMAND, 1, MAKELONG(hwnd, LBN_DBLCLK)); return CallWindowProc(fnOldList, hwnd, iMsg, wParam, lParam); }
|
при компиляции эррор-ов нету, но возникают следующие warning-ы
warning C4244: 'argument' : conversion from 'LPARAM' to 'LONG', possible loss of data warning C4312: 'type cast' : conversion from 'LONG' to 'WNDPROC' of greater size warning C4244: '=' : conversion from 'LRESULT' to 'int', possible loss of data warning C4996: 'wcscpy' was declared deprecated 1> c:\program files\microsoft visual studio 8\vc\include\string.h(250) : see declaration of 'wcscpy' 1> Message: 'This function or variable may be unsafe. Consider using wcscpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.' warning C4996: 'wcscat' was declared deprecated 1> c:\program files\microsoft visual studio 8\vc\include\string.h(243) : see declaration of 'wcscat' 1> Message: 'This function or variable may be unsafe. Consider using wcscat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.' warning C4996: 'wcscat' was declared deprecated 1> c:\program files\microsoft visual studio 8\vc\include\string.h(243) : see declaration of 'wcscat' 1> Message: 'This function or variable may be unsafe. Consider using wcscat_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.' warning C4311: 'type cast' : pointer truncation from 'const char *' to 'LONG'
Да и еще одно, программе не удается создать листбокс говорит , что unused = CXX0030: Error: expression cannot be evaluated (строка 167 )
|