|
Dear Friends
My application doesn`t support 24bit color screen.it is wokring for all other options like 32 bit,256color etc.In 24 bit mode, I am getting garbled picture.
Kindly write to me how to solve it.
Thanking you.
Adarsh
|
|
|
|
|
When reading (or writing) through your bitmap data, you have to remember that each scan line is DWORD aligned. So when you reach the end of a scan line, you will have to realign your pointer to the next DWORD boundary. If you do not do this, you will get the garbage at the end of each scan line mixed into your data, causing the picture to appear messed up.
This code is from my PJAImage class and converts a 24bit bitmap to greyscale
else if (bm.bmBitsPixel == 24)
{
BYTE *dst=(BYTE*)pBits;
for (int dh = 0; dh < bm.bmHeight; dh++)
{
for (int dw = 0; dw < bm.bmWidth; dw++)
{
dst += 3;
}
int pos = (int)dst - (int)pBits;
int rem = pos % 4;
if (rem)
dst += 4 - rem;
}
} HTH
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Dear PJ Arends,
In my code they have not used any class.It`s in WinAPI, as I am doing customization.
My progrmacode is like this:
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
hmemdc = CreateCompatibleDC(hdc);
hBmp = CreateCompatibleBitmap(hdc, WND_WIDTH, WND_HEIGHT);
SelectObject(hmemdc, hBmp);
hmemdc1 = CreateCompatibleDC(hdc);
SelectObject(hmemdc1, hBmpBckgnd);
StretchBlt(
hmemdc,
0,
0,
WND_WIDTH,
WND_HEIGHT,
hmemdc1,
0,
0,
1,
1,
SRCCOPY);
DeleteDC(hmemdc1);
This code has problem with 24bit screen resolution.What is needed...
Kindly let me know...
Thanking You.
AD
|
|
|
|
|
Other than a resource leak (you do not restore hmemdc1 before you delete it) I see nothing here that would break when using 24bit colour and would work with other colour settings. The only thing I can think of is that the bBmpBckgnd bitmap is corrupted before it gets to this point.
Check out http://www.codeproject.com/tools/imageviewer.asp[^]. It is a tool that I wrote so that I could check out these types of things in my own code. You can use it to check out what is contained in all your memory device contexts and bitmaps at any point in your code.
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Hello!!
I have a program that shows a message box from a dll (in fact it's not a complete messagebox but a wnd that is a child of another window of my program).
When I call the function, I have a runtime error that says that the caling convention of the function from the dll is not corret. Here is the code:
In the program:
typedef void (WINAPI *SHOWTOOLDLG)(int, CRect,CWnd*);<br />
...<br />
...<br />
...<br />
void SomeDlgClass:OnSomeEvent()<br />
{ <br />
if (m_hToolDll)<br />
{<br />
SHOWTOOLDLG m_pShowDlg_Func = (SHOWTOOLDLG)GetProcAddress (m_hToolDll,"ShowToolDlg");<br />
if (m_pShowDlg_Func)<br />
m_pShowDlg_Func(0,ClientRect,this);<br />
}<br />
}<br />
in the dll:
extern "C" __declspec(dllexport) void ShowToolDlg(int ToolId, CRect Position,CWnd* pParent)<br />
{<br />
CToolConfDlg* Win;<br />
Win = new CToolConfDlg;<br />
Win->Create(IDD_EMPTYDLG,pParent);<br />
Win->ShowWindow(SW_SHOW);<br />
}
Could someone help me ??
Thanks!
|
|
|
|
|
1. Why extern "C" ?
2. If it is a regular DLL using MFC, you need to add:
AFX_MANAGE_STATE(AfxGetStaticModuleState());
at the beginning of your DLL-exported function.
Regards,
BB
|
|
|
|
|
After initializing the timer by:
SetTimer(ID_PLAYTIME_EVENT, 1000, NULL);
The following codes will result in exception: 0XC00000FD: stack overflow?
void CCPPPLAYERDlg::OnTimer (UINT nIDEvent)
{
MSG msg={0};
switch (nIDEvent) {
case ID_PLAYTIME_EVENT:
if(g_hwndMain)
{
// Main message loop
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg); DispatchMessage(&msg);
}
break;
}
CDialog::OnTimer(nIDEvent);
}
DJ
|
|
|
|
|
Don't put such a loop into a timer function. They were not designed to co-exist. The code you put into a timer function must be short, sweet and to the point, consuming as little CPU as possible.
|
|
|
|
|
If my brain is thinking right, if there are too many messages in the queue, this code will never finish and end up basically calling itself.
(I am baffled as to why you need to do a message look anyway.)
Finally, why use switch? Why not use if (nIDEvent == ID_PLAYTIME_EVENT)
|
|
|
|
|
After initializing the timer by:
SetTimer(ID_PLAYTIME_EVENT, 1000, NULL);
The following codes will result in exception: 0XC00000FD: stack overflow?
void CCPPPLAYERDlg::OnTimer (UINT nIDEvent)
{
MSG msg={0};
switch (nIDEvent) {
case ID_PLAYTIME_EVENT:
if(g_hwndMain)
{
// Main message loop
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg); DispatchMessage(&msg);
}
}
else
{
// AfxMessageBox(_T("Failed to create the main window!"));
}
break;
}
CDialog::OnTimer(nIDEvent);
}
DJ
|
|
|
|
|
Your implementation is not corectly!!
The return value of 'GetMessage' function can be:
zero - If the function retrieves the WM_QUIT message;
nonzero - If the function retrieves a message other than WM_QUIT;
-1 - If there is an error (ex. if hWnd is an invalid window handle or lpMsg is an invalid pointer).
In your function the 'GetMessage' returns nonzero always and when arrive a timer message this will be blocked in while loop, but after 1 sec. will arrive other timer message and will be blocked.
This is the problem, you never exit from OnTimer function, but OnTimer function is called at each 1 sec.
From this reason you have a Stack Overflow exception.
|
|
|
|
|
You are most likely right. The funciton (while uncommented) of AfxMessageBox(_T("Failed to create the main window!")); never be reached.
Thus I called KillTimer somewhere in the program to kill ID_PLAYTIME_EVENT and there were no more Stack Overflow problems.
But question again:
How do the following codes work? Once this code being called and run, how does it exit the while loop? Is it the correct way to process the message queue?
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
From my tests, once the program runs to this code, the while loop will exit forever until exiting the entire program. Actually that is what I had expected so that some other codes can run on a multitasking windows such 2000.
DJ
|
|
|
|
|
I'm trying to use the following code
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CDocument),
RUNTIME_CLASS(CMainFrame),
RUNTIME_CLASS(CLeftView));
AddDocTemplate(pDocTemplate);
But i'm getting an error because I haven't created an CDocument derived object. However I have to use this approach, because i'm trying to create splitter windows using this code:
m_wndSplitterLR.CreateStatic(this, 1, 2);
m_wndSplitterLR.CreateView(0, 1, RUNTIME_CLASS(CRightView), CSize(0, 0), pContext);
m_wndSplitterLR.SetColumnInfo(0, 200, 0);
m_wndSplitterUD.CreateStatic(&m_wndSplitterLR, 2, 1, WS_CHILD | WS_VISIBLE, m_wndSplitterLR.IdFromRowCol(0, 0));
m_wndSplitterUD.CreateView(0, 0, pContext->m_pNewViewClass, CSize(0, 200), pContext);
m_wndSplitterUD.CreateView(1, 0, RUNTIME_CLASS(CLeftView), CSize(0, 0), pContext);
And pContext is NULL unless I use Doc/View architechture and if it's NULL the second last line chokes...but I do not need a CDocument....
Any ideas or suggestions...? Should I just define a phantom CDocument class or soemthing, somehoe???
Thanks.
"Two wrongs don't make a right, but three lefts do!" - Alex Barylski
|
|
|
|
|
First: you don't need any document to create and use splitters.
If you want your CDocument to be a communication "media" among your views (via CDocument::UpdateAllViews ), you need to derive it and add this functionality. If you don't want to, you'll probably end up with the nasty code like:
((CMyRightPane*)((CSplitterWnd*)GetParent())->GetPane(x, y))->DoSomething();
which I personally hate.
So, run for your document or explicitly create/load a frame and create its views (in CYourFrame::OnCreateClient ) without using document templates.
Regards,
BB
|
|
|
|
|
If i don't use doc/view pContext->m_pNewViewClass is NULL inside OnCreateClient() and the application crashes???
How would I get the desired effect using the above I posted, without using DOC/VIEW???
Thanks!
"Two wrongs don't make a right, but three lefts do!" - Alex Barylski
|
|
|
|
|
Sample OnCreateClient for NULL document case (untested and not very elegant - but you will get the idea):
class CYourFrame : public CFrameWnd<br />
{<br />
CSplitterWnd Splitter;<br />
}
BOOL CYourFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext*) <br />
{<br />
CCreateContext cx;<br />
cx.m_pCurrentFrame = this;<br />
<br />
Splitter.CreateStatic(this, 1, 2);<br />
Splitter.CreateView(0, 0, RUNTIME_CLASS(CMyViewLeft), CSize(250, 250), &cx);<br />
Splitter.CreateView(0, 1, RUNTIME_CLASS(CMyViewRight), CSize(0, 0), &cx);<br />
<br />
if(bInitialUpdate) Splitter.SendMessageToDescendants(WM_INITIALUPDATE, 0, 0, FALSE);<br />
<br />
Splitter.SetActivePane(0, 0);<br />
return TRUE;<br />
}
Note: You may pass NULL as a last parameter to CSplitterWnd::CreateView , the WM_INITIALUPDATE message will then be automagically sent to the subsequently created views.
Regards,
BB
|
|
|
|
|
I am trying to code a program to play wave files using the low level functions provided by VC++ such as the "MMIO" functions.
I encountered problems in "waveOutOpen","waveOutWrite","waveOutPrepareHeader" functions.
A handle was passed as the first parameter to each of the function calls.The error i got was "waveOutOpen cannot convert parameter one from void ** to struct HWaveout_ **".the same error was shown for each of the other function calls(i.e for waveOutPrepareHeader etc),subsequently i typecasted the handle as (HWAVEOUT*).While this caused the errors to stop the program did not run as the header was not being prepared. The code is as shown below.
HANDLE hWaveOut;
MMRESULT ReturnCode = waveOutOpen((HWAVEOUT*)&hWaveOut,WAVE_MAPPER,(tWAVEFORMATEX*)&PCMWaveFmtRecord,NULL,NULL,NULL);
if(ReturnCode)
{
AfxMessageBox("Could Not Open Wave Device",MB_OK | MB_ICONSTOP,NULL);
return(FALSE);
}
ReturnCode=waveOutPrepareHeader((HWAVEOUT)&hWaveOut,&WaveHeader,sizeof(WaveHeader));
if(ReturnCode)
{
AfxMessageBox("Could Not Prepare Header",MB_OK | MB_ICONSTOP,NULL);
waveOutClose((HWAVEOUT)hWaveOut);
return(FALSE);
}
ReturnCode = waveOutWrite((HWAVEOUT)&hWaveOut,&WaveHeader,sizeof(WaveHeader));
if(ReturnCode)
{
AfxMessageBox("Error Writing to Wave Device",MB_OK | MB_ICONSTOP,NULL);
waveOutClose((HWAVEOUT)hWaveOut);
return(FALSE);
}
Could anyone let me know how to proceed?
novicedude
|
|
|
|
|
Your first function,
waveOutOpen((HWAVEOUT*)&hWaveOut,WAVE_MAPPER,(tWAVEFORMATEX*)&PCMWaveFmtRecord,NULL,NULL,NULL);
seems to be correctly, but more correctly is to use function like that:
HWAVEOUT hWaveOut;
waveOutOpen(&hWaveOut,WAVE_MAPPER,(LPWAVEFORMATEX)&PCMWaveFmtRecord,NULL,NULL,NULL);
(where PCMWaveFmtRecord identifies the format of the waveform-audio data to be sent to the device).
The second and third function:
waveOutPrepareHeader((HWAVEOUT)&hWaveOut,&WaveHeader,sizeof(WaveHeader));
waveOutWrite((HWAVEOUT)&hWaveOut,&WaveHeader,sizeof(WaveHeader));
is not correctly because the first parrametter pased is need to be a HWAVEOUT handle and not a reference.
Correctly is:
waveOutPrepareHeader(hWaveOut,&WaveHeader,sizeof(WAVEHDR));
waveOutWrite(hWaveOut,&WaveHeader,sizeof(WAVEHDR));
|
|
|
|
|
Hi:
As you know "SetTimer" has the following syntax:
UINT_PTR SetTimer(
HWND hWnd, // handle to window
UINT_PTR nIDEvent, // timer identifier
UINT uElapse, // time-out value
TIMERPROC lpTimerFunc); // timer procedure
I have problem with first parameter.i used m_hWnd (public member),but it doesn't work!!!.now in my MFC application,what should i choose for first parameter ? in the other hand how can i get a handle to the form or dialog's window ? please help me.
Best Regards.
|
|
|
|
|
In MFC, SetTimer() is a CWnd method. Just call it in your dialog's OnInitDialog() or in your CFormView's OnInitialUpdate() .
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
HWND GetDlgItem( int nID ) will give you the window handle.
You could actually use CWnd::SetTimer which doesn't require a handle as a parameter.
UINT SetTimer( UINT nIDEvent, UINT nElapse, void (CALLBACK EXPORT* lpfnTimer)(HWND, UINT, UINT, DWORD) );
For your Callback function you can have a NULL parameter and you can handle WM_TIMER instead or CWnd::OnTimer(UINT nIDEvent );
// Afterall I realized that even my comment lines have bugs
|
|
|
|
|
What do you mean "it doesn't work"? It won't compile? It formats your drive?
When you call SetTimer in a window class, you use CWnd::SetTimer , which doesn't take an HWND parameter.
--Mike--
THERE IS NO THERE IS NO BUT THERE IS
MAGIC PIXIE DUST BUSINESS GENIE CODE PROJECT
Homepage | RightClick-Encrypt | 1ClickPicGrabber
"You have Erica on the brain" - Jon Sagara to me
|
|
|
|
|
Michael Dunn wrote:
It formats your drive?
Bad day @ work, Mike?
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
MR ZarrinPour wrote:
now in my MFC application,what should i choose for first parameter ?
Have a look at GetSafeHwnd(), although CWnd::SetTimer() is probably what you should be using.
|
|
|
|
|
i want to restrict a user from accessing different drives in the system from the IE url box.
when u type d: in internet explorer it directly opens the drive d i donot what this to happen. how can i acheive this ....
thnks in advance
qrious
|
|
|
|
|