|
Christian:
As I said before I'm not a Windows programmer so I'm not sure how I would go about double buffering a line draw instruction. Also I've tried invalidating the rectangle containing the old line but I think that's what's causing the flashing. Any more detailed help will be greatly appreciated.
Thanks
DGit
|
|
|
|
|
Rubberbanding the line is just part of what you need. Once you finish tracking the line and release the mouse button, your OnPaint or OnDraw will need to keep redrawing the graphics primitives (lines, arcs, ellipses, rects, etc...) whenever the area you've drawn to is invalidated.
Ivor Horton has a great introduction to this in his Visual C++ books. He goes through what is needed to store the coordinates of graphics primitives in the document in collection classes etc...
But, with that disclaimer aside, here's a quick and dirty demo on how to rubberband a line (remember, this only cover the rubberbanding and not redrawing your window when you drag another window over it etc...)...
Start a new Visual C++ Doc/View project, nothing fancy using a single document and deriving from CView for simplicity.
Use the ClassWizard to add these handlers to your view class and ensure the code looks something like this...
// in your views .h file
private:
void DrawRubberBand(CPoint pointCurrent);
CPoint m_pointLast;
CPoint m_pointStart;
BOOL m_bTracking;
// in your views .cpp file
void CRubberBandView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (nFlags & MK_LBUTTON) {
DrawRubberBand(point);
m_bTracking=TRUE;
m_pointLast=point;
}
CView::OnMouseMove(nFlags, point);
}
void CRubberBandView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
SetCapture();
m_pointStart=point;
m_pointLast=point;
CView::OnLButtonDown(nFlags, point);
}
void CRubberBandView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
ReleaseCapture();
m_bTracking=FALSE;
DrawRubberBand(point); // Erase the last line
CView::OnLButtonUp(nFlags, point);
}
void CRubberBandView::DrawRubberBand(CPoint pointCurrent)
{
CClientDC dc(this);
dc.SetROP2(R2_NOT);
dc.SelectStockObject(BLACK_PEN);
// Do we need to erase last line
if (m_bTracking) {
dc.MoveTo(m_pointStart);
dc.LineTo(m_pointLast);
}
// Draw the current line
dc.MoveTo(m_pointStart);
dc.LineTo(pointCurrent);
}
-- modified at 23:14 Saturday 8th September, 2007
|
|
|
|
|
That's roughly what I've been trying to do but looking at your DrawRubberBand() function I don't see how:
if (m_bTracking) {
dc.MoveTo(m_pointStart);
dc.LineTo(m_pointLast);
}
erases the previous line. I've tried invalidating the rectangle containing the previous line and drawing the new one but that just causes flashing on the screen and an occasional part of the new line.
DGit
|
|
|
|
|
Try the code in a separate sample app then disect it.
The secret is in the ROP code. It performs a raster operation on the screen buffer directly.
Check out SetROP2
|
|
|
|
|
Thanks, that does exactly what I want for the straight line, now I'll have to figure out how to apply it to arcs.
Thanks again
DGit
|
|
|
|
|
I'm not exactly sure how the user pictures in Windows work.. But is there a way to find out the path for the current user picture so that it can be drawn into my window's DC? pure c/c++ please!
Thanks for your help!
--PerspX
"Nowadays, security guys break the Mac every single day. Every single day, they come out with a total exploit, your machine can be taken over totally. I dare anybody to do that once a month on the Windows machine." - Bill Gates
BSoD during a Win98 presentation
|
|
|
|
|
Take a peek in this folder:
C:\Documents and Settings\All Users\Application Data\Microsoft\User Account Pictures
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello all,
I have a small but urgent problem.
I am reading a line of text from a file, that uses delimiters to
separate the text.
For that purpose I am using the strtok function. the problem is that
the text read by strtok when it finds no delimiter is of 1 char size bigger then the value it represents in the IDE.
meaning "John" is displayed as the value name holds but in strlen it shows a size of 5, as opposed to sizeof(name) that shows size of 4.
how does strtok work and why is that please, it's urgent, I have to hand it in
for school tomorow morning at 8:00 and it's now 24:00 here
the relevant code:
while( ! feof(inputFile) )
{
int check;
fgets(Line , 80 , inputFile);
command = strtok(Line , " ");
if(strcmp(command , "add_customer") == 0)
{
int i = 0;
char* name, *address;
int table_num;
if(i == 0)
{
command = strtok(NULL , ";");
name = command;
i++;
}
if(i == 1)
{
command = strtok(NULL , ";");
address = command;
i++;
}
if(i == 2)
{
command = strtok(NULL , ";");
table_num = atoi(command);
i++;
rdb_add_customer(Rest , name , address , table_num);
}
continue;
}
if(strcmp(command , "get_address") == 0)
{
int i = 0;
char* name;
if(i == 0)
{
command = strtok(NULL , ";");
name = command;
i++;
rdb_get_address(Rest , name);
}
continue;
}
//==========================================================================
int string_compare_func(Element e1 , Element e2)
{
int i , j;
if(e1 == NULL || e2 == NULL)
{
if(e1 == NULL && e2 == NULL)
return 0;
else if (e1 == NULL && e2 != NULL)
return -1;
else
return 1;
}
else
{
char* e1S = element_to_string(e1);
char* e2S = element_to_string(e2);
i = strcmp(e1S , e2S);
if(i == 0)
{
i = strlen(e2S);
return 0;
}
else if(strcmp(e1S , e2S) > 0)
{i = strlen(e1S);
i = strlen(e2S);
return 1;}
else {
i = strlen(e1S);
i = strlen(e2S);
j = sizeof(e1S);
j = sizeof(e2S);
return -1;}
}
Please HELPPPP!!!!!!!!!!!!!!
:((
}
|
|
|
|
|
sizeof and strlen are not the same thing. sizeof(e1S) is 4 because e1S is a pointer, and on your CPU, pointers are 4 bytes long.
|
|
|
|
|
Just to add a bit to what Michael said... In the post you made earlier today you had
Element string_to_element(const char* val)
{
Element localElem = malloc(sizeof(val));
strcpy((char*)localElem , val);
return localElem;
}
the sizeof( val ) is returning the size of a char pointer (4) not the length of the string. You would want to use strlen( val ) + 1 like you did in your element_to_string call.
|
|
|
|
|
Hi,
I am trying to develop a DLL which can be used in couple scenarios:
1. Loaded by a console based C++ application, with minimal Win32 code (just to load DLLs)
2. Loaded by a Windows service. This is essentially the C++ Console application converted to a service.
The issue is that I want to handle Windows Messages WM_ based. First of all I do not know whether Message Loops are possible in DLLs. In my mind there are two options:
1. Use SetWindowsHookEx - did not work - possible because the console application itself is not a windows application so does not have a message queue - not sure if my reasoning is correct.
2. Create a window in a separate thread and it may receive messages - but does it work.
So, the fundamental issues are that first I do not know that if this is even possible and second if yes, then how?
if someone can post me some code - better still point me to some authoritative source - it would be great.
Thanks for reading.
|
|
|
|
|
You don't need to have a window, but your message loop does need to run.
You can add an exported entry point to the DLL that when called, starts a thread
that runs a message loop. Note that any windows you want to create that use this message
loop to get their messages must be created on this same thread.
If you create a Win32 GUI application with the app wizard and examine the _tWinMain()
function, your thread proc in the DLL would be very similar - register any window class you
initially need, create any initial window you need, and finally, loop translating and dispatching
messages until some termination event occurs.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi-
When I open my projects and try to access the Project Property pages, the Configuration Properties window on the left is there (and browses down correctly) but the right-hand side is just a blank gray box- no grid to let me see or modify my properties.
- Happens on all my projects
- I have not used the dialogs in a long time as I have not been making those types of changes
- The projects build correctly (so the data is there and accessed correctly)
- I can see the data in the .vcproj file
- I tried updating VC++ and got one patch, but no effect
- I found one other reference to this problem (back in 2004 But no solution was given.
Can anyone help?
Thanks!
Markd
|
|
|
|
|
Hi,
Is it possible to use LPSTR_TEXTCALLBACK for some subitems in a CListCtrl control
or must it be used for every subitem ?
|
|
|
|
|
Have you tried it? I haven't....I was hoping you would try it and report
back to us with the results
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
LPSTR_TEXTCALLBACK only affects one item/subitem at a time
|
|
|
|
|
Me view is derived from CFormView.
I need to add dialog in my view like a fixed child window. I do this in OnCreate.
m_TableDialog.Create(IDD_DIALOGTABLE, this);
The problem: The m_TableDialog doesn't receive messages, but controls in it do. So, for example CMyView::OnLButtonDown never called. What's the problem?
-- modified at 1:02 Sunday 9th September, 2007
|
|
|
|
|
progDes wrote: The problem: The m_TableDialog doesn't receive messages, but controls in it do. So, for example CMyView::OnLButtonDown never called.
I'm confused. m_TaleDialog is a CMyView class object? The WM_LBUTTONDOWN message
should go to the window under the cursor unless the mouse is captured by another window.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
No, m_TableDialog is CDialogTable object. And the dialog is creating in CMyView::Create. The owner of m_TableDialog is a view class. May be the creation of dialog is wrong? Looks like some modal dialog catch all messages.
|
|
|
|
|
Again, the WM_LBUTTONDOWN message should go to the window under the cursor
unless the mouse is captured by another window.
Where are you clicking and where do you expect to get the message?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I'm clicking on dialog window, and waiting the message in CDialogTable::OnLMouseDown.
The strange thing:
Controls are acting correct, buttons are animating etc, but there is a beep sound when I'm selecting element in CListCtrl (just like, trying to do something when modal dialog on the top), bu elements are selecting correctly.
|
|
|
|
|
I'm not picturing how your windows are arranged so it's tough to tell
what's going on.
Your CDialogTable is a child of a CFormView, right?
If so, it's on top of its parent in the z-order. How much of its parent is it covering up?
What controls are on which windows?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
SOLVED
This is long to explain, but in general I'm a fool myself
|
|
|
|
|
whith the GDI+ method DrawImage(), i can display a normal size image, but i can't display an image with 400M size. is there size limit and how can i display a big size image? thanks.
|
|
|
|
|
Where did you get an image of that magnitude? I can't say I've ever tried to display one that large.
Some suggestions would be to not use interpolation to see if it renders. If your using something like InterpolationModeHighQualityBicubic you might be asking too much of the graphics object.
Did you try rendering a much smaller image using the same code to see if it's displaying it in a part of your coordinate system that is visible. You might be rendering it in negative coordinates or somewhere off the client area.
Does the large image display with other rendering programs like MS Photoeditor or something similar that will scale it to fit the screen?
Try to eliminate those possibilities first if you haven't already.
|
|
|
|