|
What is ScreenDimensions ? You should just call GetClientRect to achieve this.
Given that you're drawing to the width and height of ScreenDimensions, and getting problems on the right/bottom, I'd say the problem is actually the value itself.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
Screen Dimenions is a GetClientRect, its's a truly bizzare effect, when you resize the view. At first i though it must be a rounding problem, but even that doesn't seem to make sense!
Thanks Again, Much Appreciated
Richard
|
|
|
|
|
When drawing into a window you usually have to use width+1 and height+1 when drawing with GDI functions. Most GDI functions will draw up to but not including the last pixel value.
Todd Smith
|
|
|
|
|
OK, I have created a HBITMAP using the LR_CREATEDIBSECTION Flag. I have then attached that to a CBitmap object. At this point, I believe I have loaded a Device Independant Bitmap. I can get this DIB to be drawn to the screen too, However, I need low-level access to the pixels underneath, I am trying to use GetDIBits, but the function keeps returning 0 (i.e. it hasn`t scanned any lines), I think its to do with the fact that I have used (HDC)pBitmapWnd->GetDC() to return a handle to the Device Context, because everything else is empty (VOID* lpVOID, and BITMAPINFO* lpINFO are initialized appropriately). The hbitmap structure is definately a valid one, any ideas on how to get this going. Also, once I`ve used GetDIBits how do I access the actual bits of the bitmap? Many thanks go to Graussy, who got me on the right track at last.
Thanks
AEGC
|
|
|
|
|
once you get GetDIBits to work (which i'm afraid i can't help you with, i hate that function ), you'll have a DIB. in general, getting to the pixels in a DIB is a non-trival matter, given the number of different ways a DIB can hold data. but, since you can tell GetDIBits which format to use when Getting the data, your job is easier.
i'd tell it to give a 32 or 24 bit true color DIB. that way you don't have to worry about palettes or bit masking.
see the MSDN for "BITMAPINFOHEADER" for info on how DIBs are formatted.
good luck
-c
Smaller Animals Software, Inc.
http://www.smalleranimals.com
|
|
|
|
|
This is the function I use to get access to the pixels of a HBITMAP . Maybe it'll suit your needs with minor modifications.
BOOL RetrievePixels(HDC hDC,HBITMAP hBitmap,
LPBYTE *ppBytes,
LPBITMAPINFO lpBmi)
{
BITMAPINFO bmi={{sizeof(BITMAPINFOHEADER),0,0,1,0,0,0,0,0,0,0}};
memcpy(lpBmi,&bmi,sizeof(bmi));
if(GetDIBits(hDC,hBitmap,0,0,NULL,lpBmi,DIB_RGB_COLORS)==0){
return FALSE;
}
if((*ppBytes=(LPBYTE)malloc(
4*((lpBmi->bmiHeader.biWidth*3+3)/4)*lpBmi->bmiHeader.biHeight))==NULL){
return FALSE;
}
lpBmi->bmiHeader.biBitCount=24;
lpBmi->bmiHeader.biCompression=BI_RGB;
if(GetDIBits(hDC,hBitmap,0,lpBmi->bmiHeader.biHeight,*ppBytes,lpBmi,DIB_RGB_COLORS)==0){
return FALSE;
}
return TRUE;
}
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I'd use CreateDIBSection, which allows you to specific the pointer to the bit array ay creation time, and then use CBitmap::Attach if you really must. Otherwise, you could use the DIBSection wrapper clas on this site.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
DIBSECTION ds;
::GetObject(<bitmaphandle>, sizeof ds, &ds);
BYOEÄ pBitmapBits = (BYTE*)ds.dsBm.bmBits;
|
|
|
|
|
This only works if the bitmap was created as a DIBSection in the first place.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
|
|
|
|
|
Hi, i've posted a message about this before and i got an answer but it wasn't what i needed. You see i need to know how i can enable/gray menuitems in a dialogs menu in MFC. The menu is pure resource, there isn't any code to add the menu to the dialog, i just clicked properties of the dialog and there is an option to select a menu resource for that dialog. Now my last answer was: use OnUpdateCommandUI
i did this and then u get a pointer to the menuitem and then u can do something like this: pCmdUI->Enable(0);
but thats just not what i need! the menuitem is disabled, i cant click it anymore but its not gray!!!! so u dont know its not working, i've also tried using ->SetText("blablabla") but that doesn't seem to have any effect whatsoever. Can someone please explain this all to me, and show me how to do it right? or give me a tutorial or something i can look at? Cause all the pages about menus on codeguru and the codeproject seem to be dealing with more advanced problems.
Many thanks.
Kuniva
|
|
|
|
|
1) Add a handle to your dialog.h like this:
afx_msg LRESULT OnKickIdle(WPARAM, LPARAM);
2) Includes <afxpriv.h> in the dialog.cpp (for WM_KICKIDLE) message
3) Insert this code into the MESSAGE_MAP
ON_MESSAGE(WM_KICKIDLE, OnKickIdle)
4) Create the function OnKickIdle like this
LRESULT ServerProperties::OnKickIdle(WPARAM, LPARAM)
{
CMenu* pMainMenu = GetMenu();
CCmdUI cmdUI;
UINT n;
for (n = 0; n < pMainMenu->GetMenuItemCount(); ++n)
{
CMenu* pSubMenu = pMainMenu->GetSubMenu(n);
cmdUI.m_nIndexMax = pSubMenu->GetMenuItemCount();
for (UINT i = 0; i < cmdUI.m_nIndexMax;++i)
{
cmdUI.m_nIndex = i;
cmdUI.m_nID = pSubMenu->GetMenuItemID(i);
cmdUI.m_pMenu = pSubMenu;
cmdUI.DoUpdate(this, FALSE);
}
}
return TRUE;
}
5) Add the handles to OnUpdateCmdUI to menu items.
6) Relax, compile it e enjoy.
PS: That will work only for menus, there is a different way to handle toolbar.
[]s
|
|
|
|
|
The problem is that the update command UI system relies on the MFC message WM_KICKIDLE, which is not automatically handled by dialogs (it is handled by frame windows). The previous post has some code, however the OnKickIdle() can be done more simply:
OnKickIdle(...)
{
UpdateDialogControls ( this, FALSE );
} The second parameter controls whether menu items without command handlers will be disabled. Pass TRUE to disable them, or FALSE to leave them alone.
--Mike--
http://home.inreach.com/mdunn/
This posting is provided "as was" with no warranties, guarantees, lotteries, or any of those little bags of peanuts you get on planes. You assume all risk for crossing the street without holding mommy's hand. © 2001 Mike's Classy Software. Member FDIC. If rash develops, discontinue use.
your with and
|
|
|
|
|
cool thanks alot guys! Both of you!
Kuniva
|
|
|
|
|
Hello,
I have a C++ object ( a tree ) with the menu of my application.
Can you give me some advice to build the Menu of my MFC Application from
this object .
I have :
Root
_File
__Open
__Save..
_Edit
__etc...
_etc..
And all the managment of the action is done in the tree ( using a Command
pattern ).
So I need from the MFC application to call the tree and its actions.
Thanks for the help.
Stephane
|
|
|
|
|
One possible approach (though by no means the only one) for this problem is as follows:
- First, reserve some range of user defined message identifiers, say
WM_FIRST_TREECOMMAND , WM_FIRST_TREECOMMAND+1 , ... , WM_FIRST_TREECOMMAND+max_commands-1 , where max_commands is large enough so that the range holds room for all the commands on your command tree. This decision you have to made it on compile time, so allow for a reasonably large range.
- Have all the range of message IDs mapped to the same message handler (say
OnTreeComand ) by means of the MFC ON_COMMAND_RANGE .
- Define a map (use
std::map , for instance, or your favorite map container) that translates message IDs to TreeCommand objects (or whatever your command objects are named).
- On initialization time, build a
CMenu object that mimicks the structure of your command tree, by recursively transversing the tree. The key member function to call is CMenu::AppendMenu() that serves both for inserting commands and submenus. Use the range of user defined message IDs for assigning identifiers. For each new command inserted into the menu add an entry to the map of the form treecommand_map[id_command]=command , where command is the appropriate TreeCommand object (or a reference to it, or a pointer, you are the designer).
- That's it, now your message handler
OnTreeCommand only has to retrieve the TreeCommand object from the identifier passed using treecommand_map and execute it:
void CYourWnd::OnTreeCommand(UINT nID){
treecommand_map[nID].Execute();
}
Et voilà. Hope this helps.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Does anyone know, how one can draw graphics in overlay-mode? that is i want to draw on the desktop as the AVS component which ships with winamp 3.0 does!
[MeMger®]
|
|
|
|
|
Hello,
Well as a part of the lab, I am supposed to write a multi threaded UDP server(derives from CSocket). Now from what I understand, the server listens to client requests on a port and when it receives a request, it creates a new thread to handle the client.
So I have the following OnReceive function in the server class
void UDPServer::OnReceive(int nErrorCode) {
CSocket temp;
Accept(temp);
CConnection* pThread = (CConnection*) AfxBeginThread(RUNTIME_CLASS(CConnection), THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED);
pThread->m_hSocket = temp.Detach();
pThread->ResumeThread();
CSocket::OnReceive(nErrorCode);
}
Thus my class that handles each client is CConnection which derives from CWinThread. Now I want each client connection to have 2 sockets dedicated...one for server to send data, and the other for the server to recieve acknowledgements and commands from the client.
So I have following member variables in CConnection
CSocket incoming_socket; //for server to receive requests and commands
CSocket outgoing_socket; // for server to send data
SOCKET m_hSocket; // to receive a handle from the server for the new thread
Obviously next I need to define OnReceive(), OnSend() etc for the 2 sockets associated with the thread. How do I do this?
Where do I write the code for these functions associated with incoming_socket and outgoing_socket?
Thanks,
Mike
|
|
|
|
|
There's a lot of samples here on CodeProject that shows a lot of what you want to do.
I have to ask a couple of questions though...
Why don't you use a async socket, that way you can handle a lot of clients in a single thread. (threads uses resources, and the processor have to switch between the threads which costs performance).
If it's a server application I would implement it as a service or a console application instead of using MFC and CSocket, it's a lot faster. Then I would use an overlapped socket, or, if you need to handle several hundred clients at the same time I would go for IO Completion Ports...
Anyway, thats just MHO...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Hi Anders,
Thanks for the advice. Well this is the first server application I am developing, and infact it is just a part of the lab work so I dont want to get stuck up with many compexities.
Anyway from the learning point of view, I should first be able to get a basic multi threaded server running! I can move over to IO Completion later!
Can you show me the links to the relevant code samples here on CodeProject?
Mike.
|
|
|
|
|
Is it possible to send messages to other windows? like for example WM_TIMER ?
if there's a timer running in another application, is it possible for me to make it speed up or down, or just to send more WM_TIMER messages?? if it is, i'd really like to know how.
Thanks
Kuniva
|
|
|
|
|
If you have the HWND of the target window, you can send a message to it.
The problem I think you might be seeing is that timer messages are the lowest priority message in windows. You should set up a timer thread that pumps its own timer message (*not* WM_TIMER) if you want a reliable timer.
"...the staggering layers of obcenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi all,
I want to write a program that can run a cgi scrip from a domain in VC++.
And it communicate with domain through proxy.
If you have any relative information, please show me! Thank you very much!
Best regards,
BUNG
|
|
|
|
|
I'm porting Chris Maunder's CHyperLink class to WTL, but I've gotten stuck on one thing. The MFC original uses PreTranslateMessage() to relay messages to a tooltip. There is no PreTranslateMessage() in ATL, but since ATL message maps are just big switch statements, I ended up with this:
BEGIN_MSG_MAP(CHyperLink)
if ( m_ToolTip.IsWindow() )
{
m_ToolTip.RelayEvent(const_cast<LPMSG>(GetCurrentMessage()));
}
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
END_MSG_MAP()
This works but it's mighty ugly, so is there a better way of doing it?
--Mike--
http://home.inreach.com/mdunn/
This posting is provided "as was" with no warranties, guarantees, lotteries, or any of those little bags of peanuts you get on planes. You assume all risk for crossing the street without holding mommy's hand. © 2001 Mike's Classy Software. Member FDIC. If rash develops, discontinue use.
your with and
|
|
|
|
|
Actually its quite groovy...
PreTranslateMessage in MFC acts as a hook into the default message pump to alter how messages are dispatched.
so what you are doing here in WTL fits in well.
|
|
|
|
|
Hi.. just a simple question
How do i set the font when i want to display a text??
e.g. pDC->TextOut (0, 100, "HELLO WORLD");
how do i set the font of "hello world" to font-size 24 and Arial...
Thanks to ALL....
|
|
|
|
|