|
Cool thanks!
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Of course, %c for char! I was sure it had a simple answer but couldn't see it for looking - most embarrassing. Too many years of VB?
So big thanks Maxwell and Mark! Also Mark, I was starting to think of assembling a 2 byte char array as you suggested - that'd work with %s.
Also special thanks to Rajkumar R for the ToAscii suggestion, which is intriguing to say the least, since it requires a GetKeyboardState call to set its 256 byte array arg, lpKeyState, to the current status of *all* the virtual keys. I would have thought GetKeyState for just the virtual key in question (1st arg, uVirtKey),would be sufficient.
I suppose ToAscii will be a case-sensitive conversion - will give it a shot and see what happens.
int ToAscii(
UINT uVirtKey,
UINT uScanCode,
PBYTE lpKeyState,
LPWORD lpChar,
UINT uFlags
);
Here's the MSDN article...
http://msdn2.microsoft.com/en-us/library/ms646299(VS.85).aspx
Thanks again everyone!
glyfyx
|
|
|
|
|
glyfyx wrote: I tried to convert a keyboard virtual key code to a it's ascii character
if you are converting from Keyboard Virtual KeyCode, use
int ToAscii(
UINT uVirtKey,
UINT uScanCode,
PBYTE lpKeyState,
LPWORD lpChar,
UINT uFlags
);
glyfyx wrote: The offending later statement is:
nLen = fprintf(fOut,"kcK=%d ud=%s kc=%d sh=%d ti=%d %s\n",cb.kcK,updn,keyCode,Shift,tick, c);
format specifier is %s and passing char, c.
|
|
|
|
|
The arguments you pass to fprintf() need to match the format specifiers in the
format control string, in both type and number of arguments.
All the "%d"s in the format control string need a corresponding 32-bit integer argument passsed...
All the "%s"s in the format control string need a corresponding pointer to a null-terminated string passed.
The version where you don't pass the c argument only appears to work, since you pass 5 arguments
when the format control string specifies an expected 6 arguments.
The version that crashes probably fails because c is a char but the format specifier is %s, which means
the passed argument should be a pointer to a NULL-terminated string, not a single character.
If you do something like this, it should work:
char c<font color="Red">[2]</font>;
c<font color="Red">[0]</font> = (char)__toascii(keyCode);
<font color="Red">c[1] = '\0';</font>
keyCode = p->vkCode;
...
nLen = fprintf(fOut,"kcK=%d ud=%s kc=%d sh=%d ti=%d %s\n",cb.kcK,updn,keyCode,Shift,tick, c);
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
In Button event I wrote ...
CMatlabEng matlab;
matlab.Open(NULL);
But MatLab is not opening .....Plz Help me.........
#sanroop#
|
|
|
|
|
like this way i fallow ...
Open MSVisualC++.
Select Tools ->Customize from the MSVC menu.
Click on the Add-ins and Macro Files tab.
but MATLAB for Visual Studio on the Add-ins and Macro Files list is not showing...PLZ help me...How to Configure the Matlab Add-in for Visual Studio vc++ 6.0..PLZ
#sanroop#
|
|
|
|
|
Hi all
I am locking a file.First times it locks..but second time if i want to unlock..it is not unlocking the file..plz help me ..here is the code....
int LockFile(char *cFileName, bool bLock)
{
int iFile;
if(bLock)
{
iFile = _open(strcat(cFileName, ".lck"), _O_CREAT | _O_EXCL | _O_RDWR);
_close(iFile);
if(iFile < 0)
{
printf("File locked by another process");
return -1;
}
printf("File is locked for writting");
return iFile;
}
else
{
iFile = remove(strcat(cFileName, ""));
if(iFile == -1)
{
printf("Error in file unlocking");
return -1;
}
printf("File unlocking successfull");
}
return iFile;
}
int main(int argc, char* argv[])
{
char strFilePath []= {"E:\\Add_Modified_ENG\\test.txt"};
char *cFilePath = strFilePath;
int i = LockFile(strFilePath, true);
if(i != -1)
{
ofstream outfile(cFilePath, ios::app);
if(!outfile)
{
cout<<"Unable to open\n";
return 1;
}
outfile<<"Test";
outfile.close();
}
i = LockFile(strFilePath, false);
return 0;
}
Hi,,
I am sharan.Working as a software Engineer in Indo-Fuji Software Company located in BTM Layout.Bangalore.India.
I have Completed my B.E(COmputers)in 2006.ANd I am having 2 years of Exp in VC++.
thanking you
sharan
|
|
|
|
|
I think you are creating a lock file; You are not locking a file.
sharanu wrote: iFile = _open(strcat(cFileName, ".lck"), _O_CREAT | _O_EXCL | _O_RDWR);
and
sharanu wrote: iFile = remove(strcat(cFileName, ""));
file names are different isn't it?
|
|
|
|
|
File names are same..in first
iFile = _open(strcat(cFileName, ".lck"), _O_CREAT | _O_EXCL | _O_RDWR);
I am caoncated the(.lck)i.e is locking the file...
In second i am remove the lock
iFile = remove(strcat(cFileName, ""));
Hi,,
I am sharan.Working as a software Engineer in Indo-Fuji Software Company located in BTM Layout.Bangalore.India.
I have Completed my B.E(COmputers)in 2006.ANd I am having 2 years of Exp in VC++.
thanking you
sharan
|
|
|
|
|
yes, i just looked at LockFile function only, But then you are accessing the array beyond its size
char strFilePath []= {"E:\\Add_Modified_ENG\\test.txt"}; concatenation causes corrupted stack;
Any way your problem is you are creating the file in Read only permission, so remove(), DeleteFile() won't work unless you change the readonly attribute of the file.
try this.
iFile = _open(strcat(cFileName, ".lck"), _O_CREAT | _O_EXCL | _O_RDWR, _S_IREAD | _S_IWRITE);
|
|
|
|
|
Hi its not working .....
It is printing as "Test" in File
Hi,,
I am sharan.Working as a software Engineer in Indo-Fuji Software Company located in BTM Layout.Bangalore.India.
I have Completed my B.E(COmputers)in 2006.ANd I am having 2 years of Exp in VC++.
thanking you
sharan
|
|
|
|
|
Now u are able to call the remove() successfully, Isn't it.
What you are trying to achieve? i already told change the read only attribute before remove().
_chmod() / SetFileAttributes() to change the readonly attributes.
If you want to lock a file, LockFile() / _locking()/_lock_file() API is there.
|
|
|
|
|
Hi,
I have changed the background color of my CToolBar. Now I would like to change the background color CToolBar's parent window which is AfxControlBar*. How could I do this ?
Any help would be appreciated.
Thanks,
Paresh
|
|
|
|
|
What exactly you trying to do??
Anyways simple way to change background color is Handle WM_CTLCOLOR message and return a brush of new color.
|
|
|
|
|
Hi Sandip,
I want to paint the background color of the CToolbar. However, I am able to paint only the area which belongs to CToolbar and not the AfxControlBar, which is the parent of CToolbar. (though we have a m_wndToolbar as a member of CMainFrm).
I hope you understand the issue.
Regards,
Paresh.
|
|
|
|
|
dear all
i would like to generate several different Gaussian function according to different sigma,and then can determine x and y value(ie. bound), and then it can determine the size of Gaussian mask. the formula is below: it is Gaussian function: g(x,y)=1/2*3.14*exp(-(pow(x,2)+pow(y,2)))/2*pow(sigma,2)
thanks a lot.
Li Zhiyuan
|
|
|
|
|
I want to continuously poll one of the pins of my parallel port for activity. I've written a function to do this, but I can't find where to call the function. Every place I place the function call, it executes before my SDI page appears. I want to use an SDI environment so I can print out the data stream detected on the port pin. How do I implement my function???? Signed/Confused!
|
|
|
|
|
Does your function contain the polling loop or does it need to be called periodically?
If the function contains the loop, then your UI is never going to appear unless you provide a way for
messages to get dispatched to windows.
You could put your loop on a separate thread. Note that a "busy" loop will consume nearly all your CPU...
not very friendly to UI of your app or other apps.
You could also use a timer and periodically poll instead of using all the CPU polling.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for the reply!
If I use a Timer in an SDI application, how would I implement it in the Document, which is where I assume it would have to go? I'm having trouble defining the first parameter of the SetTimer() function (asking for a handle to the window).[ I consider myself an Intermediate programmer, but I haven't worked much with SDI; only Dialog-based apps. ]
|
|
|
|
|
A window timer will need a window, so the view class is a better place to implement that type of timer.
For better timer resolution, and without a window, you can use a multimedia timer.
timeBeginPeriod()/timeSetEvent()/timeKillEvent()/timeEndPeriod() are the multimedia timer
functions you'd need. A multimedia timer can periodically call a callback function or set/signal
an event - way more flexible than a window timer.
Note that multimedia timer events/callbacks occur on a different thread, so if in response to the
timer you need to mess with UI, you'll need to synchronize access to UI/GDI with the app's UI thread.
Here's an example...
<font color="Green">
UINT wTimerRes = 0;
MMRESULT mmTimerId = 0;
static void CALLBACK MyTimerProc(UINT, UINT, DWORD_PTR dwUser, DWORD_PTR, DWORD_PTR);
void StartTimer();
void StopTimer();
<font color="Green">
CMyDocumentClass::CMyDocumentClass()
{
UINT wTimerRes = 0;
MMRESULT mmTimerId = 0;
}
void CMyDocumentClass::StartTimer()
{
TIMECAPS tc;
if (::timeGetDevCaps(&tc, sizeof(TIMECAPS)) == TIMERR_NOERROR)
{
<font color="Green">
wTimerRes = min(max(tc.wPeriodMin, 1), tc.wPeriodMax);
::timeBeginPeriod(wTimerRes);
<font color="Green">
mmTimerId = ::timeSetEvent(100, wTimerRes, &CMyDocumentClass::MyTimerProc, (DWORD_PTR)this,
TIME_PERIODIC | TIME_CALLBACK_FUNCTION);
}
}
void CMyDocumentClass::StopTimer()
{
if (mmTimerId)
{
::timeKillEvent(mmTimerId);
mmTimerId = 0;
::timeEndPeriod(wTimerRes);
wTimerRes = 0;
}
}
void CALLBACK CMyDocumentClass::MyTimerProc(UINT, UINT, DWORD_PTR, DWORD_PTR, DWORD_PTR)
{
CMyDocumentClass *pThis = (CMyDocumentClass *)dwUser;
<font color="Green">
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Is there a way for your program to tell the list view control what height you want items to be in detail/report mode? The only immediate solution I see is to assign the list view small image list with a list that has the dimensions you want. Is there some way to do this by handling some LVN_XXX message (or something like that)?
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
Save an Orange - Use the VCF!
VCF Blog
|
|
|
|
|
I'm working exactly in the same thing!!!
First I used LVM_GETITEMRECT message, but the items height are always 17 in report mode. Even if they have a larger icon. In my case small images are 32x32 and item heights are 33.
rotter
|
|
|
|
|
Just a guess, but I think you may need to use the LVS_OWNERDRAWFIXED style.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
The row height is the greater of the height of a row of text and the height of the image list, plus a couple pixels for padding. As David said, if you need precise control, you'll need to use owner draw.
|
|
|
|
|
template <class t=""> <br />
class CProtectedVariable <br />
{<br />
CProtectedVariable()<br />
{<br />
} ; <br />
<br />
~CProtectedVariable()<br />
{<br />
}<br />
<br />
protected :<br />
T m_Var ; <br />
<br />
} ; </class>
when i do this and include this another class as a member. I am getting a few compiler errors
#include "Protected.h" <br />
class OutSideClass <br />
{<br />
protected :<br />
CProtectedVariable<bool> m_initState ; <br />
};</bool>
error C2248: 'CProtectedVariable<t>::CProtectedVariable' : cannot access private member declared in class 'CProtectedVariable<t>'<br />
1> with<br />
1> [<br />
1> T=bool<br />
1> ]</t></t>
What am I missing here ?
Engineering is the effort !
|
|
|
|
|