Sign in to follow this  

win32 - slight problem

This topic is 4693 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey everyone. Just looking for a little help with a problem im having. I have a main window, which is running fine, and a seperate window(not a child window) that comes up when the program starts. What im trying to do is render a bitmap to this other window with the Windows GDI, but it doesnt seem to be working. The program compiles fine and the window shows but nothing is on it. It's starting to bug me, I just cant seem to get it right. And thats why i'm here.
#include "main.h"

int wndcount = 0;
WNDCLASS wndclass;
HINSTANCE INST;

HWND CreateTileBrowser(HWND handle)
{
	if (wndcount == 1) return handle;

		memset (&wndclass, 0, sizeof(WNDCLASS));
		wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNCLIENT | CS_NOCLOSE;
		wndclass.lpfnWndProc = TileWndProc;
		wndclass.hInstance = INST;
		wndclass.hCursor = LoadCursor(NULL, (LPCSTR) IDC_ARROW);
		wndclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
		wndclass.lpszMenuName = NULL;
		wndclass.lpszClassName = "tileclass";
		RegisterClass(&wndclass);
		
		handle = CreateWindow ("tileclass", "tile window",
                                                 WS_CAPTION | WS_OVERLAPPED,
						10, 10, 300,
						500,hwnd, NULL, INST, NULL);

        wndcount++;
	ShowWindow(handle, SW_SHOW);
	UpdateWindow(handle);
	return handle;
}



This is my creation function for the window which has the bitmap in it.

LRESULT CALLBACK TileWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT Ps;
    HDC memDC;
    HBITMAP tileset1;
    
    switch(message)
    {
        case WM_PAINT:
            Tdc = BeginPaint(TileWnd, &Ps);
            tileset1 = LoadBitmap(INST, MAKEINTRESOURCE(IDB_TILESET1));
            memDC = CreateCompatibleDC(Tdc);
            SelectObject(memDC, tileset1);
            BitBlt(Tdc,Trec.left, Trec.top, TILEW_WIDTH, TILEW_HEIGHT, memDC, 160, 320, SRCCOPY);
            DeleteDC(memDC);
            DeleteObject(tileset1);
            EndPaint(TileWnd, &Ps);
            break;
        case WM_CREATE:
            break;
        case WM_QUIT:
            wndcount--;
            break;
        case WM_DESTROY:
            wndcount--;
            break;
        
        default:
		        return DefWindowProc(hwnd, message, wParam, lParam);
    }
    
    return 0;
}



and this is the window procedure. All my function definitions are in my main.h file.

#include "main.h"
IDB_TILESET1 BITMAP DISCARDABLE "DATA/mainset.bmp"
IDR_MAIN_MENU MENUEX
BEGIN
  POPUP "File"
  BEGIN
    MENUITEM "New\tCtrl+n",IDM_FILE_NEW
    MENUITEM "Open\tCtrl+o",IDM_FILE_OPEN
    MENUITEM "Save\tCtrl+s",IDM_FILE_SAVE
    MENUITEM "Exit",IDM_FILE_EXIT
  END
  POPUP "Layer"
  BEGIN
    MENUITEM "Layer1",IDM_LAYER_L1
    MENUITEM "Layer2",IDM_LAYER_L2
    MENUITEM "Layer3",IDM_LAYER_L3
    MENUITEM "Layer4",IDM_LAYER_L4
  END
END
IDR_ACCEL ACCELERATORS
BEGIN
  0,IDM_FILE_NEW,VIRTKEY,CONTROL,NOINVERT
  0,_FILE_NEW,VIRTKEY,CONTROL,NOINVERT
  0,IDM_FILE_OPEN,VIRTKEY,CONTROL,NOINVERT
  0,_FILE_OPEN,VIRTKEY,CONTROL,NOINVERT
  115,IDM_FILE_SAVE,VIRTKEY,CONTROL,NOINVERT
  115,_FILE_SAVE,VIRTKEY,CONTROL,NOINVERT
END
IDD_DLG1 DIALOGEX 6,6,188,110
CAPTION "NEW"
FONT 8,"MS Sans Serif"
style 0x10C80000
EXstyle 0x00000000
BEGIN
  CONTROL "OK",IDC_BTN1,"Button",0x50010000,12,84,68,15,0x00000000
  CONTROL "CANCEL",IDC_BTN,"Button",0x50010000,106,84,68,15,0x00000000
  CONTROL "Map Name",IDC_STC_MN,"Static",0x50000000,12,11,52,9,0x00000000
  CONTROL "X",IDC_STC_X,"Static",0x50000000,8,59,12,11,0x00000000
  CONTROL "Y",IDC_STC_Y,"Static",0x50000000,88,59,12,11,0x00000000
  CONTROL "",IDC_MAPNAME,"Edit",0x50010000,82,9,90,13,0x00000200
  CONTROL "",IDC_X,"Edit",0x50010000,30,59,40,13,0x00000200
  CONTROL "",IDC_Y,"Edit",0x50010000,118,59,40,13,0x00000200
END



This is my resource file, incase this is where the problem is. If anything else is needed please tell me. Any and all help is much appreaciated. cheers.

Share this post


Link to post
Share on other sites
I'm honestly not that great with the Win32 API, but I believe the problem lies in no definition of "TileWnd" as an HWND.
Tdc = BeginPaint(TileWnd, &Ps);

What happens if you change this to:
Tdc = BeginPaint(hwnd, &Ps);

I think you need to use the handle of the window from the argument list.

Share this post


Link to post
Share on other sites
It looks to me like you are drawing the bitmap to an invisible DC. Why do you use CreateCompatibleDC()? I believe that function produces a DC not associated with any specific window or on-screen area. What is wrong with the one from BeginPaint()?

Share this post


Link to post
Share on other sites

This topic is 4693 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this