|
I wrote a program which includes these declarations:-
class PEN{public: HDC d; HPEN pen,old;
PEN(HDC dc,COLORREF col);
~PEN();};
/*-----*/
/* the device context dc must still exist when the pen is deleted */
PEN::PEN(HDC dc,COLORREF col){ d=dc;
pen=(HPEN)CreatePen(0,1,col);
old=(HPEN)SelectObject(dc,pen);};
PEN::~PEN(){ SelectObject(d,old);
DeleteObject(pen);};
/*-----*/
// then I can write for example:-
/*-----*/
if(xhairs) {
PEN orange(WIdc,RGB(255,128,0)); Line(WIdc,0,b/2,(int)(2*a),(int)(b/2));
Line(WIdc,(int)(a/2),0,(int)(a/2),b);
Line(WIdc,(int)(a*1.5),0,(int)(a*1.5),b);}
/*-----*/
and the new pen is automatically cleared away when control leaves the block where the pen was declared.
And similarly with fonts etc.
modified 3-Feb-15 9:41am.
|
|
|
|
|
And your question is?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Is this class declaration likely to be any use to any of you?
|
|
|
|
|
Anthony Appleyard wrote: Is this class declaration likely to be any use to any of you? Not really, the GDI+ Pen class[^] is already available.
|
|
|
|
|
I' m new with MFC. I needed to create a floating toolbar (CToolBar) with no option of docking and save and restore its last pos.
The toolbar also should be active all the time, but its NOT. When I'm openning a new child window (dialog for instance) from the mainframe, the floating tool bar become not active (I can not click on its buttons, or drag it etc..).
In the past I've used CDialog with Overlapped style and it was floating and always active as I needed. Is it possible to do the same with my Floating Toolbar? Thanks
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
toolbarIconSize.cx = toolbarIconSize.cy = TOOLBAR_MAIN_ICON_SIZE;
if ( !m_wndMyFloatingToolbar.Create(this,m_wndMyFloatingToolbar.GetBarStyle() |WS_EX_PALETTEWINDOW | WS_EX_TOPMOST |CBRS_FLOATING | WS_VISIBLE) ||
!m_wndMyFloatingToolbar.LoadToolBar(IDR_GENERAL_TOOLBAR, toolbarIconSize))
{
TRACE0("Failed to create My Floating Toolbar\n");
return -1; }
m_wndMyFloatingToolbar.EnableDocking(0);
EnableDocking(0);
if (!CreateCtrlBar())
{
TRACE0("Failed to create ctrl toolbar\n");
return -1; }
return 0;
}
void CMainFrame::OnViewToolBar()
{
CPoint Pos = MyFloatingToolbarGetLastPosition(); \\Get last pos
FloatControlBar( &m_wndMyFloatingToolbar, Pos, CBRS_ALIGN_LEFT );
MyFloatingToolbarSetIsVisible();
FloatControlBar( &m_wndMyFloatingToolbar, Pos, CBRS_ALIGN_LEFT );
}
void CMainFrame::MyFloatingToolbarSetIsVisible()
{
WINDOWPLACEMENT wp;
m_wndMyFloatingToolbar.GetParent()->GetParent()->GetWindowPlacement(&wp);
wp.showCmd = SW_SHOW;
m_wndMyFloatingToolbar.GetParent()->GetParent()->SetWindowPlacement(&wp);
m_wndMyFloatingToolbar.GetParent()->GetWindowPlacement(&wp);
wp.showCmd = SW_SHOW;
m_wndMyFloatingToolbar.GetParent()->SetWindowPlacement(&wp);
m_wndMyFloatingToolbar.GetWindowPlacement(&wp);
wp.showCmd = SW_SHOW;
m_wndMyFloatingToolbar.SetWindowPlacement(&wp);
}
void CWJToolBar::OnWindowPosChanging(WINDOWPOS FAR* lpwndpos)
{
CToolBar::OnWindowPosChanging(lpwndpos);
if ( GetBarStyle() & CBRS_FLOATING )
{
if((lpwndpos->flags & SWP_HIDEWINDOW) && ((this->GetParentFrame())->m_hWnd !=(this->GetTopLevelFrame())->m_hWnd))
{
CMainFrame* mf = (CMainFrame*)(AfxGetApp()->GetMainWnd());
mf->MyFloatingToolbarSavePosition();
}
}
}
|
|
|
|
|
In Visual C/C++ 2008 version's main top menu, clicking on "Build" causes a dropdown menu, which includes:-
Build Solution
Rebuild Solution
Clean Solution
Build xxxx
Rebuild xxxx
Clean xxxx
Project Only
and clicking on "Project Only" causes a sub-dropdown menu with:-
Build Only xxxx
Rebuild Only xxxx
Clean Only xxxx
Link Only xxxx
where "xxxx" is the name of the current project.
What is "Solution" and what is "xxxx" and what is "Only xxxx"? Which of these 3 options recompiles the whole of the current project? Which option recompiles what?
|
|
|
|
|
Each project is part of a Solution (top folder in the tree), which may contain other projects. So you can build/rebuild/clean only a particular project, or every project in the Solution.
|
|
|
|
|
The first line of the output should use the %d place holder in the format string to print the number 42.
The second line should use the %c placeholder to print the letter J.
The third line should use the %f placeholder to print the number 3.14159 with 6 decimal digits after the
decimal (this is the default)
|
|
|
|
|
smells like homework - read your lecture notes & textbook, then post back whatever actual code you have written - we don't write code, especially homework for people - it makes them lazy and us annoyed, and your teacher/professor/whatever can smell copied/stolen works a mile off
|
|
|
|
|
|
error C2440: 'static_cast' : cannot convert from 'void (__thiscall COptionDBTransport::* )(PCTSTR)' to 'AFX_PMSG'
Throws error at this line-
ON_BN_CLICKED(IDC_BUTTON_udpCheck, &COptionDBTransport::OnBnClickedButtonudpcheck)
Please help me for this issue.
modified 31-Jan-15 3:49am.
|
|
|
|
|
Seemingly your only problem is that your method signature doesn't match.
See the AFX_PMSG[^] signature.
You method receives a PCTSTR parameter while a button event handler should be a method without any parameters.
|
|
|
|
|
Yes ,it is inherited from CCmdTarget(base class of all classes used)
M still stuck to that error
@pasztorpisti-How to pass multiple parameters to a button event handler.
|
|
|
|
|
You can not pass a parameter to a button event handler. You have to gather the data in the handler - for example by querying textboxes/checkboxes/etc in your handler method.
|
|
|
|
|
thanks pasztorpisti, will try that.
|
|
|
|
|
Does your COptionDBTransport inherit from CCmdTarget (or a derived type of it)?
Have you included (even if indirectly) <afxwin.h>? (ON_BN_CLICKED is defined in another header)
|
|
|
|
|
Thanks, Yes Have inculded the header file.
|
|
|
|
|
Then I'm totally baffled. Recommend you compile with /P (preprocess to file) and then, from a command-prompt try to compile that generated file. It should contain #line directives and such making it (hopefully) obvious why it fails.
++luck;
|
|
|
|
|
This is a code for snake game using dev c++. now i would like to know how can i create:
- a new snake (2nd snake) which eats the apple(so called apple) on its own..
- which means.. 1st snake will be handled by user. while the 2nd snake works on its own. and both snake fights to get the apple.
can any1 suggest me how can i do this.
#include <iostream>
#include <windows.h>
#include <stdlib.h>
#include <conio.h>
using namespace std;
typedef struct tailpos
{
int x;
int y;
struct tailpos *next;
struct tailpos *prev;
}
tail;
int d=4;
class snake
{
public:
int foodx,foody;
HANDLE console_handle;
COORD cur_cord;
tail *start,*current,*newtail;
snake();
void insert(int x , int y);
void draw();
void drawWall();
void move();
bool collision();
void drawfood(int x=0);
};
snake::snake()
{
start = NULL;
current = NULL;
newtail = NULL;
console_handle=GetStdHandle( STD_OUTPUT_HANDLE );
foodx=12;
foody=14;
}
void snake::drawWall()
{
cur_cord.X=0;
for(int y=0;y<=30;y++)
{.....
}
void snake::drawfood(int x)
{
tail *tmp;
tmp=start->next;
if(x==1) .....
}
void snake :: insert(int x , int y)
{
if(start == NULL)
{
newtail = new tail;
newtail->x=x;
newtail->y=y;
newtail->next=NULL;
newtail->prev=NULL;
start=newtail;
current=newtail;
}
else
{
newtail = new tail;
newtail->x=x;
newtail->y=y;
newtail->next=NULL;
newtail->prev=current;
current->next=newtail;
current=newtail;
}
}
void snake::move()
{
tail *tmp,*cur;
tmp =current;
while(tmp->prev!=NULL)
{
tmp->x=tmp->prev->x;
tmp->y=tmp->prev->y;
tmp=tmp->prev;
}
if(d==1)
start->y--;
if(d==2)
start->y++;
if(d==3)
start->x--;
if(d==4)
start->x++;
}
bool snake::collision()
{
tail *tmp;
tmp=start->next;
while(tmp->next!=NULL)
{
if(start->x == tmp->x && start->y == tmp->y)
return true;
tmp=tmp->next;
}
if(start->x == foodx && start->y == foody)
{
insert(foodx,foody);
drawfood(1);
}
for(int x=0;x<=30;x++)
{
if(start->x == x .....
}
void snake::draw()
{
tail *tmp , *last;
tmp=start;
last = current;
while(tmp!=NULL)
{
cur_cord.X=tmp->x;
cur_cord.Y=tmp->y;
SetConsoleCursorPosition(console_handle,cur_cord);
cout << "#";
tmp=tmp->next;
}
cur_cord.X=last->x;
cur_cord.Y=last->y;
SetConsoleCursorPosition(console_handle,cur_cord);
cout << ' ';
cur_cord.X.....
}
int main()
{
......
}
getch();
return 0;
}
|
|
|
|
|
Hello,
I'm trying to adapt some Microsoft code (member.cpp in Detours) for my case
( I just want to replace
void CMember::Target(void)
by
QString QString::fromAscii(const char *str, int size):
MS Code :
class CMember
{
public:
void Target(void);
};
void CMember::Target(void)
{
printf(" CMember::Target! (this:%p)\n", this);
}
class CDetour
{
public:
void Mine_Target(void);
static void (CDetour::* Real_Target)(void);
};
void CDetour::Mine_Target(void)
{
printf(" CDetour::Mine_Target! (this:%p)\n", this);
(this->*Real_Target)();
}
void (CDetour::* CDetour::Real_Target)(void) = (void (CDetour::*)(void))&CMember::Target;
My code :
class CDetour
{
public:
QString Mine_Target(const char *str, int size);
static QString (CDetour::* Real_Target)(const char *str, int size);
};
QString CDetour::Mine_Target(const char *str, int size)
{
printf(" CDetour::Mine_Target! (this:%p)\n", this);
(this->*Real_Target)(str, size);
}
QString (CDetour::* CDetour::Real_Target)(const char *str, int size) = (CDetour::*)(const char *str, int size)&QString::fromAscii;
But I get :
error C2059: syntax error: '< tag >::*'
for the last line
Why ?!
Thanks.
Edit :
If I do :
QString (CDetour::* CDetour::Real_Target)(const char *str, int size) = (QString(CDetour::*)(const char *str, int size))&QString::fromAscii;
I get :
error C2440: 'type cast' : impossible to convert from 'QString (__cdecl *)(const char *,int)' into 'QString (__thiscall CDetour::* )(const char *,int)'
modified 29-Jan-15 7:21am.
|
|
|
|
|
The first definition can't be correct. Regarding the second one, for me it looks like the QString::fromAscii isn't defined as a member method. Have you tried creating an own class like the CMember one and using this class' function in the function pointer? Once you get this working you can call QString::fromAscii directly from the inner function.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
But QString::fromAscii is a Static Public Members from Qt :
QString Class Reference
I thought I just had to replace CMember by QString and Target by fromAscii from the MS sample...
|
|
|
|
|
You're trying to cast to (CDetour::*) , which isn't a valid type definition. It is only a part of a member function pointer definition and doesn't make sense without the parameter list and return type.
Look at the last line in the MS code example: &CMember::Target is the address of a member function pointer. You can only cast a member function pointer to a member function pointer of a differentsimilar type, in this case (void (CDetour::*)(void)) , which is a member function of the class Detour (that is what CDetour::* means) with an empty parameter list (the (void) bit) and a void return type (the preceding void )
The compiler error is based on the fact that the compiler doesn't recognize (CDetour::*) as part of a function pointer definition without the preceding return type, and there is no other valid interpretation.
Your edit version looks better: the compiler does recognize the member function pointer cast correctly, it just doesn't want to accept that cast for some reason. One possible problem could be the calling convention being used: your class definition generated the member function using __thiscall , whereas the QT function was defined as using __cdecl . You may want to check your calling convention settings.
[edit]fixed my statement about function pointer casts in light of what I said in the last paragraph[/edit]
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
We use the CMFCRibbonBar defined from a resource file. We have a recent files list appearing to the right of the main menu (which contains New, Open, Print etc). The problem is that the elements are too widely spaced, which stands out as it does not match the other menus. Anyone know how to fix this?
For our Print sub-menu I was able to get 'correct' spacing of the menu items by editing the ribbon resource file and setting the <always_description> value to FALSE for each item. Unfortunately I cannot do this for file list items, and I cannot get each recent file list button using CMFCRibbonBar::FindByID(ID_FILE_MRU_FILE1+index) as it returns NULL.
|
|
|
|
|
I want to control the device with my programm.
How to get info from video capture card PEXHDCAP with no SDK or similar. I think I can only dissassemble the software / driver like hackers do.
Is there any expert who can find out how to control this device with own software ?
|
|
|
|