Currently, I have this code in my on paint event in a view. CPaintDC dc(this); CPoint originalSize = matrix.GetSize(); int y, x; for (y = 0; y < size.y; y++) { for (x = 0; x < size.x; x++) { dc.SetPixelV(CPoint(x,y), obj.GetColorRef(CPoint(x, y))); } }
As you can understand, this is pretty slow with soewhat bigger pictures where for example, tje size is over 1000 x 1000 pixels. A solution, as far as I know, is to use a memory DC. However, I am doing something wrong. I want to create the memory DC with the following CPaintDC dc(this); CDC pdc; dc.CreateCompatibleDC(&pdc); CPoint originalSize = matrix.GetSize(); int y, x; for (y = 0; y < size.y; y++) { for (x = 0; x < size.x; x++) { pdc.SetPixelV(CPoint(x,y), obj.GetColorRef(CPoint(x, y))); } } dc.BitBlt(0, 0, size.x, size.y, ...)
However, the first time only a black block was drawn then, when resizing things go wrong (the app crashes), where a colored block should be drawn. What am I doing wrong, and if I am doing it wrong, how should I do it? LPCTSTR Dutch = TEXT("Double Dutch :-)");
S van Leent
Posts
-
Help with OnPaint -
technique for assure, that a function is overwritten in c++??Maybe some light. Any function has its start address. So you can check whether the start address of the function in the derived class is the same as the address of the function in the super class itself. If so, you could fault on runtime. It has some difficulties, and some knowledge of vtables seem to be handy here, but I think it is in the direction you should be thinking. LPCTSTR Dutch = TEXT("Double Dutch :-)");
-
CPaintDC develish slowHi all, I am currently doing a project where I need to be able to have a imaging framework. Although the framework itself runs pretty smooth, the CPaintDC of MFC kills me. The SetPixelV is extremely slow, so I want to use another way of doing this. I know it is possible to create a CDC in memory, but how can I put a bitmap created from this CDC put on the surface a CWnd subclassed control? Any suggestions? LPCTSTR Dutch = TEXT("Double Dutch :-)");
-
Missing DriveBetter to much solutions as no solution :) LPCTSTR Dutch = TEXT("Double Dutch :-)");
-
Missing DriveIs it formatted as FAT32 or NTFS, or is it formatted as another file system? LPCTSTR Dutch = TEXT("Double Dutch :-)");
-
Bold and Color TEXT in MessageBox?Probably you need the windows API called MessageBoxEx LPCTSTR Dutch = TEXT("Double Dutch :-)");
-
TabControl still not goodI know, but it seems so simple to fix :( LPCTSTR Dutch = TEXT("Double Dutch :-)");
-
TabControl still not goodI can't believe it. In the newest version of .NET, the tabcontrol still looks awefull, why don't they fix it at the MS House, it shouldn't be that much pane, or is it? LPCTSTR Dutch = TEXT("Double Dutch :-)");
-
Scrollbar control problemsI've made a horizontal scrollbar control using CreateWindowEx, and on the WM_HSCROLL event in the parent window I do this:
if (flag == SB_LEFT) { curPos -= 1; } else if (flag == SB_RIGHT) { curPos += 1; } else if (flag == SB_LINELEFT || flag == SB_PAGELEFT) { curPos -= 1; } else if (flag == SB_LINERIGHT || flag == SB_PAGERIGHT) { curPos += 1; } else if (flag == SB_THUMBTRACK || flag == SB_THUMBPOSITION) { curPos = position; }
Then using SetScrollPos(hWndScroll, SB_CTL, curPos, TRUE) I try to let the scrollbar be updated, but it doesn't seem to work. any ideas? LPCTSTR Dutch = TEXT("Double Dutch :-)"); -
Overruling WH_CBT hook behaviourIf I create a window, and I use the normal SetWindowsHook procedure like this:
SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTProc, hInstance, NULL);
It does work on self defined windowclasses but it doesn't seem to work with normal controls, like buttons and so on. How can I overrule this? If not possible, can I make a button using a selfdefined windowclass which calls the button procedure on it's turn? LPCTSTR Dutch = TEXT("Double Dutch :-)"); -
Resourceless DialogboxThanks, though I'm using CreateDialogIndirectParam and DialogBoxIndirectParam right now LPCTSTR Dutch = TEXT("Double Dutch :-)");
-
Resourceless DialogboxWell then, is there a way to at least create a dialogbox without a resource? LPCTSTR Dutch = TEXT("Double Dutch :-)");
-
Resourceless DialogboxHelp wanted! I need to create a resourceless dialog box. I want it to use a WndProc instead if a DlgProc, and I want to use CreateWindow instead of CreateDialog or variants. Is there a standard window class which I can use to accomplish this task? I was thinking of:
CreateWindow(TEXT("DIALOG"), TEXT("HELLO"), WS_VISIBLE, ...)
^^^^^^
The window classThanks in advance LPCTSTR Dutch = TEXT("Double Dutch :-)");
-
CBTProc not workingWell, when I wrote the thing and uploaded it, in a minute I knew the solution, It works great. The function looks like:
static LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam) { if (nCode == HCBT\_CREATEWND) { LONG counter = 0; HWND hWnd = reinterpret\_cast(wParam); LPCBT\_CREATEWND lpcw = (LPCBT\_CREATEWND)lParam; LONG lpCreateParams = (LONG)lpcw->lpcs->lpCreateParams; // This makes it possible to use "API-style" windows too, where // the lpCreateParams does not point to a class if (lpCreateParams != 0 && lpcw->lpcs->hInstance == \_\_hInstance\_\_) { for (iIterator = arrUnboxedClasses.begin(); iIterator != arrUnboxedClasses.end(); iIterator++, counter++) { if (arrUnboxedClasses.at(counter) == lpCreateParams) { ::SetWindowLong(hWnd, GWL\_USERDATA, lpCreateParams); goto end; } } } } end: return CallNextHookEx(\_\_hWndsHook\_\_, nCode, wParam, lParam); }
I still think that another application may not crash because I install a hook, this is not a really good design, I think. LPCTSTR Dutch = TEXT("Double Dutch :-)");
-
Cost of a function callJoe Woodbury wrote: In general, unless you really understand the CPU architecture, you should just write clean C/C++ code and let the compiler do it's thing. I agree with that, also, I think Inlining is sometimes a lazy way of writing a macro, which is (the macro) sometimes much better. LPCTSTR Dutch = TEXT("Double Dutch :-)");
-
Movies: X-Men 2It's Simple, Famke Janssen is in it, and because I'm coming from the Netherlands (just as she does), I need to see it. Well I do like the rest too you know. LPCTSTR Dutch = TEXT("Double Dutch :-)");
-
Need a simple "console-style" output window in MFCA textbox could do the trick, by doing something like
txtBox->SetWindowText(txtBox->GetWindowText() + CString(_T("Some text")))
LPCTSTR Dutch = TEXT("Double Dutch :-)");
-
Cost of a function callWell, I know someone who makes a 3D-graphics engine, it really does matter pushing things on the stack or not. So I think a compiler should just inline when you want it to inline. Which doesn't gain much over complex calculations, but simple calculations, at the other hand, do matter. LPCTSTR Dutch = TEXT("Double Dutch :-)");
-
Is ++i statement in the for loop better than i++?OK, but if you don't use optimization (it can be useful for something), it does matter LPCTSTR Dutch = TEXT("Double Dutch :-)");
-
CBTProc not workingI'm experimenting with hooking, but when I do the following:
hWndsHook = SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTProc, NULL, NULL);
I expect it to run:
LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode == HCBT_CREATEWND)
{
HWND hWnd = reinterpret_cast<HWND>(wParam);
LPCBT_CREATEWND lpcw = (LPCBT_CREATEWND)lParam;
LONG lpCreateParams = (LONG)lpcw->lpcs->lpCreateParams;
::SetWindowLong(hWnd, GWL_USERDATA, lpCreateParams);
}return CallNextHookEx(hWndsHook, nCode, wParam, lParam);
}
But it doesn't. There are no compile warnings or whatsoever. I tried to debug it, but when marking it with a breakpoint (at CallNextHookEx) for example, it doesn't break, and it sure doesn't do what I want it to do. And I really am creating windows with CreateWindow, which does do what it needs to do (The MessageLoops work). LPCTSTR Dutch = TEXT("Double Dutch :-)");