|
|
You can't avoid that...
Though the other cheap way, is to post messages to your own window. You can pass the strings by converting them to atom's (see GlobalAddAtom). If you don't have a window, then go back to plan A as mentioned above.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
Santa Cruz Networks
|
|
|
|
|
Read the docs for PostThreadMessage().
It will explain how to create a message queue for your thread A (dead easy).
Threads B, C can then call PostThreadMessage(thread_A, MY_STR_MSG, char*, length).
Thread A (even though it doesn't have a window) can use the normal window GetMessage() loop to pull the strings from the message queue.
Probably want to alloc memory for strings in threads B,C and delete in thread A.
...cmk
|
|
|
|
|
Can I set a ProgressBar's postion in a static CALLBACK function? For instance:
......
//{{AFX_DATA(CFormatNT)
enum { IDD = IDD_DIALOG_FORMAT };
CProgressCtrl m_progress;
//}}AFX_DATA
.....
static BOOL CALLBACK FormatDiskCallback( ...);
.......
BOOL CALLBACK CFormatNT::FormatDiskCallback(..)
{
......
m_progress.SetPos(10);
......
}
When I compile it, there is an error as below:
error C2228: left of '.SetPos' must have class/struct/union type
What is the problem? How to solve it?
Thank you in advance!
|
|
|
|
|
A static method can't access non-static member variables. You'll need to pass a pointer to either this or just the CProgressCtrl to the callback function.
--Mike--
"So where does that leave us? Well, it leaves us right back where we started, only more confused than before." -- Matt Gullett
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
|
|
|
|
|
In the head file----------------
//{{AFX_DATA(CFormatNT)
enum { IDD = IDD_DIALOG_FORMAT };
CProgressCtrl m_progress;
//}}AFX_DATA
.....
-------------------------------------
static BOOL CALLBACK FormatDiskCallback( ...,CProgressCtrl progressBar);
static void PrintOut(...PFMIFSCALLBACK FormatExCallback,CProgressCtrl m_progress);
.......
In the implementation file-----------------------------------------
typedef BOOL (CALLBACK *PFMIFSCALLBACK)( ...,CProgressCtrl progressBar );
-------------------------
BOOL CALLBACK CFormatNT::FormatDiskCallback(...,CProgressCtrl progressBar)
{
......
m_progress.SetPos(10);
......
}
void CFormatNT::PrintOut(..., PFMIFSCALLBACK FormatExCallback,CProgressCtrl m_progress)
{
....
FormatExCallback(...,m_progress);
}
...
PrintOut(...,m_progress);
...
Compile it, and the result is:
error C2664: 'PrintOut' : cannot convert parameter 3 from 'class CProgressCtrl' to 'class CProgressCtrl'
What is the problem? And how to solve it?
|
|
|
|
|
Now I have completed the function by using another new thread.
Not handling the CProgressCtl varible in the static function.
|
|
|
|
|
how to play *.ani file in MFC?
I dont want to use the function "LoadCursorFromFile"
I want to use it as a resource.
How do i do!
|
|
|
|
|
Robert,
I am very interested in your code to change the static text and background colors. I have entered in the code to do that from your code, but the colors do not change. Could I send you the code and have you take a look and see what is wrong?
Thanks very much,
George
|
|
|
|
|
hi..
I create a subclassed MFC ActiveX control .. Subclassed from the Listbox control .. a have a method that should add an item :
the code causes an assertion .. can anyone help ?
void CSubCtrl::AddItem(BSTR FAR* strItem) <br />
{<br />
<br />
CString st(*strItem);<br />
CListBox lb;<br />
lb.Attach(COleControl::m_hWnd);<br />
lb.AddString(st);<br />
lb.Detach();<br />
<br />
}
|
|
|
|
|
When talking about assertion, it's needed to know what is its condition from the file it exists in.
However, I guess that the possible assertion that could occur in your code is the IsWindow() assertion (ASSERT(::IsWindow(hWnd)) which indicate the the HWND passed to the Attach() function is invalid.
When you get an assertion in debug mode, click retry to see the assertion condition.
|
|
|
|
|
Hi..
the asseion occures in Attach method .. when i step in the code i find that ASSERT(FromHandlePermanent(hWndNew) == NULL); causes an assetion..
any suggestion please ?
|
|
|
|
|
Hello!
I am an electronics hobyist, I am interested in writing programs for interfacing with my homebrew electronics projects. Is there a generic serial port driver for Win32 environment using open source for download?
|
|
|
|
|
|
Hello,
I am looking for a directive like #error, but one that doesn't stop the compiler. So something like #message...
Does such a directive exist?
-Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
|
|
|
|
|
Try #pragma message("My Message")
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Ah, thanks
-Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
|
|
|
|
|
You're welcome
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
I want to design an MFC program that processes part numbers, I'm not sure which is the best way to go. Could someone please give me some advice on creating this type of program. I've had two people recommend a database, but I'd like to hear a few more opinions.
Thanks much
|
|
|
|
|
You can download mySQL at http://www.mysql.com
It's free for private use.
|
|
|
|
|
Hello. I am doing a about cd-rom test program. I want to read CD-ROM data test. But I don't know read CD-ROM data. Can you help me? Thanks.
welcome to meet you!
|
|
|
|
|
|
You can open the CD as a volume. This way you reads the volume in raw mode (sector by sector).
The trick is to open the volume like this (assuming your CD-Rom i drive G:, (char) m_CurDrive == 'G')
#include "winioctl.h"
...
char NtDriveName[10];
sprintf(NtDriveName, "\\\\.\\%c:", m_CurDrive);
hDrive = CreateFile(
NtDriveName,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL
);
Then you lock the drive and read geometry for it (in order to get the sector size):
DWORD ReturnedByteCount;
DeviceIoControl(hDrive, FSCTL_LOCK_VOLUME,
NULL, 0, NULL, 0, &ReturnedByteCount,
NULL);
// Get the geometry:
DISK_GEOMETRY Geometry;
DeviceIoControl(hDrive, IOCTL_DISK_GET_DRIVE_GEOMETRY,
NULL, 0, &Geometry, sizeof(Geometry),
&ReturnedByteCount, NULL);
// Now you got the sector size (in Geometry.BytesPerSector).
// At this point, you can unlock the volume if you wish. It's the IOCTL_DISK_GET_DRIVE_GEOMETRY call who needs the drive to be locked.
IoBuffer = malloc (Geometry.BytesPerSector);
....
// Read sector by sector, starts with sector 0
// Positionera
if(SetFilePointer(hDrive, (long)
(Geometry.BytesPerSector * (int) "your wanted start-sector"),
NULL, FILE_BEGIN) == 0xFFFFFFFF) {
// Couldn't seek to it.
return FALSE;
}
// Read
b = ReadFile(hDrive,IoBuffer, Geometry.BytesPerSector, &BytesRead, NULL);
if (b && BytesRead){
// OK, read
.....
}
.....
// unlock the volume
DeviceIoControl(hDisk, FSCTL_UNLOCK_VOLUME,
NULL, 0, NULL, 0, &ReturnedByteCount,
NULL);
// close the volume
CloseHandle(hDrive);
free IoBuffer;
Note, this code isn't compiled! But it's assembled from working code (a routine that reads UNIX tar-media (diskettes and CD) in NT 4).
Good luck.
Kakan.
|
|
|
|
|
I would like to create an active X control using VC++ 6.0 in which, apart from my application specific properties and methods , I also want to have a MsComm Control (for serial port communications) as a member variable in the user activeX property page class which gets generated by the apllication wizard. The following are the steps I had taken to do so.
1. Used MFC ActiveX control Wizard to create a ActiveX application.
2. Added the MsComm active X control in the resource tool box. (The phone icon was visible in the toolbox)
3. Added the MsComm Control in the Property page dialog box (which was created automatically by the wizard).
4. Assigned a member variable, say, m_Comm to the control.
5. Added a method to the control class (automatically generated by the wizard) called OpenPort, in which I called the m_Comm.SetSettings("9600,N,8,1") function.
6. Compiled and created a ActiveX control.
So far so good ..... No Hassles.
7. Created a Dialog based MFC application in which I used this ActiveX control. Provided a button in the dialog to trigger the OpenPort Function of the active X.
Now the hassles start......
8. The program crashes.
9. I debugged the code of the activeX project and found that the address m_Comm variable was NULL instead of a meaningfull value.
Where did I go Wrong?
|
|
|
|
|
I do this for an array of COM ports (element 0 shown):
Comport[0] = &m_comm0;
// Set up the COM ports
Comport[0]->SetCommPort( (short)i + 2); // start at COM2
Comport[0]->SetInBufferSize(2040); // both buffers to just under 2K
Comport[0]->SetOutBufferSize(2040);
Comport[0]->SetRThreshold(1); // call OnComm event after 1 char reced.
Comport[0]->SetSettings(cstr1);
if (! Comport[0]->GetPortOpen()) // if the port is closed, open it
Comport[i]->SetPortOpen(TRUE);
Also, the ON_COMM event handler is set up to be called by 1 character recieved. Note that var is declared as a VARIANT and that the condition of checking for a non zero length is because once in several million events this is called with no received character. There may be more than one character received in the string.
if(Comport[Port]->GetCommEvent() == 2)
{
VARIANT var;
// character(s) received ?
var.vt = VT_BSTR; // yes, we get a BSTR back
var = Comport[Port]->GetInput();
cstr1 = var.bstrVal; // convert to a CString for convenience
if(cstr1.GetLength() > 0) // if anything to add
{
// do it here
}
}
Elaine
The tigress is here
|
|
|
|
|