|
I have a dialog based app. In the OnInitDialog() function I am showing for some time a dialog box without any buttons and system menu. It shows a waiting message. It appears into the upper left corner of the screen. How can I make it apper centred to the screen?
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Use CenterWindow() .
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
You can use of David's answer or set CenterWindow to true of property window.
|
|
|
|
|
Hi all,
i want to use a bitmp variable as a global var,
so i wrote this code
<br />
CNeLoPApp theApp;<br />
CBitmap bitmap;<br />
bitmap.LoadBitmap(IDB_BITMAP1);<br />
HBITMAP hBitmap = (HBITMAP) bitmap.GetSafeHandle();<br />
But i had those errors
error C2143: syntax error : missing ';' before '.'
error C2501: 'bitmap' : missing storage-class or type specifiers
error C2371: 'bitmap' : redefinition; different basic types
error C2143: syntax error : missing ';' before '.'
Whayt's wrong with that code.
PS: i wrote nthq into the stdafx.h
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
Blood_HaZaRd wrote: bitmap.LoadBitmap(IDB_BITMAP1);
HBITMAP hBitmap = (HBITMAP) bitmap.GetSafeHandle();
Where are you calling these methods from?
Blood_HaZaRd wrote: error C2143: syntax error : missing ';' before '.'
What line?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I changed some lignes:
in the stdafx.h
<br />
extern CBitmap bitmap;<br />
extern HBITMAP hBitmap ;<br />
In myprog.cpp (where 'TheApp' var is declared by default )
<br />
bitmap.LoadBitmap(IDB_BITMAP1);<br />
hBitmap = (HBITMAP) bitmap.GetSafeHandle();<br />
but now on aform when i try to set the bitmap to a button via OnInitialUpdate()
<br />
m_Next.SetBitmap(hBitmap);<br />
I have this error
: error C2065: 'hBitmap' : undeclared identifier (that hBitmap is not declared on that form)
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
Ok i foud the solution.
all that i do is to delete the debug folder and rebuild the prog. and it works.
But I still have some issue:
when i run the prog the button dosn't display the bitmap. but when i move the window or clik on it the bitmap appears. I even put the m_Next.SetBitmap(hBitmap); into the OninitialUpdate() and OnPaint().
how ciould i resolve that little prob
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
There's no reason to extract the HBITMAP from a CBitmap into a separate variable.
The handle is available from the CBitmap object any time.
That aside, you need to separate the global variable definitions from the code that
initializes them. For example:
CNeLoPApp theApp;<br />
CBitmap bitmap;<br />
HBITMAP hBitmap = NULL;<br />
<br />
BOOL CNeLoPApp
::InitInstance()<br />
{<br />
bitmap.LoadBitmap(IDB_BITMAP1);<br />
hBitmap = (HBITMAP) bitmap.GetSafeHandle();
...
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I had to declare The bitmap and hBitmap as global var coz i had to Forms A & B and in both of them i hve a buttom that uses the same bitmap but when i goback from B to A the prog crashes (Erreur and stops).
So with global vars i had no more the erreur. but when i lunch tha prog, i have to wait 3 or 4 seconds to viex the button with the bitmap (may be it's a time prob for loading the bitmap).
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
First, CBitmap is a C++ wrapper for an HBITMAP handle. To have a separate HBITMAP variable
is redundant and instantly doubles your maintenance for a single object. There's NO valid reason
for doing that. You can use your CBitmap object anywhere a HBITMAP is needed, without even having
to cast it, because CBitmap has a HBITMAP cast operator.
Second, why not take advantage of the object-orientedness of MFC and encapsulate the
bitmap object in the class that uses it? What makes you think two buttons can safely share the
same bitmap?
There's rarely a need for global variables in MFC. If you think you need a global variable, there's
probably a better way to design your code.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have 2 forms on each of which i load the same bitmap for a button (let's say a button labeled Next).
when i load the bitmap and the Hbitmap on form A all go well
when i load the form B after a click on button from form A all go well
when i wanna goback to form A aftr a clik on a button on Form B the prog Crach down. That's why i used the bitmap and the hBitmap as global var?
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
How do you know the crash is related to the bitmap?
If it is taking 3-4 seconds to load a bitmap, it's either really big, or
there's a problem somewhere else.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
You can also use of HBITMAP without CBitmap.
|
|
|
|
|
Hi all,
I intend to filter IPv6 packets.
I have already succeeded in capturing and decoding the packets n a human readable format.
Now i want to block some unwanted IPv6 traffic
say:
I do Win XP to drop packets with destination address A and port A1 and source address B and port B1
how can I do this?
will manipulating the IPv6 routing tables on my machine work?
I did
C:> netsh
netsh> interface ipv6
interface ipv6> show routes
this showed me some routes for IPv6 traffic going out of my machine,can i manipulate them to block certain traffic.
Is there any other way of doing it, are there some libraries,classes, methods that can help filtering IPv6 packets.
please help
thanks and regards
Ather
|
|
|
|
|
Don't cross post.
led mike
|
|
|
|
|
I've managed to compile and run all the samples in the book so far, but all the sudden this code comes up and gives me nasty headaches.
When i'm trying to compile the code below everything goes fine until the compiler tries to link it.
Here's the error i get:
cd /Users/summer/Documents/C++/xcodeproject/ex<br />
/Developer/usr/bin/g++-4.0 -o /Users/summer/Documents/C++/xcodeproject/ex/build/Debug/ex -L/Users/summer/Documents/C++/xcodeproject/ex/build/Debug -F/Users/summer/Documents/C++/xcodeproject/ex/build/Debug -filelist /Users/summer/Documents/C++/xcodeproject/ex/build/ex.build/Debug/ex.build/Objects-normal/i386/ex.LinkFileList -arch i386 -mmacosx-version-min=10.5 -isysroot /Developer/SDKs/MacOSX10.5.sdk<br />
Undefined symbols:<br />
"vtable for Kvadrat", referenced from:<br />
__ZTV7Kvadrat$non_lazy_ptr in main.o<br />
ld: symbol(s) not found<br />
collect2: ld returned 1 exit status<br />
"vtable for Kvadrat", referenced from:<br />
__ZTV7Kvadrat$non_lazy_ptr in main.o<br />
ld: symbol(s) not found<br />
collect2: ld returned 1 exit status
And here's the code:
#include <iostream>
using namespace std;
class Form
{
public:
Form() {}
virtual ~Form() {}
virtual long HentAreal() { return -1; }
virtual long HentOmkreds() { return -1; }
virtual void Tegn() {}
};
class Rektangel : public Form
{
public:
Rektangel(int laengde, int bredde):
densLaengde(laengde), densBredde(bredde) {}
virtual ~Rektangel() {}
virtual long HentAreal() { return densLaengde * densBredde; }
virtual long HentOmkreds() { return 2*densLaengde + 2*densBredde; }
virtual int HentLaengde() { return densLaengde; }
virtual int HentBredde() { return densBredde; }
virtual void Tegn();
private:
int densBredde;
int densLaengde;
};
void Rektangel::Tegn()
{
for (int i = 0;i < densLaengde;i++)
{
for (int j = 0;j < densBredde;j++)
cout << "x";
cout << "\n";
}
}
class Kvadrat : public Rektangel
{
public:
Kvadrat(int laengde);
Kvadrat(int laengde, int bredde);
~Kvadrat();
long HentOmkreds() { return 4 * HentLaengde(); }
};
Kvadrat::Kvadrat(int laengde):
Rektangel(laengde, laengde)
{}
int main()
{
cout << "Do stuff";
return 0;
}</iostream>
When i remove
Kvadrat::Kvadrat(int laengde):<br />
Rektangel(laengde, laengde)<br />
{}
It compiles without problems. But i want to create a rectangel upon creation of a square! (rektangel == rectangel && kvadrat == square in danish)
|
|
|
|
|
You need a body for Kvadrat 's destructor.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
wow.. that was too simple. i feel stupid.
thanks!
|
|
|
|
|
you forgot:
Rektangel class default constructor (declaration & definition).Kvadrat(int laengde, int bredde) constructor definition.Kvadrat destructor definition
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
You beat me to it, you addict.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Rajesh R Subramanian wrote: You beat me to it, you addict.
Shhhhhhhhhh, don't spread such rumors.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
hi i was just wondeing if anyone knew how to use the mircosoft sam voice just to make a fun little program, an example would be say an edit box for user input then a button to have the computer speak the words, i found this documentation on mircosoft but my compiler, Borland 6, had some problems with the included header files.. ick. http://msdn2.microsoft.com/en-us/library/ms717065(VS.85).aspx[^] thats the microsoft page, any help would be appricated
thanks in addvance
sorry about the crappy spelling
i ned more skooling
|
|
|
|
|
codeinelogic wrote: ...i found this documentation on mircosoft but my compiler, Borland 6, had some problems with the included header files..
And what did you think would happen?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Problem Description:- I want to show a message when any windows is closing, but only when user clicks on the right most X symbol of the window, not with ALT-F4 key press and any other method like for example file->exit.
I have one working solution with me but just wanted to know whether the function which i am using is correct or not. Basically wanted to know about the GetAsyncKeyState because i read this in MSDN
-------
Although the least significant bit of the return value indicates whether the key has been pressed since the last query, due to the pre-emptive multitasking nature of Windows, another application can call GetAsyncKeyState and receive the "recently pressed" bit instead of your application. The behavior of the least significant bit of the return value is retained strictly for compatibility with 16-bit Windows applications (which are non-preemptive) and should not be relied upon.
--------
can anybody suggest me that GetAsyncKeyState is fine or any other function on which we can rely upon
Here is the code snippet:
LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg,WPARAM wParam, LPARAM lParam)
{
LRESULT result=0L;
int k=0;
switch(Msg)
{
case WM_NCLBUTTONDOWN:
if (wParam!=HTCLOSE) // allow clicks on system menu to continue and proceed
{
DefWindowProc(hWnd, Msg, wParam, lParam);
return 0;
}
GetAsyncKeyState(VK_LBUTTON);
break;
case WM_NCLBUTTONUP:
if ((int)wParam ==HTCLOSE && !(GetAsyncKeyState(VK_LBUTTON)))
{
k=MessageBoxA(NULL, "Do u wish to close ", "getasynckeystate", MB_YESNO);
if (k==IDYES)
{
PostMessage(hWnd, WM_CLOSE, 0, 0L);
return 0;
}
else
{
DefWindowProc(hWnd, Msg, wParam, lParam);
}
}
DefWindowProc(hWnd, Msg, wParam, lParam);
break;
case WM_DESTROY:PostQuitMessage(WM_QUIT);// then close it
break;
default : return DefWindowProc(hWnd, Msg, wParam, lParam);// Process the left-over messages
}
return result;
}
Bibhakar Ranjan
|
|
|
|
|
1/ Use the pre tags as the posting guidelines at the top of the forum say - your code was unreadable until I pasted it into VC++ and auto formatted it. And I only did that because I'm waiting for a phone call. Most people aren't this nice - I'm not normally.
2/ Your actual question. Looking at the page for GetASyncKeyState...
However, it checks on the state of the physical mouse buttons, not on the logical mouse buttons that the physical buttons are mapped to.
So from the very start your code is not right - what about a left handed user?
Also:
due to the pre-emptive multitasking nature of Windows, another application can call GetAsyncKeyState and receive the "recently pressed" bit instead of your application
So, you're not safe if another program uses the function either. Basically, this is a 16bit cooperative multitasking function, of no use in any program written after 1998.
I'm assuming you're using it to make sure that when you look at a WM_NCLBUTTONUP message, it had an earlier down?
I think you'll need to monitor the following messages:
WM_NCLBUTTONDOWN:
As you've done, but set a flag saying you're now interested.
WM_CAPTURECHANGED:
If the "I'm interested" flag is set, clear it.
WM_NCLBUTTONUP:
If your flag is set, post a "do my custom quite message box" message, and handle that, otherwise pass on the message.
That should be a bit safer for you, I hope! I've include the capture changing message, as I'm pretty sure it will help, in case someone clicks down on the X, moves the mouse away, then let's go of the button. Set a breakpoint and see if I'm a genius, or talking rubbish.
Good luck!
Iain.
Iain Clarke appears because CPallini still cares.
|
|
|
|