|
See more: VC++
Dear All,
I am working MFC Application, this application is compiled using VS2008.
To capture the key pressed
OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
method is used.
The strange thing happening is when i press the key "a" without caps lock its gives the nChar value as "65" which is suppose to be "97".
Even if the caps lock is "ON" the value i get is "65" when i press "A".
The thing is either the caps lock is on or off, i get the same value as if the caps lock is on. (this is the case with all the keys)
as the OnKeyUp() is as MFC method, I am not sure how to solve this issue.
Kindly help me and let me know if you require any more information.
Below is the code i am using, because of this what happens is, when i set a text using SetDlgItemText(), it is always going as Upper case letter or word.
void CMyProg::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CString SBCommand;
CString Temp;
char *s = NULL;
char strnChar[10];
/* Alphabets and Numerals passed to the command box */
if((nChar >= 65 && nChar <= 90) || (nChar >= 48 && nChar <= 57))
{
pFrame->m_wndStatusBar.GetDlgItemText(IDC_SB_POINT,SBCommand);
Temp.Format("%c",nChar);
SBCommand += Temp;
pFrame->m_wndStatusBar.SetDlgItemText(IDC_SB_POINT,SBCommand);
/*pFrame->m_wndStatusBar.GetDlgItemText(IDC_SB_POINT,SBCommand);
SBCommand += (char*)nChar;
pFrame->m_wndStatusBar.SetDlgItemText(IDC_SB_POINT,SBCommand);*/
}
}
|
|
|
|
|
OnKeyDown: The key is Kept Down
OnKeyUp: The Key is released
The above two together form OnKeyPress
All three will give the state of the Keys.
OnChar is the best event for your expectation.
|
|
|
|
|
The character value is a virtual-key[^] code. You can use GetKeyState(VK_SHIFT) to check if any shift key is pressed or not.
Depending on your requirements, it may be better to handle WM_CHAR notifications (CWnd::OnChar() ) rather than using key up/down notifications. Then you will get the character code of the key that was pressed.
|
|
|
|
|
In addition to VK_SHIFT , you may also want to check the state with VK_CAPITAL .
|
|
|
|
|
Hi In VC++ 2005 i am working in SDI applications
1) How to change the whole background color of CStatusbar including all panes.also
2)How to change background color of a Menubar.
|
|
|
|
|
You will have to owner draw it.
For ex:
For the status bar you can do something like:
m_statusBar.SendMessage (/*setback color msg/*, 0 , (LPARAM)RGB (128,128,128)) ;
You talk about Being HUMAN. I have it in my name
AnsHUMAN
|
|
|
|
|
hi can you give the example.
|
|
|
|
|
Here[^]. here[^]
Also, you can find many other examples relating to owner drawn controls
You talk about Being HUMAN. I have it in my name
AnsHUMAN
|
|
|
|
|
|
Hi all
I created a Activex, when you click a button in Activex opens a FileDialog but when I click on treeview with folders list the list files screen is not update.
I started with C:\ folder, even I change folders in treeview or press F5 nothing happens. I'm using Windows 7 and this problem just happen inside a ActiveX and IE9. In the older version this just not happen and the code is the same.
Here is the code:
CFileDialog dlg(TRUE, szMask, szPath,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
aux, NULL, 0, TRUE);
dlg.m_ofn.lpstrInitialDir = initialDir;
if (dlg.DoModal() != IDOK) {
return;
}
Anyone can help me.
Thank you
|
|
|
|
|
What value are you passing in szMask?
|
|
|
|
|
Hi
I'm using default All files (*.*)
|
|
|
|
|
I think in this case you should pass NULL. Please note that you need to pass only extension, e.g. for Excel files you would pass _T("xls"). For all files, pass NULL in place of szMask
|
|
|
|
|
Thank you
But my problem is not with mask, when I use my activex component inside IE9, when I click on treeview with folder names the screen where show files are not refreshing, my initial dir is C:\ but if I click in e.g D:\ nothing is showed, the screen stays in C:\. This just happen with activex in browser. I could check if set to FALSE the last parameter in CFileDialog constructor is working in both cases, in my application and browser, this parameter set Vista Style dialog, but is not a acceptable solution.
|
|
|
|
|
Can someone please explain / provide better description about this C2010 error to me.
I have never used “...” ellipsis as function parameter.
Why is the compiler complaining about this?
Is this some recent addition to the language?
I am still happily using VC 6.0 and have no desire to let go of it.
Source:
#define USBERR(format,...) usb_err(__FUNCTION__,format,__VA_ARGS__)
#define USBERR0(format) usb_err(__FUNCTION__,"%s",format)
Error:
k:\0\0 littlewire\downloads\usb library\libusb-win32-src-1.2.6.0\libusb-win32-src-1.2.6.0\src\error.h(131) : error C2010: '.' : unexpected in macro formal parameter list
Only the first #define fails and I am not really sure I need it. I would be happy just to compile this USB library for now.
Any help will be as always greatly appreciated.
Thanks Vaclav
|
|
|
|
|
See Variadic Macros[^] in the MSDN.
The above link is for Visual Studio 2005 which introduces Variadic Macros. So it seems that you are using an older VS version.
|
|
|
|
|
Thank you.
My suspicion was correct, it is a recent (MS? ) addition to the language.
I'll try to bypass it and see if there are any serious problems with it.
I have not analyzed the library to see if the macro is executed as a result of logic error or hardware error.
|
|
|
|
|
|
Vaclav_Sal wrote: Only the first #define fails and I am not really sure I need it. So comment it out and see what happens.
You could always create something like:
#define USBERR1(format,argv1) usb_err(__FUNCTION__,format,argv1)
#define USBERR2(format,argv1,argv2) usb_err(__FUNCTION__,format,argv1,argv2)
#define USBERR3(format,argv1,argv2,argv3) usb_err(__FUNCTION__,format,argv1,argv2,argv3)
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Hi everybody. I trying to draw an overlay over a CDib bitmap:
CSize sizeDoc = pDoc->GetDib()->GetDimensions();
int cx = (int)((float)sizeDoc.cx * m_fZoomFactor);
int cy = (int)((float)sizeDoc.cy * m_fZoomFactor);
CSize sizeLog(cx, cy);
CBitmap bmp;
bmp.CreateCompatibleBitmap(pDC, sizeLog.cx, sizeLog.cy); CDC MemDC;
MemDC.CreateCompatibleDC(pDC); CBitmap* pOldBitmap = MemDC.SelectObject(&bmp); pDoc->GetDib()->Draw(&MemDC, CPoint(0,0), sizeLog); DrawOverlay(&MemDC, pDC); pDC->BitBlt(0, 0, sizeLog.cx, sizeLog.cy, &MemDC, 0, 0, SRCCOPY); pDC->SelectObject(pOldBitmap);
and everything goes well, except when user try to drag the view, while view goes slowly ... why ? (That behaviour is more visible when the picture is a little bit zoomed)How can I speed up the code from above ? Or, what I'm doing wrong ?
I have here[^] a simple sample project .... Thank you.
modified 16-Oct-12 7:28am.
|
|
|
|
|
The problem is with this line:
pDoc->GetDib()->Draw(&MemDC, CPoint(0,0), sizeLog);
You need to replace it with another BitBlt that will copy stuff to MemDC
|
|
|
|
|
Thank you for your interest. But I don't know how can I put content of CDib (CMyDoc::m_dib) into MemDC with CDC::BitBlt(...). Can you show me a little sample here ? Will be very helpfull to me ... You can test the behaviuour from above post link.
|
|
|
|
|
You need to create DIB (I think you have already already created it based on the code), then you need to copy the bitmap bits to the DIB's buffer using this code:
HBITMAP hOldBitmap = NULL;
if (m_hBitmap == NULL)
{
m_hBitmap = CreateDIBSection(hDC, (BITMAPINFO*)m_hDib, DIB_RGB_COLORS, &m_lpBits, NULL, 0);
if (m_hBitmap == NULL) return;
if (m_lpBits == NULL)
{
::DeleteObject(m_hBitmap);
m_hBitmap = NULL;
return;
} }
memcpy(m_lpBits, ((LPBYTE)m_hDib + *(LPDWORD)m_hDib + GetPaletteSize()), m_bi.biSizeImage);
if (m_hMemDC == NULL)
{
m_hMemDC = CreateCompatibleDC(hDC);
if (m_hMemDC == NULL) return;
}
hOldBitmap = (HBITMAP)SelectObject(m_hMemDC, m_hBitmap);
BitBlt(hDC, dwX, dwY, m_bi.biWidth, m_bi.biHeight, m_hMemDC, 0, 0, SRCCOPY);
SelectObject(m_hMemDC, hOldBitmap);
The main part here is the memcpy.
I have copied it from my program. If you can't understand what the "m_" variables are, let me know and I will explain
|
|
|
|
|
Yes, I know what 'm_' is, (member variable), but I also saw that you have m_hMemDC, so you apply the double-buffering tehnique ? Like in this[^] application ?
Anyway, I kindly thank you, I'll apply your ideea ...
|
|
|
|
|
Google it for "Double Buffering"
|
|
|
|
|