|
make member variables of cstring for each edit box. then
when the button is clicked call
UpdateData(false);
m_strEdit1 = m_strEdit2;
UpdateData(ture);
You need to get a good book on windows control and how to use them.
This space is empty.
|
|
|
|
|
for some reason that just clears the contents of both boxes
|
|
|
|
|
i found the problem, i think you go the UpdateData()'s mixed up
you have to do
UdateData(TRUE);
m_edit1 = m_edit2;
UpdateData(FALSE);
|
|
|
|
|
Yeah! I didnt exactly remember which one did what. Any ways good that you figured it out.
This space is empty.
|
|
|
|
|
As said before, what I am tying to do is get the letters of all the CD/DVD drives on the users computer using MFC. This is what I have so far:
DWORD Drives = GetLogicalDrives();
CString FormatString;
FormatString.Format("%i",Drives);
DriveControl.SetWindowText(FormatString);
FormatString returns 61... I have no idea why it is returning 61. I am assuming that I am doing it wrong? If anyone could show me how to do this right, that would be great.
-Dev578
|
|
|
|
|
GetLogicalDrives returns a bit mask. The individual bits represent the available drive letters.
GetLogicalDrives() returned 61 on your computer. A more useful way to look at this would be in binary. i.e. 111101 (or 00000000000000000000000000111101)
Starting with the least most significant bit (the right one), we see that you:
have an A drive
have no B drive
have a C drive
have a D drive
have a E drive
have a F drive
have no drives G - Z.
In your code, you can use a bitwise AND operation to parse out the individual drives' availability.
i.e:
DWORD drives = GetLogicalDrives();
if (drives & 0x01)
// have A
if (drives & 0x02)
// have B
if (drives & 0x04)
// have C
//...
|
|
|
|
|
You should also take a look at the documentation for GetLogicalDriveStrings() and GetDriveType().
|
|
|
|
|
Try this:
<br />
DWORD dwLogicalDrives = ::GetLogicalDrives();<br />
char szDriveRoot[] = "";<br />
if(dwLogicalDrives)<br />
{<br />
for(int iCnt = 0; iCnt < 32; ++iCnt)<br />
{<br />
memset(szDriveRoot, 0, sizeof(szDriveRoot));<br />
if(dwLogicalDrives & (1 << iCnt))<br />
{<br />
sprintf(szDriveRoot, "%c:\\", iCnt + 'A');<br />
UINT uiDriveType = ::GetDriveType(szDriveRoot);<br />
switch(uiDriveType)<br />
{ <br />
case DRIVE_UNKNOWN:<br />
TRACE1(_T("%s is unknown\n"), szDriveRoot);<br />
break;<br />
<br />
case DRIVE_NO_ROOT_DIR:<br />
TRACE1(_T("Partition %s is no root drive\n"), szDriveRoot);<br />
break;<br />
<br />
case DRIVE_REMOVABLE:<br />
TRACE1(_T("Partition %s is a removable device\n"), szDriveRoot);<br />
break;<br />
<br />
case DRIVE_FIXED:<br />
TRACE1(_T("Partition %s is a Harddisk\n"), szDriveRoot);<br />
break;<br />
<br />
case DRIVE_REMOTE:<br />
TRACE1(_T("Partition %s is a network drive\n"), szDriveRoot);<br />
break;<br />
<br />
case DRIVE_CDROM:<br />
TRACE1(_T("Partition %s is CD-ROM\n"), szDriveRoot);<br />
break;<br />
<br />
case DRIVE_RAMDISK:<br />
TRACE1(_T("Partition %s is no RAM-Disk\n"), szDriveRoot);<br />
break;<br />
}<br />
}<br />
}<br />
Pascal
|
|
|
|
|
could someone please post a working example of
a dialog based program
that has a button you click
and it runs a thread and updates an edit box based on the number of times the thread runs. Everytime i try i get error wincore.cpp assert. as you can see if my other messages posted. Someone told me to use GetSafeHWND but i get a conversion error whe i try saying it can't convert HWND from class myclass.
an example of this would be great.
thanks a million
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
I'm not an MFC guy at all, but I ran across this in the wincore.cpp distributed with VS.NET 2003 (line 891).
// Note: if either of the above asserts fire and you are
// writing a multithreaded application, it is likely that
// you have passed a C++ object from one thread to another
// and have used that object in a way that was not intended.
// (only simple inline wrapper functions should be used)
//
// In general, CWnd objects should be passed by HWND from
// one thread to another. The receiving thread can wrap
// the HWND with a CWnd object by using CWnd::FromHandle.
//
// It is dangerous to pass C++ objects from one thread to
// another, unless the objects are designed to be used in
// such a manner.
Looks like passing CWnd objects between threads is forbidden.
If you can post your code (or snippets), someone here might be able to tell you why it's failng.
|
|
|
|
|
please look at line 254, 267,268 on this cpp
http://rafb.net/paste/results/j1260079.html (cpp file)
also look at the header file 26 thru 29 on how i have struct threadstruct
http://rafb.net/paste/results/y3002186.html (header file)
thanks for the kind help,
tony aka win32newb
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
Ok, I'm trying to understand some of what's going on. (I'm not a fan of mfc because it's so convoluted.)
lines 267 and 268:
CCash3mfcDlg *pdlg;
*pdlg = (CCash3mfcDlg*)CWnd::FromHandle("handle");
You definitely can't do that. First off, FromHandle is expecting an HWND, not a char *. It shouldn't even compile. Second, you're dereferencing the pointer (pdlg) and assigning a different pointer to the object pdlg points to. It's difficult to explain what that code says, because it's not valid. But looking through the rest of the function, I can't see anywhere you are using pdlg, so just remove those two lines completely. They've got several problems, and they aren't necessary for any other code.
Here's your THREADSTRUCT definition:
typedef struct THREADSTRUCT
{
CCash3mfcDlg* _this;
}THREADSTRUCT;
(You could simplify that by dropping the "typedef" and replacing the trailing "THREADSTRUCT;" with just ";". Your definition is redundant. But I don't think you should have any trouble with it.)
However, int line 254, you're setting the _this variable to an HWND value:
_param->_this = GetSafeHwnd();
That's also not allowed. An HWND and an object pointer are completely separate, relatively unrelated entities.
I'd suggest that you simplify the whole thing. Recreate your project from scratch, and only add in the bare minimum of functionality, and find the first point at which it fails. Right now, you've got a pretty big chunk of code, and that makes it harder to step through and figure out the point (or points) where you've got problems.
I'd also suggest that you change StartThread and
Ongobutton as follows:
UINT CCash3mfcDlg::StartThread(LPVOID param)
{
HWND wnd = (HWND)param;
CCash3mfcDlg * dlg = (CCash3mfcDlg*)CWnd::FromHandle(wnd);
dlg->run();
return 1;
}
void CCash3mfcDlg::Ongobutton()
{
AfxBeginThread (StartThread,GetSafeHwnd());
UpdateData(TRUE); // I actually don't know what this does, but no matter.
}
I believe that should do what you want.
|
|
|
|
|
i figured it out really simple actually
UINT CCash3mfcDlg::StartThread(LPVOID param)
{
CCash3mfcDlg *tony =static_cast<ccash3mfcdlg *="">(param);
tony->run();
return 1;
}
void CCash3mfcDlg::Ongobutton()
{
UpdateData(TRUE);
AfxBeginThread (StartThread,static_cast<lpvoid>(this));
}
in the run()
CString Tempstring;
///////////////converts the int to a string for the editbox control
Tempstring.Format( "%d", m_win ); m_winupdate.SetWindowText( Tempstring );
Anotherstring.Format( "%d", counter );
m_played.SetWindowText(Anotherstring);
Loststring.Format("%d", money);
m_lostvalue.SetWindowText(Loststring);
HOPE THIS HELPS SOMEONE ELSE IN THE FUTURE
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
win32newb wrote:
updates an edit box based on the number of times the thread runs
I'm not exactly sure what you mean by that, but I looked at your code, and I assume you want to know how many times the thread goes through the loop. One problem I saw is that you need to stop thinking linearly with threads. You call your thread, and then the line UpdateData(TRUE); may or may not be executed before the thread...so you won't always get the same results. You should use some sort of control device, like a CSemaphore so that the Ongobutton() function waits until the thread is finished. Or another method is to have your thread update your edit box directly. I've never had assert problems with using threads...here is what I usually use if I plan on using variables from my class, otherwise I just pass NULL as my second parameter:
AfxBeginThread( StartThread, static_cast<lpvoid>(this) );
If you call your thread using this, you should have access to anything defined in the calling class, as well as your controls.
Good luck, and let me know if I was any help.
|
|
|
|
|
well i get a syntax error when i do what you stated.
i know in your example you use static_cast(this) _param is assigned this so i used it instead.
UINT CCash3mfcDlg::StartThread(LPVOID param)
{
THREADSTRUCT *ts = new THREADSTRUCT;
CCash3mfcDlg *pdlg;
pdlg = (CCash3mfcDlg*)CWnd::FromHandle(ts->_this);
pdlg->run();
//here is the time-consuming process which interacts with your dialog
return 1;
}
void CCash3mfcDlg::Ongobutton()
{
THREADSTRUCT *_param = new THREADSTRUCT;
_param->_this = GetSafeHwnd();
AfxBeginThread (StartThread,static_cast(_param)); // gives me error c2059: syntax error: '('
UpdateData(TRUE);
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
Are you declaring your StartThread function as static in your class?
|
|
|
|
|
yes it is static. do you have like yahoo or something so it can be more realtime instead of playing message tag
in any event thanks for the help first of all
the portion of my header CCash3mfcDlg.h
static UINT StartThread (LPVOID param);
typedef struct THREADSTRUCT
{
HWND _this;
} THREADSTRUCT;
then here is how i have it implemented so far and not working
UINT CCash3mfcDlg::StartThread(LPVOID param)
{
THREADSTRUCT *ts = new THREADSTRUCT;
CCash3mfcDlg *pdlg;
pdlg = (CCash3mfcDlg*)CWnd::FromHandle(ts->_this);
pdlg->run();
//here is the time-consuming process which interacts with your dialog
return 1;
}
void CCash3mfcDlg::Ongobutton()
{
THREADSTRUCT *_param = new THREADSTRUCT;
_param->_this = GetSafeHwnd();
UpdateData(TRUE);
AfxBeginThread (StartThread,static(_param)); // gives me error c2059: syntax error: '('
}
int CCash3mfcDlg::run()
{
..........
}
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
I don't have Yahoo, but I do use AIM. My screen name is DougW48 (go figure) if you need to ask any questions. I have found the cause of that error C2059, and I was able to compile your project without a problem. You need to stop passing _param as static:
AfxBeginThread( StartThread, _param );
Let me know if this fixes it for you, and if you're still having problems with those edit boxes! Good luck.
|
|
|
|
|
hello,
im quite new to all this.
i would like to make a toolbar/dialogbar in my program that will have hot buttons just like internet explorer has ("back", "next", "stop", "reload", "home".... etc.)
the hot button doesnt even have to be a different bitmap on it only that the button would "jump out" when the mouse is over it, and pressed..
(and of course the button background should be different)
can anyone help me or direct me to a tutorial about this?
thanks,
asher
http://www.backup2000.com
|
|
|
|
|
I'm very familiar with C/C++ Console Applications and Visual Basic programming. I'm having a tought time with Visual C++ Edit Boxes. I can't figure out how to format an editbox for hexadecimal data, input data and output data. I downloaded a few tutorials and demos on edit boxes, which were a great start for edit boxes in general, but none specifically address this topic.
Here is what I'm trying to do....
Supposing that you have a form with 3 edit boxes and a button. The user will input a 1 byte hexadecimal number into edit box1 and edit box2. When the user clicks the button, the hexadecimal values in edit box1 will be subtracted from the value in edit box2. The answer will be displayed in hexadecimal format in edit box3. One other thig is that I want to filter the input data "on the fly", only allowing the user to type the numbers and characters 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F into edit box1 and edit box2. Any other letters will be rejected and not accpted.
If anyone has some simple code examples that can help me I'd greatly appreciate it. Thanks..
Freddie.
|
|
|
|
|
I created a project with VS.2002 and do a lot of coding, now I want to change the exe file that compiler buid, where should I change the setting to create new exe file? I don't wanna create new project with new name. Any solution for it?
Mazy
"A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope
|
|
|
|
|
Mazdak wrote:
don't wanna create new project with new name
no please
I havent used VS.NET but i guess there must be a link tab somewhere in the project settings where you have to provide the outfile name. there you can change the name of the exefile name.
This space is empty.
|
|
|
|
|
Thanks, yes , it was somewhere in properties for project.
Mazy
"A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope
|
|
|
|
|
Project Properties|Linker|General|Output File
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Thanks.
Mazy
"A bank is a place that will lend you money if you can prove that you don't need it." - Bob Hope
|
|
|
|