|
What language? What toolkit? What object is this?
earl
|
|
|
|
|
Language: C++
Toolkit: Windows Console API
I just wanted the basic formula to fill a square... Thanks!
Windows Calculator told me I will die at 28.
|
|
|
|
|
I assume the representation of the image in memory is sequential X and stepped Y. This would mean that pixel X=0/Y=0 is followed in memory by pixel X=1/Y=0, then X=2/Y=0, etc.
With this memory representation of the image your formula would be correct. If your image is 100 pixels wide then the pixel X=17/Y=35 would be located in memory array cell 35*100+17.
However, you should note that your code could have several optimizations, applicable in any language. The most important of them is that all modern processors use cache machanisms, which are exploited to their best if memory accesses are sequential.
This means that your outter loop should be the Y loop, and the inner loop should be the X loop. Something like this:
for (int cy = loc.y; cy < loc.y+loc.h; cy++) {
for (int cx = loc.x; cx < loc.x+loc.w; cx++) {
this->screen[cy*loc.w+cx].Attributes = color;
} // next x
} // next y
The loop order is simply reversed. With this arrangement the access the processor needs to the main memory is optimized, because the X loop accesses the memory sequentially (the pixels are arranged so that pixel X+1 follows pixel X, and the cache can take advantage of this). This can lead to typical improvements of 10x or more (of course, depending on the overall performance of the language). If the Y loop is the inner loop, then no memory access is sequential, since (from the cache point of view) the memory will be accessed in (potentially) large leaps and never sequentially. However, with large caches and small images, the cache could hold all the image square and still behave optimally (the cache would be helping the performance of your code, and your code would not be helping the cache at all).
Another simple optimization would be something like:
int y0=loc.y;
int y1=loc.y+loc.h;
int x0=loc.x;
int x1=loc.x+loc.w;
int pixel_index;
for (int cy = y0; cy < y1; cy++) {
pixel_index=cy*loc.w+cx;
for (int cx = x0; cx < x1; cx++) {
this->screen[pixel_index].Attributes = color;
pixel_index=pixel_index+1;
} // next x
} // next y
The advantages of the previous code are several:
1) Avoid an addition with each iteration of the outter y loop (y1 is precomputted).
2) Avoid an addition with each iteration of the inner x loop (x1 is precomputted).
3) Avoid one multiplication for each pixel. Since the pixel_index is computed at the start of each loop, we take advantage from the fact that adjacent X pixels correspond to adjacent addresses in memory. So, we just increment pixel_index, avoiding the multiplication for each X loop. This could be further inproved if we precomputed how much pixel_index would have to be incremented at the end of each X loop to end up in the first X of the next line, but this typically doesn't improve performace much.
The optimizations 1) and 2) above increase the clarity of the code, but are typically not very significant. Optimization 3) may be much more significant, but it reduces clarity. In any case, these optimizations are noticeable more and more as images become larger and larger.
I hope that you find these very easy to implement hints helpful.
Rilhas
|
|
|
|
|
Hmm... I never thought of it that way... Thanks very much!
Windows Calculator told me I will die at 28.
|
|
|
|
|
Hy. I'm trying to subclass the main winamp window in order to be able to get winamp internal information without using a timer(ie: current song artist, album, title, lenght, ..., volume, etc). I'm currently having trouble sbuclassing the winamp window (don't actualy know how to do it)
If some one could tell me what I did wrong, or what could be done better, I wold be realy grateful.
Here's the code:
========================================================================================
// gen_mymsc.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
#include "gen_mymsc.h"
#include "gen.h"
#include "confDiag.h"
#include "wa_ipc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
//
//TODO: If this DLL is dynamically linked against the MFC DLLs,
// any functions exported from this DLL which call into
// MFC must have the AFX_MANAGE_STATE macro added at the
// very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//
// Cgen_mymscApp
BEGIN_MESSAGE_MAP(Cgen_mymscApp, CWinApp)
END_MESSAGE_MAP()
// Cgen_mymscApp construction
Cgen_mymscApp::Cgen_mymscApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
int Cgen_mymscApp::winampInit()
{
AfxMessageBox(_T("Winamp has initiated the plugin."), MB_ICONASTERISK, 0);
return 0;
}
void Cgen_mymscApp::winampConfig()
{
CconfDiag *confDiag = new CconfDiag();
//INT_PTR
confDiag->DoModal();
}
void Cgen_mymscApp::winampQuit()
{
AfxMessageBox(_T("Winamp has destroyed the plugin!!! "), MB_ICONASTERISK, 0);
}
int Cgen_mymscApp::winampSongChanged()
{
return 0;
}
// The one and only Cgen_mymscApp object
Cgen_mymscApp theApp;
// Cgen_mymscApp initialization
BOOL Cgen_mymscApp::InitInstance()
{
CWinApp::InitInstance();
hwndWinamp = FindWindowW(_T("Winamp 1.x"), NULL);
return TRUE;
}
/*********************************
* Winamp main functions *
*********************************/
WNDPROC lpWndProcOld = NULL;
LONG winampLong;
bool smth = false;
HWND winampHWND;
int init(){
AFX_MANAGE_STATE(AfxGetStaticModuleState());
winampHWND = FindWindow(L"Winamp v1.x", NULL);
winampLong = GetWindowLong(winampHWND, 0);
lpWndProcOld = (WNDPROC)SetWindowLong(winampHWND, GWL_WNDPROC, winampLong);
return theApp.winampInit();
}
void config(){
AFX_MANAGE_STATE(AfxGetStaticModuleState());
theApp.winampConfig();
}
void quit(){
AFX_MANAGE_STATE(AfxGetStaticModuleState());
theApp.winampQuit();
}
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
AfxMessageBox(L"We has entered the the callback procedure");
if(message==WM_WA_IPC && lParam==IPC_ISPLAYING && smth==false)
{
AfxMessageBox(L"Winamp is playing");
smth = true;
return 0;
}
return CallWindowProc(lpWndProcOld,hwnd,message,wParam,lParam);
}
winampGeneralPurposePlugin plugin =
{
GPPHDR_VER,
"Multi - Yahoo! Messenger Status Changer (gen_mymsc.dll)",
init,
config,
quit,
};
extern "C" {
__declspec(dllexport) winampGeneralPurposePlugin *winampGetGeneralPurposePlugin(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return &plugin;
}
}
===============================================================================================
http://rafb.net/paste/results/6vBdVY85.nln.html <-the same code with sintaxHighlight
|
|
|
|
|
u0m3 wrote: winampLong = GetWindowLong(winampHWND, 0);
Did you just make this up? 0 is DWL_MSGRESULT.
u0m3 wrote: lpWndProcOld = (WNDPROC)SetWindowLong(winampHWND, GWL_WNDPROC, winampLong);
lpWndProcOld = (WNDPROC)SetWindowLong(winampHWND, GWL_WNDPROC, (LONG) &MainWndProc);
|
|
|
|
|
I started using this code for subclassing the main window: http://forums.winamp.com/showthread.php?s=&threadid=227006
Here's the relevant part:
int init()<br />
{<br />
lpWndProcOld = (WNDPROC)SetWindowLong(plugin.hwndWinampParent,GWL_WNDPROC,(LONG)WndProc);<br />
<br />
HWND pe = (HWND)SendMessage(plugin.hwndWinampParent,WM_WA_IPC,IPC_GETWND_PE,IPC_GETWND);<br />
lpPEProcOld = (WNDPROC)SetWindowLong(pe, GWL_WNDPROC, (LONG)PlaylistEditorProc);<br />
<br />
return 0;<br />
}
I used only the first part...
lpWndProcOld = (WNDPROC)SetWindowLong(plugin.hwndWinampParent,GWL_WNDPROC,(LONG)WndProc);
I got errors for plugin and (LONG)WndProc -> don't know how to get them... sorry... I'm a n00b.
|
|
|
|
|
hfry wrote: lpWndProcOld = (WNDPROC)SetWindowLong(winampHWND, GWL_WNDPROC, (LONG) &MainWndProc);
What is MainWndProc? Or more importantly, how do I get it?
|
|
|
|
|
It's your window procedure...
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
|
I have a fairly large application (MFC App) developed in Visual C++ 6.0.
As it's growing constantly, it's getting bigger and bigger and I've started to modularize it by adding DLLs with Visual Studio 2003 and now Visual Studio 2005.
Is there a better method nowadays that I can use to add new modules to the app or is DLL still the classic method used ?
Thanks.
|
|
|
|
|
vcpp_cgr wrote: is DLL still the classic method used
Pretty much the same, except that it's called assembly in the context of .NET Framework.
Best,
Jun
|
|
|
|
|
How can I recieve HBITMAP from clipboard? In both cases I;m getting empty bitmap:
1. HGLOBAL hMem = GetClipboardData( CF_BITMAP );
HBITMAP hBitmap = (HBITMAP) GlobalLock( hMem );
2. HBITMAP hBitmap = (HBITMAP) GetClipboardData( CF_BITMAP );
And second question:
how can I then create CBitmap object from HBITMAP?
Thanks for any help
~~~~
|
|
|
|
|
HBITMAP handle = (HBITMAP)GetClipboardData(CF_BITMAP);
CBitmap * bm = CBitmap::FromHandle(handle);
Do the chickens have large talons?
|
|
|
|
|
Then I need to draw this bitmap from clipboard. How can I select it for device context, to draw it on the screen?
This code isn't working:
CDC dcTmp;<br />
dcTmp.CreateCompatibleDC( pDC );<br />
<br />
HBITMAP handle = (HBITMAP)GetClipboardData(CF_BITMAP);<br />
CBitmap * bm = CBitmap::FromHandle(handle);<br />
dcTmp.SelectObject( bm );<br />
<br />
pDC->BitBlt( 0,0,uWidth,uHeight, &dcTmp, 0,0,SRCCOPY );
~~~~
|
|
|
|
|
Please somebody help me
~~~~
|
|
|
|
|
Code:
#include <iostream>
#include ".\PrimeGen.h"
using namespace std;
void main ()
{
CPrimeGen PrimeRange1(1,1000);
int iCountPrimes = 0;
for (int iCount = 1; iCount = 1000; iCount++)
{ if (PrimeRange1.PrimeNumber[iCount] == true)
{iCountPrimes ++;}
}
cout << iCountPrimes;
}
class CPrimeGen
{
public:
CPrimeGen(int iUpperBound);
CPrimeGen(int iUpperBound, int iInterval);
CPrimeGen(int iLowerBound, int iUpperBound, int iInterval);
virtual ~CPrimeGen();
bool isPrime (int iNumber);
bool *PrimeNumber; // array of PrimeNumbers
};
Jon
|
|
|
|
|
which symbol is unresolved ?
Do the chickens have large talons?
|
|
|
|
|
Test1 error LNK2019: unresolved external symbol __endthreadex referenced in function "void __stdcall AfxEndThread(unsigned int,int)" (?AfxEndThread@@YGXIH@Z)
Test1 error LNK2019: unresolved external symbol __beginthreadex referenced in function "public: int __thiscall CWinThread::CreateThread(unsigned long,unsigned int,struct _SECURITY_ATTRIBUTES *)" (?CreateThread@CWinThread@@QAEHKIPAU_SECURITY_ATTRIBUTES@@@Z)
Any ideas?
Jon
|
|
|
|
|
You are providing too little information. However, I would guess that you are missing a multithreading library. Make sure you are linking with multithread libraries.
Mutithreaded libraries are "LIBCMT.LIB" (release) and "LIBCMTD.LIB" (debug). However, I find it strange that the MFC is the one requesting the presence of "_beginthreadex" or "_endthreadex". This probably means you are not linking against MFC base libraries.
Anyway, try to link with the multothreaded libraries and see what you get. If it doesn't work then try to provide more information on the project settings (kind of project, compiler settings, linker settings, ...).
I hope this helps,
Rilhas
|
|
|
|
|
Hello,
I'm trying to program a few exception classes for use in some software I'm working on. I'm more familliar with Java style of exception programming, and am having trouble finding some good API documentation on C++ exception classes. My plan was to inherit from exception, or runtime_error, however I can't find figure out what methods I'm inheriting without a good API. Does anone know of a good API page on the exeption classes?
Thanks.
Patrick
|
|
|
|
|
|
Thanks for the link, that puts me on the right trak; however, considering the following example:
<br />
#include <iostream><br />
#include <exception><br />
using namespace std;<br />
<br />
class myexception: public exception<br />
{<br />
virtual const char* what() const<br />
{<br />
return "My exception happened";<br />
}<br />
} myex;<br />
<br />
int main () {<br />
try<br />
{<br />
throw myex;<br />
}<br />
catch (exception& e)<br />
{<br />
cout << e.what() << endl;<br />
}<br />
return 0;<br />
}<br />
This example does part of what I'm looking for, however I'd like to have more options when using the exception class. I'd like to give the programmer the option of passing in their own error message to the exception class, or to just use the default. Anyone know where I can look fir this?
Thanks.
Patrick
-- modified at 16:47 Thursday 13th July, 2006
|
|
|
|
|
pgav wrote: Anyone know where I can look fir this?
What Joe Woodbury said is correct. The C++ base exception class only defines what() so unless you want to use that you can just create your own base exception class to your own design requirements.
"Just about every question you've asked over the last 3-4 days has been "urgent". Perhaps a little planning would be helpful?" Colin Angus Mackay in the C# forum
led mike
|
|
|
|
|
With C++ exceptions, you can throw any object, even an int if you feel like it. There is no base exception class. (STL has an exception class, but it's very limited.)
I STRONGLY suggest writing your own exception class and write it to fit your requirements.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
hi,.....hhow can v load any movie clip in opengl?....`i have seen the tutorial in nehe..but it is not going wid the program i have developed..not showing the animation of the movie instead showing conflicts with already made tecxtures GL_TEXTURES_2D..how can v resolve dis?
Regards
NooR
|
|
|
|
|