|
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....
|
|
|
|
|
look up cdc - selectobject in the msdn help stuff
---
"every year we invent better idiot proof systems and every year they invent better idiots ... and the linux zealots still aren't being sterilized"
|
|
|
|
|
take a look at SelectObject
Nish
|
|
|
|
|
Use DrawText() instead, also create and select a CFont beforehand using CFont::CreatePointFont .
---
Simon
decided that his 'ironlung' nickname sounded kinda stupid, so he decided to use his real name
|
|
|
|
|
thanks........
|
|
|
|
|
I want to implement in the MeasureItem() function,but I found I can't
set the height base on the data of the item(because I call GetItemDataPtr(), it always returns NULL),what should I do?Thank you.
|
|
|
|
|
The problem is that during WM_MEASUREITEM processing there's no item data. If you have LBS_OWNERDRAWFIXED listbox, the message is sent when listbox is created - there are no items at this time. LBS_OWNERDRAWVARIABLE doesn't help either - it's sent when you add item, before your call to SetItemData.
You'll have to pre-calculate item height before calling AddString, store the value in the place from which MeasureItem can read, and use this value in MeasureItem.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
hi all, i need some help on program easy stuff. im trying to program tic tac toe but im stuck on trying to figure out how i can program a function to test to see if there's a winner yet...any suggestions on how to make a very simple function that can do this?
|
|
|
|