PDA

View Full Version : Correct way to draw an icon in w32?



euphoria
August 17th, 2003, 13:05
The way i do it is wrong - if i move a window in front of my prog it draws the icon on top of the moved window and leaves a 'tail'.

This is what i use to draw the icon

void draw_icon(HICON hIcon) {

RECT rect;
if (GetWindowRect(GetDlgItem(hWndMainDlg, IDC_MAIN_STARS), &rect) == 0) {
MessageBox(hWndMainDlg, "GetClientRect() failed!", "***Error", 0);
} else {

HDC hDC;

if ((hDC = CreateDC("DISPLAY", NULL, NULL, NULL)) == NULL) {

MessageBox(hWndMainDlg, "CreateDC(\"DISPLAY\", NULL, NULL, NULL) failed!", "***Error", 0);
return;
}
if (DrawIconEx(hDC, rect.right+2, rect.top+2, hIcon, 0, 0, 0, NULL, DI_NORMAL) == 0) {

MessageBox(hWndMainDlg, "DrawIconEx() failed!", "***Error", 0);
}
DeleteDC(hDC);
}
}

And here i call it (ccPaint() gets called after a WM_PAINT msg):

void ccPaint(HWND hWnd, HDC hdc)
{

PAINTSTRUCT ps;

hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);

if (hIcon != NULL) {

draw_icon(hIcon);
}
}

What is the correct way to update the icon?

PS. the indent tag sucks...

Cyberman
August 19th, 2003, 19:46
The way i do it is wrong - if i move a window in front of my prog it draws the icon on top of the moved window and leaves a 'tail'.

This is what i use to draw the icon


What is the correct way to update the icon?

PS. the indent tag sucks...

Hey Euph.. how has your Chrono Cross editor been going?

Anyhow to answer your question you have to draw the icon IN the window that's being covered. This likely will cause windows to redraw the window above it so it covers the right area or it just copies the bitmap data over it. Either way.

You have to use the window handle to be sure you are drawing in that window. I might dig through the windows API in a bit if you really are desperate for this information.

Cyb

bjz
August 20th, 2003, 06:59
You could also try:
InvalidateRect(GhWnd, &rect, TRUE);

euphoria
August 21st, 2003, 12:01
Hey Euph.. how has your Chrono Cross editor been going?
Well, thanks for asking. Bad... no luck on the CRC-thing. Though i found out the character names from the save :)
But it's really pointless until i crack the CRC. I thought of using some PSX emus debugger to track and disassemble the CRC calculation but i haven't found any usefull.
FPSE's sucks, since i don't have a clue at what address should i break and i would want to step all the way to the game loading...
PCSX don't have any other than a log defines which creates pretty big logs... and no disassemly.
ePSXe - don't know how to active them.



Anyhow to answer your question you have to draw the icon IN the window that's being covered. This likely will cause windows to redraw the window above it so it covers the right area or it just copies the bitmap data over it. Either way.

You have to use the window handle to be sure you are drawing in that window. I might dig through the windows API in a bit if you really are desperate for this information.
Cyb


Well i have a the main window handle and it creates a child window (hWndMainDlg):

hWndMainDlg = CreateDialog(hInst, MAKEINTRESOURCE(IDD_MAINDIALOG), hWnd, (DLGPROC)DlgProc);
So i _think_ i'm creating the icon in the right window



You could also try:
InvalidateRect(GhWnd, &rect, TRUE);


I doesn't draw the icon if i put that instead of the draw_icon call on the ccPaint.

aprentice
August 21st, 2003, 14:57
In the window creation function, WinMain, specify the icon.

WNDCLASS wc;
wc.hIcon = LoadIcon(hInst,MAKEINTRESOURCE(IDI_MYICO N));

Cyberman
August 21st, 2003, 16:25
Well, thanks for asking. Bad... no luck on the CRC-thing. Though i found out the character names from the save :)
But it's really pointless until i crack the CRC. I thought of using some PSX emus debugger to track and disassemble the CRC calculation but i haven't found any usefull.
FPSE's sucks, since i don't have a clue at what address should i break and i would want to step all the way to the game loading...
PCSX don't have any other than a log defines which creates pretty big logs... and no disassemly.
ePSXe - don't know how to active them.


Yes I asked linuzappz about that, his response was 'PCSX2' :)

Which I can understand. I suppose the only way to do is to add a GDB debugging interface into it (using sockets preferably it's slow but reliable) and run code insight. Unfortunately you will have to step through the whole thing there is no easy way around it. They found the way of disabling the CRC check on FF7 acidentally.

You were a lot further than I did, however I believe they are using a standard SQUARE CRC so I can test that I suppose and see if it works. I could send you the PSXmemtool DLL spec as well. The biggest difficulty with finding the CRC is learning what data the check is done on. Often it's not on the range you think it is, and hence the reason why debugging is the better option.



Well i have a the main window handle and it creates a child window (hWndMainDlg):

hWndMainDlg = CreateDialog(hInst, MAKEINTRESOURCE(IDD_MAINDIALOG),
hWnd, (DLGPROC)DlgProc);
So i _think_ i'm creating the icon in the right window



I doesn't draw the icon if i put that instead of the draw_icon call on the ccPaint.
draw_icon likely assumes the current window which in this case is the window covering the one beneath. Why are you drawing an Icon dare I ask? wouldn't it be better to place an image map on the window?

Cyb

euphoria
August 22nd, 2003, 13:13
Yes I asked linuzappz about that, his response was 'PCSX2' :)

Which I can understand. I suppose the only way to do is to add a GDB debugging interface into it (using sockets preferably it's slow but reliable) and run code insight. Unfortunately you will have to step through the whole thing there is no easy way around it. They found the way of disabling the CRC check on FF7 acidentally.

You were a lot further than I did, however I believe they are using a standard SQUARE CRC so I can test that I suppose and see if it works. I could send you the PSXmemtool DLL spec as well. The biggest difficulty with finding the CRC is learning what data the check is done on. Often it's not on the range you think it is, and hence the reason why debugging is the better option.


draw_icon likely assumes the current window which in this case is the window covering the one beneath. Why are you drawing an Icon dare I ask? wouldn't it be better to place an image map on the window?

Cyb

Well i don't know what a GDB interface is... But i mean just a in-emulator disassembly/memory viewer/breakpoint facilities (like in nemu 0.8).

Thanks guys, for your help on the icon thing. I figured it out at last.
I was drawing on the "DISPLAY" context which is wrong! Im supposed to draw to the windows device context (GetDC(hWndMain)) and do a ValidateRect(...) to it.

Cyb, Well i don't know how to place an image map :)

Cyberman
August 22nd, 2003, 23:09
Well i don't know what a GDB interface is... But i mean just a in-emulator disassembly/memory viewer/breakpoint facilities (like in nemu 0.8).

Thanks guys, for your help on the icon thing. I figured it out at last.
I was drawing on the "DISPLAY" context which is wrong! Im supposed to draw to the windows device context (GetDC(hWndMain)) and do a ValidateRect(...) to it.

Cyb, Well i don't know how to place an image map :)
GDB == GNU Debug
Code Insight is a windows application that will connect to a GDB interface (example would be Visual Boy Advance has this) and allow you to view and step through any part of the memory. For a PSX emulator this would be cool, I'm thinking if I get it working for PCSX then moving it to PCSX2 things will be smoking.

Glad you solved your problem, I try not to learn windows stupid pet tricks personally :) I use BCB for my high level graphics and events, less complicated coding. The end result though is that it makes a bigger program.. can't have everything I suppose.

Cyb