Sign in to follow this  
hemanthb2004

Image Not Showing

Recommended Posts

hemanthb2004    120
I have to build a project. For that I am using an OWNER Drwan Menu. Now i want the small part of the remaining space to have an image. i.e a small logo in the top right corner of the application on the menu bar unused space. Now to dry that I just typed a code to display an image somewahere in the main window. But the output is not showing the Bitmap. Why is that. What is the probelm with the below code #include <windows.h> #include"resource.h" #define ID_FILE_EXIT 9001 #define ID_STUFF_GO 9002 const char g_szClassName[] = "myWindowClass"; HINSTANCE hInstance; LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { HDC hDC, MemDCExercising; PAINTSTRUCT Ps; HBITMAP bmpExercising; switch(Message) { case WM_CREATE: { HMENU hMenu, hSubMenu; hMenu = CreateMenu(); hSubMenu = CreatePopupMenu(); AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, "E&xit"); AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File"); hSubMenu = CreatePopupMenu(); AppendMenu(hSubMenu, MF_STRING, ID_STUFF_GO, "&Go"); AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Stuff"); SetMenu(hwnd, hMenu); } break; case WM_PAINT: { hDC = BeginPaint(hwnd, &Ps); // Load the bitmap from the resource bmpExercising = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_EXERCISING)); // Create a memory device compatible with the above DC variable MemDCExercising = CreateCompatibleDC(hDC); // Select the new bitmap SelectObject(MemDCExercising, bmpExercising); // Copy the bits from the memory DC into the current dc BitBlt(hDC, 200, 200, 200, 200, MemDCExercising, 0, 0, SRCCOPY); // Restore the old bitmap DeleteDC(MemDCExercising); DeleteObject(bmpExercising); EndPaint(hwnd, &Ps); } break; case WM_COMMAND: switch(LOWORD(wParam)) { case ID_FILE_EXIT: PostMessage(hwnd, WM_CLOSE, 0, 0); break; case ID_STUFF_GO: break; } break; case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, Message, wParam, lParam); } return 0; } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wc; HWND hwnd; MSG Msg; wc.cbSize = sizeof(WNDCLASSEX); wc.style = 0; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = NULL; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wc.lpszMenuName = NULL; wc.lpszClassName = g_szClassName; wc.hIconSm = NULL; RegisterClassEx(&wc); hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, g_szClassName, "A Menu ", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, NULL, hInstance, NULL); if(hwnd == NULL) { MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); while(GetMessage(&Msg, NULL, 0, 0) > 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return Msg.wParam; } I have also uploaded the project itself : http://www.geocities.com/kalamirch/menu_two.zip

Share this post


Link to post
Share on other sites
Drazgal    368
You have two problems with your code. You never assigna value to your global hInstance which means your program cannot find the resource when you try to load it. You are also Blitting to coord 200,200 try 0,0 or something smaller instead.

Share this post


Link to post
Share on other sites

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