Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C++ GUI Problem

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Heartless
I post too much
Reputation: 0

Joined: 03 Dec 2006
Posts: 2436

PostPosted: Sat Sep 27, 2008 12:01 pm    Post subject: C++ GUI Problem Reply with quote

I was following a source code I found online trying to make a bitmap GUI. My problems is that it only shows up as a grey square...

Here is my code:
Code:
#include <windows.h>
#include "resource.h"

HBITMAP GUI;
HWND MainWindow;

LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
   WNDCLASS wc;
   MSG Message;
   POINT Points[3];
   HRGN hRGN;
   wc.style = CS_HREDRAW | CS_VREDRAW;
   wc.lpfnWndProc = WindowProc;
   wc.cbClsExtra = 0;
   wc.cbWndExtra = 0;
   wc.hInstance = hInstance;
   wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
   wc.hCursor = LoadCursor(NULL, IDC_ARROW);
   wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
   wc.lpszMenuName = NULL;
   wc.lpszClassName = TEXT("Class");
   if (RegisterClass(&wc) == false)
      MessageBox(NULL, TEXT("Registering Class has failed!"), TEXT("ERROR"), MB_OK + MB_ICONWARNING);
   GUI = LoadBitmap(GetModuleHandle(NULL), "IDB_BITMAP1 ");
   MainWindow = CreateWindow(TEXT("Class"), TEXT("GUI"), WS_POPUPWINDOW, 0, 0, 200, 200, NULL, NULL, hInstance, NULL);
   Points[0].x = 1;   Points[0].y = 1;
   Points[1].x = 199;   Points[1].y = 1;
   Points[2].x = 199;   Points[2].y = 199;
   Points[3].x = 1;   Points[3].y = 199;
   hRGN = CreatePolygonRgn(&Points[0], 4, WINDING);
   SetWindowRgn(MainWindow, hRGN, true);
   ShowWindow(MainWindow, SW_SHOW);
   SetWindowLong(MainWindow, GWL_EXSTYLE, GetWindowLong(MainWindow, GWL_EXSTYLE) | WS_EX_LAYERED);
   SetLayeredWindowAttributes(MainWindow, 0x00ffffff, 0, LWA_COLORKEY);
   UpdateWindow(MainWindow);
   while(GetMessage(&Message, NULL, NULL, NULL))
   {
      TranslateMessage(&Message);
      DispatchMessage(&Message);
   }
   return Message.wParam;
}

LRESULT CALLBACK WindowProc(HWND hwnd,UINT Message,WPARAM wParam,LPARAM lParam)
{
   switch(Message)
   {
      case WM_LBUTTONDOWN:
         RECT rect;
         POINTS pt;
         pt = MAKEPOINTS(lParam);
         SendMessage(MainWindow, WM_NCLBUTTONDOWN, HTCAPTION, 0);
         GetWindowRect(MainWindow, &rect);
         SetActiveWindow(MainWindow);
         break;
      case WM_PAINT:
         PAINTSTRUCT ps;
         HDC kon, pom;
         kon = BeginPaint(MainWindow, &ps);
         pom = CreateCompatibleDC(kon);
         SelectObject(pom, GUI);
         BitBlt(kon, 0, 0, 200, 200, pom, 0, 0, SRCCOPY);
         DeleteDC(pom);
         EndPaint(MainWindow, &ps);
         break;
      case WM_DESTROY:
         PostQuitMessage(0);
         break;
      default:
         return (DefWindowProc(hwnd,Message,wParam,lParam));
   }
   return 0;
}


Here is my bitmap


Anyone know my problem.

_________________
What dosen't kill you, usually does the second time.
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sat Sep 27, 2008 12:12 pm    Post subject: Reply with quote

You'll probably find the LoadImage function more useful.

http://msdn.microsoft.com/en-us/library/ms648045.aspx
Back to top
View user's profile Send private message
kitterz
Grandmaster Cheater Supreme
Reputation: 0

Joined: 24 Dec 2007
Posts: 1268

PostPosted: Sat Sep 27, 2008 12:17 pm    Post subject: Reply with quote

you made sure you defined IDB_BITMAP1 and put it to a proper image?

like for an Icon it is

Code:
IDI_MYICON ICON "Icon.ico"


I dunno what for bitmap

_________________
Back to top
View user's profile Send private message Send e-mail
Heartless
I post too much
Reputation: 0

Joined: 03 Dec 2006
Posts: 2436

PostPosted: Tue Sep 30, 2008 6:34 pm    Post subject: Reply with quote

I still get the same problem when I use this:

Code:
GUI = (HBITMAP)LoadImage(hInstance, TEXT("IDB_BITMAP1"), IMAGE_BITMAP, LR_DEFAULTSIZE, LR_DEFAULTSIZE, LR_DEFAULTCOLOR);

_________________
What dosen't kill you, usually does the second time.
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Tue Sep 30, 2008 6:36 pm    Post subject: Reply with quote

change

TEXT("IDB_BITMAP1")

to

MAKEINTRESOURCE(IDB_BITMAP1)

_________________
Back to top
View user's profile Send private message
Heartless
I post too much
Reputation: 0

Joined: 03 Dec 2006
Posts: 2436

PostPosted: Tue Sep 30, 2008 6:39 pm    Post subject: Reply with quote

Thankyou lurc, it worked.
_________________
What dosen't kill you, usually does the second time.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites