|
So maybe problem is of file did you check it?
|
|
|
|
|
LiYS wrote: sa
LiYS wrote: You can alo use of CFile::Read
Use ShareDenyNone Flag!
|
|
|
|
|
Hello everyone,
Is there a way that a software interrupts be programmed in windows. I need to run a timer routine that sends an interrupt every 20 ms. I have tried using
Sleep(20) ---> Not deterministic
GetTickCount ---> Determinitic up to 100ms
QueryPerformanceCounter ---> Gives a good result.
But I am looking to see if there is some way that within windows scheduler or elsewhere itself a timer interrupt could be programmed.
Thank you,
Best regards,
Suraj.
|
|
|
|
|
Interrupts are handled in kernel mode, not user mode. Windows in a preemptive multitasking OS not a real-time OS; if you need super accurate timing you could be in for problems.
Steve
|
|
|
|
|
Hello,
I don't need perfect accuracy. But was wondering on only that if there are interrupts that can be set within my program so that the 20 ms time can be detected. Or is there is way in which any inbuilt timer (in windows) can be set so that it counts down and sends a trigger to the windows scheduler.
Thanks.
Suraj.
|
|
|
|
|
SetTimer(hwnd, 100, 100, NULL);
...OnTimer(...)
{
AfxMessageBox("");
}
why it can popup some messgebox, it look like a Multi-Thread...?
|
|
|
|
|
mfc_dialog wrote: why it can popup some messgebox, it look like a Multi-Thread...?
What are you asking?
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
INT g_nData;<br />
<br />
SetTimer(hwnd, 100, 100, NULL);<br />
<br />
...OnTimer(...)<br />
{<br />
if (g_nData > 0)<br />
{<br />
g_nData--;<br />
}<br />
else<br />
{<br />
g_nData++;<br />
}<br />
}
g_nData will not happen "Memory access errors"?unneed use ::EnterCriticalSection() and ::LeaveCriticalSection()?
|
|
|
|
|
Again, cant understand your question. By the way, you have mentioned last parameter of SetTimer as NULL . That means, there will be no timerproc associated with this timer.
|
|
|
|
|
mfc_dialog wrote: SetTimer(hwnd, 100, 100, NULL)
You didn't provide any timer functon for the timer 100.
So it will call default OnTimer(nEventID)...
I think you are using some other Timers too..
do your calculations by checking the Event ID parameter...
Hope this will help...
Do your Duty and Don't expect the Result
|
|
|
|
|
You may want to initialize g_nData:
INT g_nData = 0;
The timer messages should arrive on the same thread so you shouldn't need ::EnterCriticalSection()
and ::LeaveCriticalSection().
Are you getting errors at runtime?
Mark
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
i have used the GlobalMemoryStatus(), but is can not renturn a process's physical memory number.
can any one tell me?thanks!
|
|
|
|
|
|
I use MFC SDI in vs 2005.
I have a problem to print bitmap on my printer. It's works on OnFilePrintPreview() but not on the OnFilePrint()
I try with createcompatiblebitmap but i have a crash.
My code:
My printer is selected here, i have a pDC with m_hDC unused.
void MyView::OnPrint(CDC *pDC, CPrintInfo *pInfo)
{
CBitmap bmp;
if (bmp.LoadBitmap(IDB_BITMAP_1))
{
BITMAP bmpInfo;
bmp.GetBitmap(&bmpInfo);
CDC dcMemory;
BOOL result;
result=dcMemory.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp);
result=pDC->BitBlt(x, y, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory,
0, 0, SRCCOPY );
dcMemory.SelectObject(pOldBitmap);
}
}
thanks
|
|
|
|
|
What do you mean by crash? Assertion error? BSOD?
Is pDC valid or NULL?
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
the pDC is valid because print text and line works correctly, i have only a assert error on:
...
dcMemory.CreateCompatibleDC(pDC);
bmp.CreateCompatibleBitmap(&dcMemory,bmpInfo.bmWidth,bmpInfo.bmHeight);
...
but the handle of pDC is unused
i have assert error here when i try CreateCompatibleBitmap(ASSERT on the dcMemory):
BOOL CGdiObject::Attach(HGDIOBJ hObject)
{
ASSERT(m_hObject == NULL);
...
}
|
|
|
|
|
I think your maybe your problem is of bmp.Load();(your answer to my reply)
|
|
|
|
|
You said createcompatiblebitmap has a problem but where you used it? and whats error?
|
|
|
|
|
the error come from ASSERT on the handle of the pDC in this function:
BOOL CGdiObject::Attach(HGDIOBJ hObject)
{
ASSERT(m_hObject == NULL);
...
}
i try CreateCompatibleBitmap :
void MyView::OnPrint(CDC *pDC, CPrintInfo *pInfo)
{
CBitmap bmp;
if (bmp.LoadBitmap(IDB_BITMAP_1))
{
BITMAP bmpInfo;
bmp.GetBitmap(&bmpInfo);
CDC dcMemory;
BOOL result;
result=dcMemory.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp);
bmp.CreateCompatibleBitmap(&dcMemory,bmpInfo.bmWidth,bmpInfo.bmHeight);
result=pDC->BitBlt(x, y, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory,
0, 0, SRCCOPY );
dcMemory.SelectObject(pOldBitmap);
}
}
|
|
|
|
|
jerome_data wrote: bmp.CreateCompatibleBitmap(&dcMemory,bmpInfo.bmWidth,bmpInfo.bmHeight);
CreateCompatibleBitmap initializes a bitmap compatible to mentioned DC.
In your case, its already initialized. Thats why assert is there. Comment this line, as it is not required.
|
|
|
|
|
Good eye
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
Thanks !
But, seems like OP is not interested to reply back, once his problem is known.
|
|
|
|
|
You assign IDB_BITMAP_1 to bmp object and then create a another bitmap you can before CreateCompatibleBitmap use of bmp.detach() and create your bitmap
|
|
|
|
|
Used this code to print a bitmap on printer and display
void YourClass::PrintBitmap(CDC *pDC, CPrintInfo *pInfo,UINT Bitmap,int x,int y)
{
LPBITMAPINFO info; // Structure for storing the DIB information,
// it will be used by 'StretchDIBits()'
HBITMAP hbit; // Handle to the bitmap to print
BITMAP bm; // Structure used for obtaining information
// about the bitmap (size, color depth...)
int nColors = 0; // Used to store the number of colors the DIB has
int sizeinfo = 0; // Will contain the size of info
RGBQUAD rgb[256]; // Used to store the DIB color table
// The following line loads the bitmap from resource bitmap
hbit = (HBITMAP) LoadImage(AfxGetInstanceHandle(),
MAKEINTRESOURCE(Bitmap),
IMAGE_BITMAP,
0,
0,
LR_CREATEDIBSECTION);
// Obtain information about 'hbit' and store it in 'bm'
GetObject(hbit, sizeof(BITMAP), (LPVOID) &bm);
nColors = (1 << bm.bmBitsPixel);
if(nColors > 256)
nColors=0; // This is when DIB is 24 bit.
// In this case there is not any color table information
// Now we need to know how much size we have to give for storing "info" in memory.
// This involves the proper BITMAPINFO size and the color table size.
// Color table is only needed when the DIB has 256 colors or less.
sizeinfo = sizeof(BITMAPINFO) + (nColors * sizeof(RGBQUAD)); // This is the size required
info = (LPBITMAPINFO) malloc(sizeinfo); // Storing info in memory
// Before 'StretchDIBits()' we have to fill some "info" fields.
// This information was stored in 'bm'.
info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
info->bmiHeader.biWidth = bm.bmWidth;
info->bmiHeader.biHeight = bm.bmHeight;
info->bmiHeader.biPlanes = 1;
info->bmiHeader.biBitCount = bm.bmBitsPixel * bm.bmPlanes;
info->bmiHeader.biCompression = BI_RGB;
info->bmiHeader.biSizeImage = bm.bmWidthBytes * bm.bmHeight;
info->bmiHeader.biXPelsPerMeter = 0;
info->bmiHeader.biYPelsPerMeter = 0;
info->bmiHeader.biClrUsed = 0;
info->bmiHeader.biClrImportant = 0;
// If the bitmap is a compressed bitmap (BI_RLE for example), the 'biSizeImage' can not
// be calculated that way. A call to 'GetDIBits()' will fill the 'biSizeImage' field with
// the correct size.
// Now for 256 or less color DIB we have to fill the "info" color table parameter
if(nColors <= 256)
{
HBITMAP hOldBitmap;
HDC hMemDC = CreateCompatibleDC(NULL); // Creating an auxiliary device context
hOldBitmap = (HBITMAP) SelectObject(hMemDC, hbit); // Select 'hbit' in 'it'
GetDIBColorTable(hMemDC, 0, nColors, rgb); // Obtaining the color table information
// Now we pass this color information to "info"
for(int iCnt = 0; iCnt < nColors; ++iCnt)
{
info->bmiColors[iCnt].rgbRed = rgb[iCnt].rgbRed;
info->bmiColors[iCnt].rgbGreen = rgb[iCnt].rgbGreen;
info->bmiColors[iCnt].rgbBlue = rgb[iCnt].rgbBlue;
}
SelectObject(hMemDC, hOldBitmap);
DeleteDC(hMemDC);
}
// Let's get 'StretchDIBiting'! 'pDC' is the printer DC
HDC hdc = pDC->GetSafeHdc(); // Getting a safe handle
// Stretching all the bitmap on a destination rectangle of size (size_x, size_y)
// and upper left corner at (initial_pos_x, initial_pos_y)
StretchDIBits(hdc,
x,
y,
bm.bmWidth,
bm.bmHeight,
0,
0,
bm.bmWidth,
bm.bmHeight,
bm.bmBits,
info,
DIB_RGB_COLORS,
SRCCOPY);
// This mode, DIB_RGB_COLORS indicate the color table are pure RGB values
// The mode DIB_PAL_COLORS indicate the color table items are index to the local palette items
DeleteObject(hbit);
free(info)
}
|
|
|
|
|
There are three list which include objects of my classes.(car,bus,lorry) All the objects have an unique id number. I want to find the object which has a id that has given as parameter. (as using template method of c++)
For example
my classes are;
class car{
string colour1;
int id;
int weight1;
}
class bus{
string colour2;
int id;
int weight2;
}
class lorry{
string colour3;
int id;
int weight3;
}
Is it necessary to write same names of the variables (id) to apply template method to my application?
Thanks.
|
|
|
|
|