What's new

Correct way to draw an icon in w32?

euphoria

Emutalk Member
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
Code:
void draw_icon(HICON hIcon) {
[INDENT]RECT rect;
  if (GetWindowRect(GetDlgItem(hWndMainDlg, IDC_MAIN_STARS), &rect) == 0) {[INDENT]MessageBox(hWndMainDlg, "GetClientRect() failed!", "***Error", 0);[/INDENT]
  } else {
    [INDENT]HDC hDC;[/INDENT]

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

And here i call it (ccPaint() gets called after a WM_PAINT msg):
Code:
void ccPaint(HWND hWnd, HDC hdc)
{
  [INDENT]PAINTSTRUCT ps;

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

  if (hIcon != NULL) {
    [INDENT]draw_icon(hIcon);[/INDENT]
  }[/INDENT]
}

What is the correct way to update the icon?

PS. the indent tag sucks...
 

Cyberman

Moderator
Moderator
euphoria said:
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
 
OP
euphoria

euphoria

Emutalk Member
Cyberman said:
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.

Cyberman said:
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):
Code:
hWndMainDlg = CreateDialog(hInst, MAKEINTRESOURCE(IDD_MAINDIALOG), hWnd, (DLGPROC)DlgProc);
So i _think_ i'm creating the icon in the right window

bjz said:
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

Moderator
In the window creation function, WinMain, specify the icon.

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

Cyberman

Moderator
Moderator
euphoria said:
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.

euphoria said:
Well i have a the main window handle and it creates a child window (hWndMainDlg):
Code:
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
 
OP
euphoria

euphoria

Emutalk Member
Cyberman said:
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

Moderator
Moderator
euphoria said:
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
 

Top