|
knowing that you know makes me happy
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
MFC uses CDC wrapper to handle device contexts as a wrapper for most sorts of images
there are no facts, only interpretations
|
|
|
|
|
Hi All,
Can anybody please tell me how to determine which disk is the boot disk ie the disk by which the system boot took place using mfc.
Regards
Abinash
|
|
|
|
|
"GetWindowsDirectory()" provides the path where windows is installed. From path you can retrive the drive letter (first character of the path). Through the drive letter you find out the physical drive number of the disk by using DeviceIOControl() and IOCTL_STORAGE_GET_DEVICE_NUMBER
|
|
|
|
|
It's a Win32 FAQ (on Win32 ng[^] , system, since 1995 )
|
|
|
|
|
MFC, STUDIO'2008, WINDOWS'XP 2003
#include <float.h>
_controlfp(_DN_FLUSH, _MCW_DN); // : error C3861: '__controlfp': identifier not found
// Denormal values flushed to zero by hardware on ALPHA and x86
// processors with SSE2 support. Ignored on other x86 platforms.
below some variants:
//+-1 _controlfp(0, MCW_EM);
<float.h>
// below following line is incorrect - don't display MessageBox(L"1\nDIVIDE BY ZERO");
_controlfp(_DN_FLUSH, _MCW_DN);
_controlfp(0, _MCW_DN);
_controlfp(_DN_SAVE, _MCW_DN);
_controlfp(0, _MCW_DN);
int err;
double fResult; // Bennet, pg.136
double x,y;
x = 5.0;
y = 0.0;
_try
{
fResult = x/y;
// _control87_2(0, 0,&fResult, 0);
//- _controlfp(0, 0,&fResult, 0); // : error C2660: '_controlfp' : function does not take 4 arguments
//- _controlfp(&fResult, 0); // : error C2664: '_controlfp' : cannot convert parameter 1 from 'float *' to 'unsigned int'
}
_except (GetExceptionCode() == EXCEPTION_FLT_DIVIDE_BY_ZERO)
{
MessageBox(L"1\nDIVIDE BY ZERO");
MessageBox(_T("2\nDIVIDE BY ZERO"));
AfxMessageBox(_T("3\nDIVIDE BY ZERO"));
}
|
|
|
|
|
And the question is?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Why don't exec
MessageBox(L"1\nDIVIDE BY ZERO");
|
|
|
|
|
The following code works fine on my system
#include "Excpt.h"
#include <Windows.h>
#include "cmath"
#include <float.h>
void main()
{
_controlfp(0, MCW_EM);
float fResult;
float x,y;
x = 5.0;
y = 0.0;
_try
{
fResult = x/y;
}
_except (GetExceptionCode() == EXCEPTION_FLT_DIVIDE_BY_ZERO)
{
MessageBox(NULL, L"DIVIDE BY ZERO", L"", MB_OK);
}
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
hi all
How to retrieve the all drives in a computer and their size or their starting and end Sector using VC++ Code
|
|
|
|
|
Shiv Murti Pal wrote: How to retrieve the all drives in a computer
this might help!
MFS System Utility[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
To get the list of available drives, use GetLogicalDrives() . To get their size, use GetDiskFreeSpace() .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
And see System Information Utility[^].
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Hi everyone!
I am trying to convert a HDC to Bitmap so that I can have a final picture of all bitmap components. Basically in my code what I do is that I have a bitmap at the background then I add other small bitmaps on top of the main bitmap, thus my final goal is to have a "screenshot" such that it is sort of a bitmap containing all other added bitmaps.
However, for some reason the final bitmap comes out in black. Please I need help and suggestions.
The piece of code is the following(in bold is the part of the code to get the final bitmap, which is almost at the end of the code):
void CSpeedoMeter::OnPaint()
{
CPaintDC dc(this);
//HDC thisDC = CreateDC("Desktop", NULL, NULL, NULL);
HDC thisDC = dc.GetSafeHdc();
HDC hdcMem;
//
// Create a compatible DC.
//
hdcMem = CreateCompatibleDC(NULL);
int seconds2 = 300;
int seconds = 3600;
//clock_t endwait = 0;
//if(saveState == true)
{
//getting the number of CumVend from database
//tempDay = ConnectDBFast();
//tempDay = 42000;
//tempWeek = tempDay + ConnectDBWeek(hdcMem);
//tempMonth = tempDay + ConnectDBMonth();
//tempMonth = 7878996;
//tempYear = tempDay + ConnectDBYear();
//tempYear = 7334554;
saveState = false;
//endwait = 0;
endwait = clock() + seconds * CLOCKS_PER_SEC;
//SetCursor(LoadCursor(NULL,IDC_WAIT));
}
if(saveStateFast == true)
{
//getting the number of CumVend from database
//tempDay = ConnectDBFast();
saveStateFast = false;
endwait2 = clock() + seconds2 * CLOCKS_PER_SEC;
}
//
// Get the size of the client rectangle.
//
RECT rc;
GetClientRect(&rc);
//ndh = rc.right - rc.left;
//ndv = rc.bottom - rc.top;
ndh = rc.right - rc.left - 845;
ndv = rc.bottom - rc.top - 140;
C.x = ndh/2;
C.y = ndv/2;
if(ndh > ndv)
needlelength = (int)(ndv/2.5f);
else
needlelength = (int)(ndh/2.5f);
//needlepos.x = ndh/2;
//needlepos.y = ndv/2 + needlelength;
needlepos.x = ndh/2;
needlepos.y = ndv/2 + needlelength - 190;
HBITMAP hBitmap = (HBITMAP)::LoadImage(AfxGetInstanceHandle(), "C:\\Speedometer\\res\\speedometer6.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
GetObject(hBitmap, sizeof(bitmap), &bitmap);
SelectObject(hdcMem, hBitmap);
SetNeedleColor(RGB(255, 126, 45));
// draw needle
DrawNeedle((int)tempDay, &dc, needlecolor, hdcMem);
// draw font
HFONT hfont, holdfont;
hfont = CreateFontIndirect(&lf);
holdfont = (HFONT) SelectObject(hdcMem, hfont);
//******************************* CODE TO DRAW NUMBERS FOR DAILY SELLS **********************************
RECT fntRc;
fntRc.left = 815;
fntRc.right = 1000;
fntRc.top = 830;
fntRc.bottom = 1080;
//tempDay = 0;
char numm1[20];
string strTotalDay = "";
strTotalDay = itoa(tempDay, numm1, 10);
//int ll = strTotalMonth.length();
string back1 = strTotalDay;
for(int b=0; b < strTotalDay.length(); b++)
{
back1[b] = strTotalDay[strTotalDay.length()-1-b];
}
strTotalDay = back1;
for(int b=0; b < strTotalDay.length(); b++)
{
if(b != 0)
{
//RECT fntRc1;
fntRc.left -= 55;
fntRc.right -= 55;
}
drawNumbers(hdcMem, &dc, fntRc, strTotalDay[b]);
}
////////////////////////////////////////////////////////////////////////////////////////////////
//******************************* CODE TO DRAW NUMBERS FOR WEEKLY SELLS **********************************
RECT fntRc4;
fntRc4.left = 1683;
fntRc4.right = 1868;
fntRc4.top = 150;
fntRc4.bottom = 400;
//tempWeek = 17;
char numm[20];
string strTotalWeek = "";
strTotalWeek = itoa(tempWeek, numm, 10);
//int ll = strTotalMonth.length();
string back4 = strTotalWeek;
for(int b=0; b < strTotalWeek.length(); b++)
{
back4[b] = strTotalWeek[strTotalWeek.length()-1-b];
}
strTotalWeek = back4;
for(int b=0; b < strTotalWeek.length(); b++)
{
if(b != 0)
{
//RECT fntRc1;
fntRc4.left -= 55;
fntRc4.right -= 55;
}
drawNumbers(hdcMem, &dc, fntRc4, strTotalWeek[b]);
}
////////////////////////////////////////////////////////////////////////////////////////////////
//******************************* CODE TO DRAW NUMBERS FOR MONTHLY SELLS **********************************
RECT fntRc1;
fntRc1.left = 1683;
fntRc1.right = 1868;
fntRc1.top = 380;
fntRc1.bottom = 630;
//tempMonth = 11111111;
string strTotalMonth = "";
stringstream ss;
ss << tempMonth;
strTotalMonth = ss.str();
//TextOutA(hdcMem,5,5, strTotalMonth.c_str(),20);
string back = strTotalMonth;
for(int b=0; b < strTotalMonth.length(); b++)
{
back[b] = strTotalMonth[strTotalMonth.length()-1-b];
}
strTotalMonth = back;
for(int b=0; b < strTotalMonth.length(); b++)
{
if(b != 0)
{
//RECT fntRc1;
fntRc1.left -= 55;
fntRc1.right -= 55;
}
drawNumbers(hdcMem, &dc, fntRc1, strTotalMonth[b]);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
//******************************* CODE TO DRAW NUMBERS FOR YEARLY SELLS **********************************
RECT fntRc3;
fntRc3.left = 1683;
fntRc3.right = 1868;
fntRc3.top = 610;
fntRc3.bottom = 860;
//tempYear = 15556;
char numm2[20];
string strTotalYear = "";
strTotalYear = itoa(tempYear, numm2, 10);
string back2 = strTotalYear;
for(int b=0; b < strTotalYear.length(); b++)
{
back2[b] = strTotalYear[strTotalYear.length()-1-b];
}
strTotalYear = back2;
for(int b=0; b < strTotalYear.length(); b++)
{
if(b != 0)
{
//RECT fntRc1;
fntRc3.left -= 55;
fntRc3.right -= 55;
}
drawNumbers(hdcMem, &dc, fntRc3, strTotalYear[b]);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//HWND window;
const char* filename = "res\\speedomoterSCREEN.bmp";
// get screen rectangle
//GetWindowRect(&rc);
// bitmap dimensions
int bitmap_dx = rc.right - rc.left;
int bitmap_dy = rc.bottom - rc.top;
// create file
ofstream file(filename, ios::binary);
if(!file) return;
// save bitmap file headers
BITMAPFILEHEADER fileHeader;
BITMAPINFOHEADER infoHeader;
fileHeader.bfType = 0x4d42;
fileHeader.bfSize = 0;
fileHeader.bfReserved1 = 0;
fileHeader.bfReserved2 = 0;
fileHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
infoHeader.biSize = sizeof(infoHeader);
infoHeader.biWidth = bitmap_dx;
infoHeader.biHeight = bitmap_dy;
infoHeader.biPlanes = 1;
infoHeader.biBitCount = 24;
infoHeader.biCompression = BI_RGB;
infoHeader.biSizeImage = 0;
infoHeader.biXPelsPerMeter = 0;
infoHeader.biYPelsPerMeter = 0;
infoHeader.biClrUsed = 0;
infoHeader.biClrImportant = 0;
file.write((char*)&fileHeader, sizeof(fileHeader));
file.write((char*)&infoHeader, sizeof(infoHeader));
// dibsection information
BITMAPINFO info;
info.bmiHeader = infoHeader;
// ------------------
// THE IMPORTANT CODE
// ------------------
// create a dibsection and blit the window contents to the bitmap
//HDC winDC = GetWindowDC(window);
HDC memDC = CreateCompatibleDC(NULL);
BYTE *memory = 0;
HBITMAP bitmap = CreateDIBSection(hdcMem, &info, DIB_RGB_COLORS, (void**)&memory, 0, 0);
SelectObject(memDC, bitmap);
BitBlt(thisDC, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, hdcMem, 0, 0,SRCCOPY);
DeleteDC(memDC);
//ReleaseDC(window, winDC);
const char *memory1 = (char*)memory;
// save dibsection data
int bytes = (((24*bitmap_dx + 31) & (~31))/8)*bitmap_dy;
file.write(memory1, bytes);
DeleteObject(bitmap);
//DeleteObject(font1);
DeleteObject(hfont);
DeleteObject(holdfont);
DeleteObject(hBitmap);
DeleteDC(hdcMem);
DeleteDC(thisDC);
if(clock() >= endwait)
{
saveState = true;
}
if(clock() >= endwait2)
{
saveStateFast = true;
}
Invalidate();
}
|
|
|
|
|
LuisFilipeSa wrote: BitBlt(thisDC, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, hdcMem, 0, 0,SRCCOPY);
It looks like (BTW your code appears a bit involute...) you're bit-blitting in the wrong direction, i.e. memory->screen instead of screen->memory.
Please, use the code block button for posting code snippets.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Yes but when bit-blitting in that direction it works fine, this is, the final bitmap is displayed properly on the screen. But when I try to copy that bitmap to a bitmap file it does not work.
That piece of code that you copied on your reply is working fine, this is:
BitBlt(thisDC, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, hdcMem, 0, 0,SRCCOPY);
The problem is within the code in bold that I posted before.
The rest of the code which is not in bold works perfectly.
Any more advice please?
Thank you.
|
|
|
|
|
You need to blit into the opposite direction if you wish to save correctly the bitmap content into the array.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I do understand now what you are saying, but i am a bit lost, don't know what to do next.
So I have blitted into "thisDC" variable according to my code, then next I have:
CreateDIBSection(hdcMem, &info, DIB_RGB_COLORS, (void**)memory, 0, 0);
Then I thought that by doing the above code everything would go to "memory" variable.
What should I do next? Can you give me an example or help me out please.
Thank you.
|
|
|
|
|
I'm updating an OleDb application. I didn't write the original logic however it closely resembles the OleDb samples provided by Microsoft. It uses the standard IDBInitialize, IDBCreateSession, IDBCreateCommand and ICommandText interfaces to call a stored procedure, returning an IRowset instance. The ICommandWithParams interface is used to set parameter information for the stored procedures and IID_IAccessor to create bindings for the buffer to hold the returned data. ie. fairly standard OleDb code, as noted virtually identical to the samples provided by Microsoft. It works well and has done for a while. Currently the Rowsets are all forward only. All the update requires is that the Rowsets support being able to scroll through the data more than once. According to the documentation this is done by creating an instance of the ICommandProperties interface, filling some DBPROP structures and calling ICommandProperties::SetProperties. However when I do this I get an error on ICommandText::Execute. If I subsequently call ICommandProperties::GetProperties with the guidPropertySet of an DBPROPIDSET struct set to DBPROPSET_PROPERTIESINERROR it tells me that the properties I've set are invalid. This happened regardless of the properties I attempted to set. Out of curiosity I created a test application that ran a select command rather than calling a stored procedure. This ran perfectly. When I switched the logic so that it called a parameter-less stored procedure that returned the exact same data I got the errors again, suggesting that there is something different you need to do for stored procedures. However this is old technology now and I can't find any information (as well as being something of an OleDb noob!)
Any help much appreciated.
|
|
|
|
|
Hi,
I created a tracking tooltip which works fine on Windows XP without a manifest, the tooltip is using TTF_TRACK and TTF_TRANSPARENT tooltip flags. When I add a manifest the left mouse click still works as expected (control behind tooltip receives WM_LBUTTONDOWN ), but a double-click will not work (control behind the tooltip receives no WM_LBUTTONDBLCLK ). Also the dialog loses focus when double-clicking over the tooltip, I am guessing that the tooltip gets the focus.
I needed some time to rule out any other cause for this problem, confirmed that nobody else is stealing messages, it's just triggered by using a manifest in order to get XP Visual styles[^]. It looks like the tooltip implementation in ComCtl32.dll Version 6 is different and double-click mouse events are not forwarded to the parent window. Anyone has an idea how to fix this problem? Thanks!
Here is my code to create the tooltip:
m_hTooltip = ::CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
m_hWnd, NULL, NULL, NULL);
if(m_hTooltip)
{
TOOLINFO ti;
memset(&ti, 0, sizeof(ti));
ti.cbSize = sizeof(ti);
ti.uFlags = TTF_TRACK | TTF_ABSOLUTE | TTF_TRANSPARENT | TTF_IDISHWND;
ti.hwnd = m_hWnd;
ti.uId = (UINT)m_hTooltip;
::SendMessage(m_hTooltip, TTM_ADDTOOL, 0, (LPARAM)&ti);
}
And then later to enable/disable the tooltip:
if(bEnable)
{
ti.lpszText = (LPTSTR)pText;
::SendMessage(m_hTooltip, TTM_UPDATETIPTEXT, 0, (LPARAM) &ti);
::SendMessage(m_hTooltip, TTM_TRACKPOSITION, 0, (LPARAM) MAKELONG(pRect->left, pRect->top));
::SendMessage(m_hTooltip, TTM_TRACKACTIVATE, TRUE, (LPARAM)&ti);
} else {
::SendMessage(m_hTooltip, TTM_TRACKACTIVATE, FALSE, (LPARAM)&ti);
}
|
|
|
|
|
Subclassing the tooltip control fixed the problem on Windows XP, found no other solution to get the transparency functionality with ComCtl32.dll version 6. Now it works both with or without manifest.
|
|
|
|
|
Hello people!
I wrote a little test application to experiment with GetThreadContext[^]. In this application, which is actually a dialog based application, i have 3 threads, the GUI thread, a thread that runs a few pointless loops and one that regularry enumerates the threads belonging to this process and calls GetThreadContext on each thread. In the enumeration i use CreateToolhelp32Snapshot[^] method and Thread32First[^]/Thread32Next[^] to get the thread IDs, then i use OpenThread[^] specifying the flag THREAD_GET_CONTEXT to gain the handle of the thread and then i feed GetThreadContext with this handle. In the CONTEXT struct i get the info in i give CONTEXT_CONTROL for the ContextFlags member, as found in winnt.h , to get the program counter (that's Eip , right?). And here comes the part i do not understand and require some help with. For each thread i am getting a different value in the Eip, that is understandable, since the 3 threads are executing different parts of the code, however, this value never seems to be changing in time, what i mean is, if i run my program and for a given thread i get -let's say- 12345678 for Eip, it will still be 12345678 in 10 secs, 15 secs, 1 minutes, it never seems to change. What i would expect is that this value keeps changing as the thread runs and executes different parts of the code. Btw all the rest of the registers i get if i specify CONTEXT_CONTROL behaves the same way. Can anyone explain me why and maybe give me a hint how i could actually get the program counter the correct way for the threads? (The point of this all is that i just want to see if i can detect deadlocked threads this way or not.)
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
I had an idea:
The values are only saved when the threads are switched, maybe the granularity is so big that it just doesn't switch often enough?
But that really wouldn't make sense, context switches happen often..
On an other note though, you can't reliably detect deadlocks this way unless you're allowed to make some assumptions about the code. For example if it's possible to get to the same address more than once (eg a loop) then you may be lucky enough to always catch it there (and it may really happen, if there is a place where it will always wait a while there is a pretty good chance that you'll catch it there), the chance that it could happen makes it unreliable.
And if it stays at a given address for a while, how long until you will declare it dead? What if it's just slow?
Actual detection is possible by constructing a wait-for graph.
note: I probably make mistakes instead of sense, I apologize in advance
|
|
|
|
|
I know that detecting endless loops can't be done this way (easily) but i was hoping that if a thread is sitting on a WaitForSingleObject or WaitForMultipleObjects call for example then its IP doesn't change much, true that i could get into a situation where the given thread isn't deadlocked, just runs into the same place quite often and it might happen that the "watcher thread" always finds it sitting there and will think it is dead...but all this is just an experiment for now to see what is possible and what is not.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Ok well then I can't help too much, I don't know why the values aren't updated more often, there is probably some arcane windows-specific reason that I'm not aware of
|
|
|
|
|