|
Try changing CFrameWnd to CMiniFrameWnd. That might or might not be what you want.
|
|
|
|
|
Hi,
I used the following code to show the CFileDialog, but when I exit my application, there was a message in the output window: "The thread 0xFFFAB69D has exited with code -1 (0xFFFFFFFF)."
Is there something wrong?
CFileDialog dlg(TRUE, NULL,"*.bmp;*.jpg;*.gif\0", OFN_FILEMUSTEXIST, "Picture Files (*.bmp;*.jpg;*.gif)|*.bmp; *.jpg; *.gif|All Files(*.*)|*.*||", this);
if(dlg.DoModal() == IDOK)
{
m_strFileName = dlg.m_ofn.lpstrFile;
}
And strange enough: If I change the above "*.bmp" to others text file extension, such as "*.txt", or "*.cpp", no the warning message. I was greatly confused. I am looking forward your kind help.
Thanks;
Feng
|
|
|
|
|
That's not an error message. A thread used by the common dialog just finished running and exited. No worries.
|
|
|
|
|
Why all my control IDs for my FormView don't show up on the ClassWizard uder the Mermber Variables tab?
Is there anything that I can do manually. Any other shortcuts?
Thank you.
|
|
|
|
|
I've seen this with certain controls. Not sure why it happens. What I've done, is manually add them for DDX or subclass the controls using a class derived from their base class...ie CMyListBox from CListBox.
If you want to add them manually, check out the code in the CDialog::DoDataExchange(CDataExchange* pDX) function. That will give you an idea of how to format the new control.
Good luck,
Frank
|
|
|
|
|
If I recall correctly, this was a bug with certain foreign language versions of the IDE (something to do with how your locales are setup). I think this was fixed in one of the service packs though.
|
|
|
|
|
Hi,
I have a MFC application that uses Microsoft Access tables.
The result of my program writes data into a Access database so at the end, I have a Table with the results.
I would like to know: How can I allow the user to save that RESULT TABLE where they SPECIFY the name of the table and the location of where to save it?
If anyone has any ideas, Please let me know.
Thanks in Advance
Steve
|
|
|
|
|
Hi Everyone,
How do I display the data in a Microsoft Access Table with an MFC application?
Can I call up a table from Access for display directly?
If anyone knows, Please let me know.
Thanks in Advance!
Steve
|
|
|
|
|
I'm writting an MMC utility to do some remote admin. I need to be able to connect to a computer by computer name on the local network and stop/start services. I know this can be done through Windows 2000/NT management tools but I need this capability in my MMC snap-in. Does anyone know what library or functions I can use for this task. Just give me a name and I can search on it. Thanks.
|
|
|
|
|
Hi there,
Could somebody help me to figure out how to restore Visual Studion (version 6) settings, of a user in WinNT.
Thus because the user keeps getting an error message: "memory cannot be read" when executing the MSDEV.EXE,
but under the admin and other accounts it's still working fine.
Thanks for any help, or idea
|
|
|
|
|
How to convert a BSTR into LPSTR?
|
|
|
|
|
#include <atlconv.h>
void convert(BSTR bstr)
{
USES_CONVERSION;
LPSTR sz = W2A(bstr);
LPCSTR sz2 = W2CA(bstr);
}
The new strings allocated by the W2A and W2CA macros are on the stack, so they will vanish once the function returns.
|
|
|
|
|
I want that my application will work in english and in my language.
How can I do it?
|
|
|
|
|
This looks like a school project, but it's not.
Having used mutexes and semaphores a zillion times, "finally the time has arrived to write my own implementation for use in an embedded system without OS."
I did some research on the matter and I found Peterson's Algorithm (for 2 processes, threads or whatever) and Lamport's bakery algorithm (for N processes, threads or whatever). There is no need to reinvent "hot water" again, an existing algorithm will do just fine.
For info,
Peterson's Algorithm:
int flag[2] = { FALSE, FALSE } // flag[i] indicates that Pi wants to
// enter its critical section.
int turn = 0; // turn indicates which process has
// priority in entering its critical
// section.
// mutexbegin:
flag[i] = TRUE;
turn = 1 - i;
while (flag[1 - i] && turn == 1 - i)
;
// mutexend:
flag[i] = FALSE;
Now Lamport's Bakery algorithm.
Assumptions:
NPROCS is the number of processes.
max(int *array) returns the maximum value in array.
Each process has a unique ID, so ties on the number chosen are broken by comparing IDs.
Replace i with the appropriate process ID.
// Global initialization:
int choosing[NPROCS] = { FALSE };
int number[NPROCS] = { 0 };
// mutexbegin:
choosing[i] = TRUE;
number[i] = max(number) + 1;
choosing[i] = FALSE;
for (j = 0; j < NPROCS; ++j)
{
while (choosing[j])
;
while (number[j] != 0 && (number[j] < number[i] ||
number[j] == number[i] && j < i) )
;
}
// mutexend:
number[i] = 0;
THE QUESTION:
in the line
number[i] = max(number) + 1;
we see the function 'max'. How do I interprete this?
I thought it meant the maximum of all the numbers in number[], but that does not seam to work.
Also, any suggestions on writing a
bool CPP_Mutex::TryEnter(unsigned int PNumber)
function ?
Any input or pointers greatly appreciated!
NOTE: I know this class produces what is called a "spinning lock", but that's OK.
I tested it with a dual processor machine with the following code:
#define NPROCS 2
#undef Max
#define Max(A,B) ((A)<(B)?(B):(A))
// Implementation of LAMPORTS Bakery Algorithm
class CPP_Mutex
{
public:
CPP_Mutex()
{
memset(m_nChoosing, 0, sizeof(int)*NPROCS);
memset(m_nNumber, 0, sizeof(int)*NPROCS);
}
~CPP_Mutex()
{
}
void Enter(unsigned int PNumber)
{
m_nChoosing[PNumber] = 1;
m_nNumber[PNumber] = MAX(m_nNumber) + 1;
m_nChoosing[PNumber] = 0;
for (unsigned int teller = 0; teller < NPROCS; teller++)
{
while (m_nChoosing[teller])
;
while ( m_nNumber[teller] != 0
&& ( m_nNumber[teller] < m_nNumber[PNumber] ||
m_nNumber[teller] == m_nNumber[PNumber] && teller < PNumber)
)
;
}
}
void Leave(unsigned int PNumber)
{
m_nNumber[PNumber] = 0;
}
protected:
int MAX(int* numbers)
{
int toReturn = 0;
for (unsigned int teller = 0; teller < NPROCS; teller++)
{
toReturn = Max(toReturn, *(numbers+teller));
}
return toReturn;
}
private:
int m_nChoosing[NPROCS];
int m_nNumber[NPROCS];
};
unsigned int value = 0;
unsigned int prevvalue = 0;
bool stop = false;
CPP_Mutex theTestMutex;
void IncreaseValue(unsigned int PNumber)
{
// if (theTestMutex.TryEnter(PNumber))
{
theTestMutex.Enter(PNumber);
prevvalue = value;
value++;
assert(prevvalue == value-1);
// cerr << PNumber << ":" << value << "\t";
theTestMutex.Leave(PNumber);
}
}
DWORD WINAPI ThreadProc( LPVOID lpParameter )
{
while (!stop)
{
IncreaseValue((unsigned int) lpParameter);
}
return 0;
}
int main(int argc, char* argv[])
{
HANDLE hThread1 = NULL;
HANDLE hThread2 = NULL;
DWORD dwThreadID1 = 0;
DWORD dwThreadID2 = 0;
hThread1 = ::CreateThread(NULL, 0, ThreadProc, (void*) 0, 0, &dwThreadID1);
hThread2 = ::CreateThread(NULL, 0, ThreadProc, (void*) 1, 0, &dwThreadID2);
WaitForSingleObject(hThread1, 60000);
stop = true;
WaitForSingleObject(hThread1, INFINITE);
WaitForSingleObject(hThread2, INFINITE);
CloseHandle(hThread1);
CloseHandle(hThread2);
return 0;
}
|
|
|
|
|
Out of curiosity, how are you getting multiple threads if you don't have an OS?
Also, if this is an x86 processor, you can use the SMP correct incrementers in x86 assembler. These are instructions which guarantee that they will execute fully before allowing access. IIRC they are instructions such as XADD or something similar.
|
|
|
|
|
A Problem with the previously mentioned algorithms is that they assume "atomic" read and write operations.
I also found this solution which is, like you say is dependent on "undividable" processor instructions.
// ALGORITHM
////////////
// wait(s)
// { set s = 0 and if old value of s was 0 then
// repeat
// 'wait'
// until set s = 0 and old value of s was 1 }
// signal(s)
// { s = 1; Tell OS if appropriate }
Concerning, "how are you getting multiple threads if you don't have an OS?".
From my perspective (WinNT/W2K backend programmer, now engaged in building software for a NO-OS device), the device we are building has two "tasks" ("Threads").
It has a slow main loop (task 1) which can be 'interrupted' ("pre-empted") by the driver level (task 2..N).
The idea is to have the driver level handle the Hardware dependent stuff, e.g. detect if a keypad button that was pressed, and put it in an event queue for the slow main loop to process.
If my main loop can get interrupted at any time, I need some protection (locking) on the queue, otherwise it will get corrupted. (if it is locked by the main loop, I could put the event in a temporary queue and put it in the real queue some time later (ASAP of course) )
The standard way of avoiding corruption is:
mutex_begin()
{
disable_interrupts();
}
mutex_end()
{
enable_interrupts();
}
Which of course could lead to "event loss".
The algorithm above (based on TestAndSet) is an improvement over this, but it needs to be supported by processor instructions.
Since I am not a whizz kid in assembler (let's be honest, I never had to use it before so I never did), I am gratefull for any pointers or assembler crash courses that anyone can give me about these undividable SMP safe (i386) instructions I could use to implement a Test And Set function.
// MSDN example
int power2( int num, int power )
{
__asm
{
mov eax, num ; Get first argument
mov ecx, power ; Get second argument
shl eax, cl ; EAX = EAX * ( 2 to the power of CL )
}
/* Return with result in EAX */
}
// my would-be function that sets a value (nValue) on the target address (pTargetAddress) and returns the previous value (that was found in pTargetAddress)
int testandset(int* pTargetAddress, int nValue)
{
__asm
... // help !
}
Best regards,
Gert.
|
|
|
|
|
I think this is it, unless I'm mistaken.
int TestAndSet(int* pTargetAddress, int nValue)
{
__asm
{
mov edx, dword ptr [pTargetAddress]
mov eax, nValue
xchg eax, dword ptr [edx]
}
}
|
|
|
|
|
Anyone know of any good face recogition software? I've got two bitmaps, and I'd like to compare them to see if they are the same person.
|
|
|
|
|
Hello!
I have been trying to set the color of a slider I created with MFC. I managed to color it's background but didn't manage to change the slider "knob" or "path" color, how is this done?
I also have a Combobox wich I would like to change the color of as well, but it didn't work out either. I tried to check the "owner drawn and with strings on the Combobox, but I still couldn't change the colors and over the text was the picture of my icon, hmm...
Then there's the frame of the window, I beieve I should override OnNcPaint() function for this but either I'm wrong or doig it wrong. =)
And changing the color of the entire application menu would be very nice if I could do this too.
I tried to override OnPaint, but it didn't work... I could use some samples of code, since I seem to be doing something wrong when I don't get it to work. =) I heard something about "changeing the thumb and track colors using custom draw." how is this done in code?
Thanks,
/Fredrik
|
|
|
|
|
Try
http://www.codeproject.com/miscctrl/cfctrl.asp
Not exactly what you want, but you could work from here...
HTH
Jerry
|
|
|
|
|
Thanks, that helped with the colors in the ComboBox, but my real problem is the color of the little thin line around the ComboBox and the little arrow for klicking on the combobox to bring down the choices in it. Does anyone know how to override the dialog from getting these colors from the system and how to set them? I have tried a lot of things but none seems to work.
Also, how to paint the frame of the dialog window and how to override the menu colors, not just the fields in the menu, but I want contol over the whole menu and what color it has.
I really need help with this, this problem is really killing me!
|
|
|
|
|
Simple just paint over it!
Have a look here...
http://www.codeproject.com/combobox/combobox_flatcombo.asp
HTH
Jerry
|
|
|
|
|
I have a dialog-based application. I would like to hide the main dialog and display an icon only in the system tray. I've tried to use ShowWindow(SW_HIDE), but the dialog still appears.
In "ApplicationName.cpp" file and in "InitInstance" module, my codes look like the following:
CFwuTestDlg dlg; //1 //the main dialog
m_pMainWnd = &dlg; //2
m_pMainWnd->ShowWindow(SW_HIDE);//3
m_pMainWnd->UpdateWindow();//4
int nResponse = dlg.DoModal();//5
return FALSE;//6
I've tried to delete line 5, but Windows complains that .exe file generate error.
Could anyone help me? Thank you.
|
|
|
|
|
First, you do not need to hide the dialog. The way that the system tray works is that windows are minimized to be not shown.
http://www.codeproject.com/shell/systemtray.asp
http://home.socal.rr.com/samhobbs/VC/TaskbarStatusIcon.html
You certainly do not want to remove the DoModal (line 5) but you do want to remove the ShowWindow and UpdateWindow (lines 3 and 4).
|
|
|
|
|
Is it possible to store pointers to objects in the STL collection classes and have the collection automatically destroy the objects as the collection elements are destroyed? e.g.:
class A
{
int var1;
};
vector<a*> v;
A* obj1 = new A;
A* obj2 = new A;
v.push_back(obj1);
v.push_back(obj2);
v.clear();
The last statement here will remove all elements from the vector but won't delete the actual objects, *obj1 and *obj2. Can vector be specialised so it will delete the objects its elements point to? (This can be done fairly easily in MFC so I am hoping the same is true for STL)
|
|
|
|
|