|
I am using fragments of code from Microsoft OneInstance sample. When application starts and it founds other instance window, it activates it using next code:
pWndPrev = CWnd::FindWindow(lpszUniqueClass,NULL);
if ( pWndPrev )
{
pWndChild = pWndPrev->GetLastActivePopup();
if (pWndPrev->IsIconic())
pWndPrev->ShowWindow(SW_RESTORE);
pWndChild->SetForegroundWindow();
}
In Windows XP, if pWndPrev is minimized, it is not restored. This code works fine in all previous Windows versions. What changes should be done in this code to work properly in XP ?
|
|
|
|
|
Hi -
I also would love to find a code solution to your problem, but I think it's a registry tweak, which requires a re-login after changing.
HKEY_CURRENT_USER\Control Panel\Desktop
set ForegroundLockTimeout = 0 (DWORD)
set ForegroundFlashCount = 0 (DWORD)
A short article on this at:
http://www.windows2000faq.com/Articles/Index.cfm?ArticleID=15978
If you do find a code solution, please post to this thread.
|
|
|
|
|
|
How can I prevent a user from accessing my ISAPI extension directly from his browser?
I have an ISAPI extension that can be accessed by the URL - <nobr>[http://www.mysite.com/scripts/myisapi.dll?query=value]
I access the extension from an asp page through a form submit request. Now my problem is that anybody smart enough to decipher the url and the query string that needs to be provided to the extension can access it successfully. I would want to prevent this access. How can I go about achieving this?
|
|
|
|
|
Hi,
I can't think of a simple way to do this, but you could modify you ASP code to add an application-specific HTTP header field to the request (I think - I don't know ASP real well) and check for that header in your ISAPI extension. A user could potentially write their own code to include that header, but it would at least prevent someone executing the ISAPI from their browser.
Another possibility is the HTTP header HTTP_QUERY_REFERER which is not always provided, but would show the URL that linked to the ISAPI extension. You'll just need to make sure that the URL matches your ASP page.
Hope this helps.
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
thanks derek !
I have considered your advice. But the methods suggested above are not void of loopholes. Http headers are prone to tampering and URL addresses can be spoofed.
I have been looking at the method by which asp pages are prevented from malicious access by the use of session ids. I am talking about the session ids created by the ASP engine. But I have no idea of how to access the same session id in my extension. I want to obtain the session id from the asp engine directly from my extension.
Is this possible?
|
|
|
|
|
Hi,
As far as I know, there is no way to get the session id outside of ASP (which is not to say that there isn't a way!).
If you are attempting to prevent malicious use of the ISAPI extension, would it be possible to encrypt the query string before passing it to the ISAPI DLL? If the ISAPI DLL reads the query string and can't decode it, then assume it comes from a spurious source and do something accordingly. We use a similar system to this (although our encryption is done by a client-side app, rather than an ASP page).
------------------------
Derek Waters
derek@lj-oz.com
|
|
|
|
|
Hi,
I need to retrieve the logical coordinates of the printer, I tried to use this:
CSize Test;
Test.cx = pDC->GetDeviceCaps(HORZRES);
Test.cy = pDC->GetDeviceCaps(VERTRES);
The I use that logical coordinates to print a metafile, but seems that the coordinates are not the right ones ( they are small), how can I retrieve that logical size ?, Thanks, Bye !
Braulio
|
|
|
|
|
I think your problem is in the conversion. Metafile needs coordinates in .01 millimeter units.
Try something like this:
RECT rc;
rc.top = rc.left = 0;
int iWidthMM = pDC->GetDeviceCaps(HORZSIZE);
int iHeightMM = pDC->GetDeviceCaps(VERTSIZE);
int iWidthPels = pDC->GetDeviceCaps(HORZRES);
int iHeightPels = pDC->GetDeviceCaps(VERTRES);
rc.right = (nWidth * iWidthMM * 100)/iWidthPels;
rc.bottom = (nHeight * iHeightMM * 100)/iHeightPels;
HDC hMetaDC = CreateEnhMetaFile(pDC->GetSafeHdc(),_T("C:\\Temp\\Image.emf"), &rc, _T("Your Description\0Image\0\0"));
- God bless the World
|
|
|
|
|
Hi,
I would like to rotate 90º a metafile, in order to make fit two pages in one if the user chooses to print in A3 format. How can I rotate a metafile ?.
Thanks, Bye !
Braulio
|
|
|
|
|
how to make the pocketPC become fullscreen (including hide the taskbar and menubar) in eVC (embeded visual c++ 3.0)
pls answer it as soon as posible, T.Q.!
|
|
|
|
|
Try article "Q266244" in MSDN.
HOWTO: Create Full-Screen Applications for the PocketPC
Normski. - Professional Windows Programmer
|
|
|
|
|
The Following code works fine except for the black edges that are displayed in the Transparent Image. How can I get rid of that???
COLORREF m_crWhite = RGB(255,255,255);
COLORREF m_crBlack = RGB(0,0,0);
//pdc is the Screen Dc
COLORREF crOldBack = pDC->SetBkColor(m_crWhite);
COLORREF crOldText = pDC->SetTextColor(m_crBlack);
COLORREF crOldBkMode = pDC->SetBkMode(TRANSPARENT);
//The Following 2 lines gives me image information.
int nImageWidth = m_pImageInfoData->bmpInfo.bmiHeader.biWidth;
int nImageHeight = m_pImageInfoData->bmpInfo.bmiHeader.biHeight;
CBitmap BmpMask;
BmpMask.CreateBitmap( nImageWidth, nImageHeight, 1, 1, NULL);
CDC hdcSrc, hdcDst;
hdcSrc.CreateCompatibleDC(pDC);
hdcDst.CreateCompatibleDC(pDC);
CBitmap BmpSource;
BmpSource.CreateCompatibleBitmap(pDC,nImageWidth,nImageHeight);
CBitmap* hbmSrcT = (CBitmap*) hdcSrc.SelectObject(&BmpSource);
CBitmap* hbmDstT = (CBitmap*) hdcDst.SelectObject(&BmpMask);
StretchDIBits(hdcSrc.GetSafeHdc(),
0, 0, nImageWidth, nImageHeight,
0, 0, nImageWidth, nImageHeight,
m_pImageInfoData->pszData,
&(m_pImageInfoData->bmpInfo),
DIB_RGB_COLORS, SRCCOPY);
COLORREF clrSaveBk = hdcSrc.SetBkColor(crColor);
hdcDst.BitBlt(0,0,nImageWidth, nImageHeight, &hdcSrc,0,0,SRCCOPY);
COLORREF clrSaveDstText = hdcSrc.SetTextColor(RGB(255,255,255));
hdcSrc.SetBkColor(RGB(0,0,0));
hdcSrc.BitBlt(0,0,nImageWidth, nImageHeight, &hdcDst,0,0,SRCAND);
hdcDst.SetTextColor(clrSaveDstText) ;
hdcSrc.SetBkColor(clrSaveBk);
pDC->StretchBlt( nLeft, nTop, nWidth, nHeight, &hdcDst,
0, 0, nImageWidth,nImageHeight,SRCAND);
pDC->StretchBlt( nLeft, nTop, nWidth, nHeight, &hdcSrc,
0, 0,nImageWidth,nImageHeight,SRCPAINT);
hdcSrc.SelectObject(hbmSrcT);
hdcDst.SelectObject(hbmDstT);
hdcSrc.DeleteDC();
hdcDst.DeleteDC();
pDC->SetBkMode(crOldBkMode);
pDC->SetTextColor(crOldText);
pDC->SetBkColor(crOldBack);
|
|
|
|
|
Change your image so the outside square is the mask color. Or do you mean black edges around your image ? Either way, it's obviously a problem with the mask. You can use GDI+ to draw transparent images and specify a *range* for red, green and blue to be transparent. Otherwise you could iterate through the bits and change any color within a range to be the mask color.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
I'm not using MFC, and I'm storing bitmaps inside my own button classes, which encapsulate the HWND of the button. If I respond to the WM_DRAWITEM message, and draw my buttons, they flicker like crazy if the window is being resized ( and they are moved ). The ones that stay put also flicker as they are redrawn.
I've been trying to get a wndproc happening to subclass the buttons, but that seems not to want to work. Does anyone have any other suggestions ?
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
Whenever your window is being resized, your main window is receiving a WM_ERASEBKGND message. This message by default erases all the controls on the window which then need to be redrawn. This is bad for flicker. One was around this would be to use the following routine to only fill in that windows area by excluding the areas of the controls on the window so they are not erased:
int dont_erase_indexes[] =
{
IDC_DPAS_LAMP,
IDC_INSTRUMENT_TYPE,
IDC_LABEL1,
IDC_LABEL2,
IDC_DESTINATION,
IDC_CURRENT_STATUS,
IDC_LOG,
IDC_GRAPH,
IDC_DOWNLOAD_STATUS,
IDC_DOWNLOAD_PROGRESS,
ID_AUTO_LOAD,
IDC_UPLOAD_ASSAYS,
IDC_AUTO_UPLOAD,
IDC_BROWSE_FOR_FOLDER
} ;
BOOL CYourWindow::OnEraseBkgnd(CDC* pDC)
{
static int dont_erase_indexes[] =
{
IDC_DPAS_LAMP,
IDC_INSTRUMENT_TYPE,
IDC_LABEL1,
IDC_LABEL2,
IDC_DESTINATION,
IDC_CURRENT_STATUS,
IDC_LOG,
IDC_GRAPH,
IDC_DOWNLOAD_STATUS,
IDC_DOWNLOAD_PROGRESS,
ID_AUTO_LOAD,
IDC_UPLOAD_ASSAYS,
IDC_AUTO_UPLOAD,
IDC_BROWSE_FOR_FOLDER
} ;
CRect clip ;
pDC->SaveDC() ;
for (int i = 0 ; i < sizeof(dont_erase_indexes) / sizeof(int) ; i++)
{
GetDlgItem(dont_erase_indexes[i])->GetWindowRect(&clip);
ScreenToClient(&clip);
pDC->ExcludeClipRect(&clip);
}
pDC->GetClipBox(&clip);
pDC->FillSolidRect(clip, GetSysColor(COLOR_BTNFACE));
pDC->RestoreDC(-1) ;
return FALSE;
}
Hope this helps out
Roger Bin Allen
|
|
|
|
|
Hey, cool. I did not know about this stuff, thank you *very* much.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
Hello fellow CPians. Happy New Year!
On my break from school, I thought I'd torture myself be reading Charles Petzold's Programming Windows. It's actually been a great read until now.
One of the sample programs declares a PMSG variable. The code goes on to allocate enough memory to store the appropriate amount of space using;
pmsg = malloc (cLinesMax * sizeof (MSG));
This code does not compile is VC6, SP5. I get the following error;
error C2440: '=' : cannot convert from 'void *' to 'struct tagMSG *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
I've tried casting the return value to PMSG which solve the compile problem but the program bombs! I'm in way over my head on this one...
Any help that anyone can provide is greatly appreciated.
Sorry for the size of the post, but here's the complete code.
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT("KeyView1");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.lpszMenuName = NULL;
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszClassName = szAppName;
if (!RegisterClass (&wndclass))
{
MessageBox(NULL, TEXT("This application requires WinNT to run."),
szAppName, MB_ICONERROR);
return 0;
}
hwnd = CreateWindow(szAppName, TEXT("Keyboard Message Viewer #1"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
static int cxClientMax, cyClientMax;
static int cxClient, cyClient;
static int cxChar, cyChar;
static int cLinesMax, cLines;
static PMSG pmsg;
static RECT rectScroll;
static TCHAR szTop[] = TEXT("Message Key Char ")
TEXT(" Repeat Scan Ext ALT Prev Tran");
static TCHAR szUnd[] = TEXT("------- --- ---- ")
TEXT(" ------ ---- --- --- ---- ----");
static TCHAR* szFormat[2] = {
TEXT("%-13s %3d %-15s%c%6u %4d %3s %3s %4s %4s"),
TEXT("%-13s 0x%04x%1s%c %6u %4d %3s %3s %4s %4s") };
static TCHAR* szYes = TEXT("Yes");
static TCHAR* szNo = TEXT("No");
static TCHAR* szDown = TEXT("Down");
static TCHAR* szUp = TEXT("Up");
static TCHAR* szMessage[] = {TEXT("WM_KEYDOWN"), TEXT("WM_KEYUP"),
TEXT("WM_CHAR"), TEXT("WM_DEADCHAR"),
TEXT("WM_SYSKEYDOWN"), TEXT("WM_SYSKEYUP"),
TEXT("WM_SYSCHAR"), TEXT("WM_SYSDEADCHAR") };
HDC hdc;
int i, iType;
PAINTSTRUCT ps;
TCHAR szBuffer[128], szKeyName[32];
TEXTMETRIC tm;
switch (message)
{
case WM_CREATE:
case WM_DISPLAYCHANGE:
cxClientMax = GetSystemMetrics(SM_CXMAXIMIZED);
cyClientMax = GetSystemMetrics(SM_CYMAXIMIZED);
hdc = GetDC(hwnd);
SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
GetTextMetrics(hdc, &tm);
cxChar = tm.tmAveCharWidth;
cyChar = tm.tmHeight;
ReleaseDC(hwnd, hdc);
if (pmsg)
free (pmsg);
cLinesMax = cyClientMax / cyChar;
pmsg = malloc (cLinesMax * sizeof (MSG));
cLines = 0;
case WM_SIZE:
if (message == WM_SIZE)
{
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
}
rectScroll.left = 0;
rectScroll.right = cxClient;
rectScroll.top = cyChar;
rectScroll.bottom = cyChar * (cyClient / cyChar);
InvalidateRect(hwnd, NULL, TRUE);
return 0;
case WM_KEYDOWN:
case WM_KEYUP:
case WM_CHAR:
case WM_DEADCHAR:
case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
case WM_SYSCHAR:
case WM_SYSDEADCHAR:
for (i = cLinesMax - 1; i > 0; i--)
{
pmsg[i] = pmsg[i - 1];
}
pmsg[0].hwnd = hwnd;
pmsg[0].message = message;
pmsg[0].wParam = wParam;
pmsg[0].lParam = lParam;
cLines = min(cLines + 1, cLinesMax);
ScrollWindow(hwnd, 0, -cyChar, &rectScroll, &rectScroll);
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
SelectObject(hdc, GetStockObject(SYSTEM_FIXED_FONT));
SetBkMode(hdc, TRANSPARENT);
TextOut(hdc, 0, 0, szTop, lstrlen(szTop));
TextOut(hdc, 0, 10, szUnd, lstrlen(szUnd));
for (i = 0; i < min(cLines, cyClient / cyChar - 1); i++)
{
iType = pmsg[i].message == WM_CHAR ||
pmsg[i].message == WM_SYSCHAR ||
pmsg[i].message == WM_DEADCHAR ||
pmsg[i].message == WM_SYSDEADCHAR;
GetKeyNameText(pmsg[i].lParam, szKeyName, sizeof(szKeyName) / sizeof(TCHAR));
TextOut(hdc, 0, (cyClient / cyChar - 1 - i) * cyChar, szBuffer,
wsprintf(szBuffer, szFormat[iType],
szMessage[pmsg[i].message - WM_KEYFIRST],
(PSTR) (iType ? TEXT(" ") : szKeyName),
(TCHAR) (iType ? pmsg[i].wParam : ' '),
LOWORD (pmsg[i].lParam),
HIWORD (pmsg[i].lParam) & 0xFF,
0x10000000 & pmsg[i].lParam ? szYes : szNo,
0x20000000 & pmsg[i].lParam ? szYes : szNo,
0x40000000 & pmsg[i].lParam ? szDown : szUp,
0x80000000 & pmsg[i].lParam ? szUp : szDown));
}
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
Paul Lyons
Do not go where the path may lead, go instead where there is no path and leave a trail.
- Ralph Waldo Emerson
|
|
|
|
|
I dunno what are you trying to say, man. I didn't read all the code, get bored.
But. The malloc() function returns void* , it is known and it is ok. You should cast the return value to whatever you want like this:
pmsg = (MSG*)malloc (cLinesMax * sizeof (MSG));
That's all. No buzzz It will elliminate the error you got
Philip Patrick
"Two beer or not two beer?" <shakesbeer>
Web-site: www.saintopatrick.com
|
|
|
|
|
malloc function returns void * type. You should make type casting if you want to use malloc. For example;
pmsg = (tagMSG*)malloc(cLinesMax * sizeof (MSG));
|
|
|
|
|
Oh my bad, lol, just read it all
What error you are getting?
Try to go in debugger step by step to see if your i is in boundaries. Also look on the pmsg array in debugger, i mean on all of its members, if they are initialized
Philip Patrick
"Two beer or not two beer?" <shakesbeer>
Web-site: www.saintopatrick.com
|
|
|
|
|
I'm creating an owner drawn menu derived from CMenu. Some of the menu items will be pop up menu items that have other menus pop up when you highlight them (of course). My owner drawn menu is going to custom draw an arrow signifying that it is a pop up menu, just like Windows does. The problem is that Windows still draws the original arrow on my menu items whenever it is a pop up item. Does anyone know how to remove this default drawing of pop up menu item arrows?
~Andrew Clark
|
|
|
|
|
Hi,
I am programming a multithreaded application however I am having lots of difficulties this week. I programmed many multithreaded applications but in this program I am really stucked. There is a main View class (say CMyView). This class have a CTaskManager class, which controls all the threads. The threads are called CTaskThread. Each CTaskThread need to call methods of CTaskManager. Here is the problematic part of the code:
class CTaskManager
{
public:
CTaskManager ();
virtual ~CTaskManager ();
protected:
CString m_sSharedVars [MAX_VARS];
...
};
void CTaskManager::ReplaceVariables (CString &str)
{
for (int i = 0 ; i < MAX_VARS ; i++)
{
if (m_sSharedVarNames [i] != m_sSharedVars [i])
{
while (str.Replace (m_sSharedVarNames [i], m_sSharedVars [i]) != 0);
}
}
}
When I run the program, it crashes at line m_sSharedVarNames [i] != m_sSharedVars [i] . In fact, it crashes whenever it tries to acces the elements of CTaskManager. However, when I remove the definition CString m_sSharedVars [MAX_VARS]; from the class and write it to the beginning of the CPP file (i.e. make it global), the program works fine. But the problem is that, I have to access other variables of CTaskManager, and I cannot make all of them global. The error message is the following:
<br />
The intruction at "0x5f47714c" referenced memeory at "0xcdcdcde1". The memory could not be "read". <br />
Click on OK to terminate the program<br />
Click on Cancel to debug the program<br />
When I click on Cancel and debug the program, it jumps to the following line in AFX.INL
<br />
_AFX_INLINE CString::operator LPCTSTR() const<br />
{ return m_pchData; }<br />
The error is
<br />
Unhandled exception in MyProgram.exe (MFC42D.DLL):0xC0000005:Access Violation<br />
Please HELP. I am stucked and I dont know what to do. I tried to use CCriticalSection to protect the data to be read/written by more than one threads at the same time but it didnt worked. In fact, when I run only one thread, the program crashes again!
Kind regards
Mustafa Demirhan
http://www.macroangel.com
Sonork ID 100.9935:zoltrix
|
|
|
|
|
I create the threads as follows (may help):
bool CTaskManager::LaunchTask (const CString &sTaskName, const CString &sTaskFolder)
{
CTaskObject *pTask = FindTask (sTaskName, sTaskFolder);
if (pTask)
{
if (pTask->m_bRunning)
return true;
pTask->m_bRunning = true;
CTaskThread *pThread = new CTaskThread ();
pThread->m_pTaskObject = pTask;
pThread->m_pTaskManager = this;
AddTaskThread (pThread);
pThread->CreateThread ();
return true;
}
else
return false;
return true;
}
Thanks for any helps.
Kind regards
Mustafa Demirhan
http://www.macroangel.com
Sonork ID 100.9935:zoltrix
|
|
|
|
|
1.Try init the m_sSharedVars[MAX_VARS] first before operations.
2.Or maybe an error occurs internally of CString in String-Length.
I Guess. I would try.
|
|
|
|
|