Skip to main content
GameDev.net gamedev.net
🔒 Locked

weird problem

Started by kernel n bytes Dec 2, 2004 at 6:50 PM 0 replies 500+ views
Original Post
kernel n bytes
kernel n bytes
For some reason when I try to compile a Win32 program using C++ under Dev-C++ I cannot get my Icon to appear on a button. here is the source: /*main.cpp*/ #include #include #include #include #define WIN32_LEAN_AND_MEAN #define OEMRESOURCE #if !defined ButtonControlsH #define ButtonControlsH #endif #if !defined LR_SHARED #define LR_SHARED #endif LRESULT CALLBACK WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam); HINSTANCE g_hInst; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND hWnd; MSG msg; HICON hWndIcon; HCURSOR hCursor; TCHAR chClassName[]=TEXT("My Program"); WNDCLASSEX wcx; g_hInst = hInstance; hWndIcon = (HICON)LoadImage(0, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_SHARED); hCursor=(HCURSOR)LoadImage(0,IDC_ARROW,IMAGE_CURSOR,0,0,LR_SHARED); wcx.cbSize = sizeof(WNDCLASSEX); wcx.style = CS_HREDRAW|CS_VREDRAW; wcx.lpfnWndProc = (WNDPROC)WndProc; wcx.cbClsExtra = 0; wcx.cbWndExtra = 0; wcx.hInstance = hInstance; wcx.hIcon = hWndIcon; wcx.hCursor = hCursor; wcx.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1); wcx.lpszMenuName = NULL; wcx.lpszClassName = chClassName; wcx.hIconSm = NULL; if (!RegisterClassEx(&wcx)) { MessageBox( NULL, TEXT("Failed to register wnd class"), TEXT("ERROR"), MB_OK|MB_ICONERROR); return FALSE; } hWnd=CreateWindowEx(0, chClassName, TEXT("My Program"), WS_OVERLAPPEDWINDOW, GetSystemMetrics(SM_CXSCREEN)/4, GetSystemMetrics(SM_CYSCREEN)/4, GetSystemMetrics(SM_CXSCREEN)/2, GetSystemMetrics(SM_CYSCREEN)/2, NULL, NULL, hInstance, NULL); if (!hWnd) { MessageBox( NULL, TEXT("Failed to create wnd"), TEXT("ERROR"), MB_OK|MB_ICONERROR); return FALSE; } ShowWindow(hWnd,nCmdShow); UpdateWindow(hWnd); while (GetMessage(&msg,NULL,0,0)>0) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hWnd,UINT Message,WPARAM wParam,LPARAM lParam) { static HBITMAP hBmp; static HICON hIcon; static HWND hIconBtn; static HWND hBmpBtn; switch (Message) { case WM_CREATE: hIconBtn=CreateWindowEx(0, TEXT("BUTTON"), TEXT("NO TEXT"), WS_CHILD|WS_VISIBLE|BS_ICON, 240, 70, 80, 40, hWnd, NULL, g_hInst, NULL); hIcon=(HICON)LoadImage(NULL,MAKEINTRESOURCE(ICO_SMILE),IMAGE_ICON,0,0,LR_SHARED); /* When I replace ICO_SMILE with OBM_CHECK it will display a check mark but it won't show my image when I use ICO_SMILE (It shows nothing instead */ SendMessage(hIconBtn,BM_SETIMAGE,IMAGE_ICON,(LPARAM)hIcon); break; case WM_DESTROY: PostQuitMessage(0); return 0; default: return DefWindowProc(hWnd,Message,wParam,lParam); } } /* res1.rc */ #include "def1.h" ICO_SMILE ICON "'directory'" /* def1.h */ #define ICO_SMILE 1005 // ------------------------------------------------------------- I've went to Project Options and made sure my resource script is included in the compilation and its still not working.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.