|
why ReleaseDC is not saving my information.
|
|
|
|
|
[edited - my brain works faster than my fingers]
ReleaseDC() does not save information. Please provide more info.
---
CPUA 0x5041
Sonork 100.11743 Chicken Little
If a man is standing in the middle of the forest speaking and there is no woman around to hear him...is he still wrong?
|
|
|
|
|
I'm making a window that acts as a menu, see:
this is my command:
ShowMenu(BOOL bFromKey, int x, int y,CWnd* pParent, HMENU hMenu)
and i have a CMenu named m_pMenu
i convert the hMenu into a CMenu:
m_pMenu->m_hMenu = hMenu;
this is ok, now i create my window using the CreateEx command, after my window is created i call another class called DrawMenuItem, this one get the size of all the menuitems stored in the m_pMenu, after get the size of the items, i assing the size to the window using the MoveWindow, after this the window is showed using the ShowWindow, then i call the ReleaseDC to make m_pMenu free for use for every class, but here's the problem when the menu is showed it call the OnPaint, in this i paint the background and i draw the menu text for the menuitems, but the m_pMenu is empty in this, why if it's supposed to be the m_pMenu of the ShowMenu command?
|
|
|
|
|
So let me get this clear, you are painting the background and text in the menu, but ...
A) you never see the text appear on the menu
B) you see the text appear on the menu, but the next time it appears the text is gone
First, I would say that if you are painting the background in the OnPaint handler, then you need to handle the OnEraseBkgnd handler as well and simply return TRUE in your implmentation of this function.
second if your answer to the above statement is choice A, I would say make sure that you are drawing in the proper coordinates for you window. It is possible that you have miscalculated the region that you should be drawing and you are not drawing on a region where the menu window exists.
If your answer is B, then I will have to ask some more questions.
Good Luck!
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
If you want the data for a DC from a window to be persistent after you call ReleaseDC, then you need to create your window with the CS_OWNDC or CS_CLASSDC style.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
is not working either
|
|
|
|
|
Based on your reply to PJ Arends response, the styles of your window are not the problem. I responded to the other thread, I hope that helps you.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
I have this combobox that i want to add some items to, but nothing is added when i do this:
for (int i = 0;i < 147;i++)
SendMessage(DlgItems[5], CB_ADDSTRING, 0L, (LPARAM)gszGenres[i]);
DlgItems[5] equals the hwnd of the control and gszGenres is a global char array with 148 items.
WHat am i doing wrong?
thanks
|
|
|
|
|
I just did what you're trying to do, but you don't mention a few things so I had to improvise in my declarations.
Here's how I declares my array of HWNDs
static struct
{
int id;
} combos [] = {
IDC_COMBO1, IDC_COMBO2, IDC_COMBO3, IDC_COMBO4, IDC_COMBO5, IDC_COMBO6};
HWND DlgItems[6];
I then initialize them like this:
for (int i = 0; i < sizeof combos / sizeof combos[0]; i++)
DlgItems[i] = ::GetDlgItem(GetSafeHwnd(), combos[i].id);
I created an array of strings like this:
static struct
{
char sz[10];
} gszGenres [] = {
"1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
"11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
"21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
"31", "32", "33", "34", "35", "36", "37", "38", "39", "40",
"41", "42", "43", "44", "45", "46", "47", "48", "49", "50",
"51", "52", "53", "54", "55", "56", "57", "58", "59", "60",
"61", "62", "63", "64", "65", "66", "67", "68", "69", "70",
"71", "72", "73", "74", "75", "76", "77", "78", "79", "80",
"81", "82", "83", "84", "85", "86", "87", "88", "89", "90",
"91", "92", "93", "94", "95", "96", "97", "98", "99", "100",
"101", "102", "103", "104", "105", "106", "107", "108", "109", "110",
"111", "112", "113", "114", "115", "116", "117", "118", "119", "120",
"121", "122", "123", "124", "125", "126", "127", "128", "129", "130",
"131", "132", "133", "134", "135", "136", "137", "138", "139", "140",
"141", "142", "143", "144", "145", "146", "147", "148"};
Finally, the code to load the combo box:
for (int i = 0; i < sizeof gszGenres / sizeof gszGenres[0]; i++)
::SendMessage(DlgItems[5], CB_ADDSTRING, 0L, (LPARAM)gszGenres[i].sz);
Cheers,
Tom Archer
Author, Inside C#
Author, Visual C++.NET Bible
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af
|
|
|
|
|
I don't use all that MFC stuff. Do you know how to do it without MFC? here's what i do:
HWND DlgItems[6];
DlgItems[5] = GetDlgItem(hWnd, IDC_GENRES);
and then initialize the strings like this (up to number 147)
char gszGenres[148][23];
strcpy(gszGenres[0], "Blues");
strcpy(gszGenres[1], "Classic Rock");
strcpy(gszGenres[2], "Country");
strcpy(gszGenres[3], "Dance");
... etc.
and then add them like a wrote before...
|
|
|
|
|
What MFC stuff? I defined two static structs, called the Win32 SDK function ::GetDlgItem to fill the hwnd struct and then called the Win32 SDK function ::SendMessage to send the CB_ADDSTRING message. The only MFC you see here is the call to GetSafeHwnd becuase I don't know from where you're calling the ::GetDlgItem function. You can obviously replace that with however you get the hwnd for your dialog.
Cheers,
Tom Archer
Author, Inside C#
Author, Visual C++.NET Bible
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af
|
|
|
|
|
Oh, sorry, i see, we're doing exactly the same... does your work?
|
|
|
|
|
No problem. My app is an MFC app, but I'm using Win32 SDK calls to mimic your environment. Yes, the data shows up exactly as it should.
Cheers,
Tom Archer
Author, Inside C#
Author, Visual C++.NET Bible
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af
|
|
|
|
|
Then i simply don't understand it. I have also tried just passing (LPARAM)"hello" to the lparam, and nothing happens...
|
|
|
|
|
strange, when i use the CB_GETCOUNT message to get the number of items in the combobox, it says 147, but nothing shows up in the box...
|
|
|
|
|
When i send the WM_SETTEXT message and pass for example "Rock" to the lparam, it selects it and it appears...
|
|
|
|
|
I just checked if my WndProc recieved the CBN_DROPDOWN message (the message sent when the list is about to be expanden ie. dropped down) and it doesen't get the message...
|
|
|
|
|
What happens when you do a CB_SETCURSEL?
Cheers,
Tom Archer
Author, Inside C#
Author, Visual C++.NET Bible
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af
|
|
|
|
|
It works "Acid Punk"... number 3...
|
|
|
|
|
This tells me that your drop down is too small.
Sorry. I just read how that can be taken.
Anyway, this thread should help you in determing how to, er, lengthen your drop down.
Cheers,
Tom Archer
Author, Inside C#
Author, Visual C++.NET Bible
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af
|
|
|
|
|
Tom Archer wrote:
What MFC stuff?
LOL
I can imagine how you just stood there stunned.
I mean you type in a post, two pages long and then he says this
Nish
The posting stats are now in PDF:-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
Updated - May 04th, Saturday
|
|
|
|
|
He's probably used to getting MFC replies even though he's requested a Win32 solution.
Cheers,
Tom Archer
Author, Inside C#
Author, Visual C++.NET Bible
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af
|
|
|
|
|
Tom Archer wrote:
He's probably used to getting MFC replies even though he's requested a Win32 solution.
Yeah
Possible.
Of course maybe he remembers how a guy here asked a CString question and suddenly another *guy* asks him if he is using MFC
Nish
The posting stats are now in PDF:-
http://www.busterboy.org/codeproject/
Feel free to make your comments.
Updated - May 04th, Saturday
|
|
|
|
|
This has nothing to do with answering your question, but you might find this link helpful!
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Anonymous wrote:
WHat am i doing wrong?
I don't know. But here are some things to check:- If it is not already,
gszGenres should be defined something like this:
const char* gszGenres[] =
{
"Rock",
"Heavy Metal",
"Ancient ('70s) Rock",
"Fake ('80s) Rock",
"Industrial",
"Trance",
"Trip Hop",
"Rap",
"Baroque",
"Blues",
"Pop"
};
const int nNumGenres = sizeof(gszGenres)/sizeof(char*); - If there are really 148 strings in
gszGenres , then this loop will skip one, since it only loops 147 times (i = 0 to 146). If you use the code above, you can use nNumGenres to avoid hard-coding this value. - How is
DlgItems defined? Can you avoid hard-coding indices somehow? - Are you positive
DlgItems[5] is the correct HWND ? Put in a breakpoint and check.
--------
People they come together
People they fall apart.
No one can stop us now
'cause we are all made of stars... -- Moby, We are all made of stars
|
|
|
|
|