| View previous topic :: View next topic |
| Author |
Message |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
Posted: Mon Jun 09, 2008 3:30 pm Post subject: C++ System.IO Namespace |
|
|
How do I add the name space
Whatever I try, it gives me errors like "undeclared identifier" and such
Thanks
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Mon Jun 09, 2008 3:41 pm Post subject: |
|
|
Your using .NET right?
if so put
using namespace System.IO;
before everything below your includes
_________________
|
|
| Back to top |
|
 |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
Posted: Mon Jun 09, 2008 3:49 pm Post subject: |
|
|
| lurc wrote: | Your using .NET right?
if so put
using namespace System.IO;
before everything below your includes |
Ummm im using win32 app....will it not work for that?
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Mon Jun 09, 2008 3:54 pm Post subject: |
|
|
Nope, Win32 Applications use API's not .NET Librarys
What functions were you planning to use from the System.IO?
_________________
|
|
| Back to top |
|
 |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
Posted: Mon Jun 09, 2008 3:56 pm Post subject: |
|
|
| I want to open a .txt file, and load the entire content, inducing if there is a "enter" characters into a "EDIT" textbox.
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Mon Jun 09, 2008 4:04 pm Post subject: |
|
|
For Getting the directory to a text file using an OpenFileDialog:
OPENFILENAME struct - http://msdn.microsoft.com/en-us/library/ms646839.aspx
GetOpenFileName function - http://msdn.microsoft.com/en-us/library/ms646927.aspx
For opening a file handle:
_tfopen_s - http://msdn.microsoft.com/en-us/library/z5hh6ee9.aspx
For reading a file from an open handle (while (_fgetts(...)) loop to get full file):
_fgetts - http://msdn.microsoft.com/en-us/library/c37dh6kf.aspx
Closing the file handle:
fclose - http://www.cplusplus.com/reference/clibrary/cstdio/fclose.html
I'll get a code snippet up soon... just sit tight.
Edit
Found one i made a while ago for something my friend wanted.
| Code: | // Remember to include these:
// #include <windows.h>
// #include <tchar.h>
// #include <stdio.h>
BOOL TxtDocToListBox( INT nDlgId, BOOL bClearBox )
{
FILE* fDoc;
TCHAR tszPath[MAX_PATH], // Where the path to the document gets stored
tszText[MAX_PATH]; // Buffer to hold our text that we are getting.
OPENFILENAME ofn; // OpenFileDialog struct
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hWnd;
ofn.lpstrFilter = _T("Text Documents (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"); // .txt filter
ofn.lpstrFile = tszPath; // where to store the path
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = _T("txt");
if ( GetOpenFileName( &ofn ) )
{
if ( bClearBox )
SendDlgItemMessage( hWnd, nDlgId, LB_RESETCONTENT, 0, 0 );
_tfopen_s( &fDoc, tszPath, _T("r")); // open to read (r = read)
if ( fDoc )
{
while ( _fgetts( tszText, _ARRAYSIZE(tszText), fDoc ) )
{
SendDlgItemMessage( hWnd, nDlgId, LB_ADDSTRING, 0, (LPARAM)tszText );
}
fclose( fDoc );
return TRUE;
}
}
return FALSE;
} |
_________________
Last edited by lurc on Mon Jun 09, 2008 4:20 pm; edited 1 time in total |
|
| Back to top |
|
 |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
Posted: Mon Jun 09, 2008 4:19 pm Post subject: |
|
|
| Thanks alot
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Mon Jun 09, 2008 4:21 pm Post subject: |
|
|
There we go, added a code snippet Unfortunatly it doesnt add it all to a edit box, it adds it to a ListBox (old project for my friend was using an listbox, but you should get the idea)
_________________
|
|
| Back to top |
|
 |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
Posted: Mon Jun 09, 2008 4:46 pm Post subject: |
|
|
Uhh u still there?
I have a small problem....
It compiles fine, but I needed to add
#include <Commdlg.h>
to make it compile properly... annyways my real question is, that nothing pops up...should the sniplet of code you provided works already?
Or so I need to do something else?
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Mon Jun 09, 2008 4:50 pm Post subject: |
|
|
Are you filtering WM_COMMAND so that when u press a button, it calls that function with the 1st parameter being the Dlg ID to the list box?
_________________
|
|
| Back to top |
|
 |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
Posted: Mon Jun 09, 2008 4:53 pm Post subject: |
|
|
ya...exacrly what you said...
I had to change the Id from
INT to HWND though
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Mon Jun 09, 2008 4:55 pm Post subject: |
|
|
wuhhh,
when your creating the object using CreateWindowEx the HMENU parameter is the id, give it an assigned ID and use that.
_________________
|
|
| Back to top |
|
 |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
Posted: Mon Jun 09, 2008 5:06 pm Post subject: |
|
|
| what do you mean by HMENU parameter ?
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Mon Jun 09, 2008 5:12 pm Post subject: |
|
|
Here's an exapmle.
| Code: |
//header files blablabla
#define IDC_BUTTON 100
//coding blablabla
case WM_CREATE:
HWND hButton = CreateWindowEx(WS_EX_CLIENTEDGE, "BUTTON", "test", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwnd, (HMENU)IDC_BUTTON, GetModuleHandle(NULL), NULL);
break;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDC_BUTTON:
TxtDocToListBox(nDlgId, bClearBox); //define function somewhere so you can call it
break;
}
break;
//finish coding
|
The HMENU parameter is for, when creating child windows (controls are windows), the identifier. The identifier is an integer. You need the identifier to filter out the WM_COMMAND message. As seen. The LOWORD of the wParam is the identifier of the control, where as the HIWORD is the notification message, and the lParam holds the handle of the control that sent the message.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
Posted: Mon Jun 09, 2008 8:46 pm Post subject: |
|
|
So what do I put exactly as nDlgId?
IDC_BUTTON or hButton?
Or something else?
|
|
| Back to top |
|
 |
|