mIRC Home    About    Download    Register    News    Help

Print Thread
#78788 11/04/04 12:03 AM
Joined: Mar 2003
Posts: 187
S
Vogon poet
OP Offline
Vogon poet
S
Joined: Mar 2003
Posts: 187
I'm going nuts. I cant figure out whats wrong, RegisterClass isnt working, and the window isnt creating.

Code:
RECT rc;
 GetWindowRect(db,&rc);
 WNDCLASS wc;
 const char* szAppName = "richclass";
    
    wc.style = 0;
    wc.lpfnWndProc = WndProc;
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.cbClsExtra = 0; 
    wc.cbWndExtra = 0; 
    wc.hInstance = OurSelf; 
	wc.lpszMenuName = NULL;
    wc.lpszClassName = szAppName; 

	if (!RegisterClass(&wc)) { 
		lstrcpy(data,"no"); 
		return 3; 
	}
   CHAR szBuf[80]; 
    DWORD dw = GetLastError(); 
 
    wsprintf(szBuf, "%s failed: GetLastError returned %u\n", 
        "ok", dw); 
 
    MessageBox(NULL, szBuf, "Error", MB_OK); 
 HWND newrich = CreateWindow(szAppName,szAppName,WS_CHILD, rc.left, rc.top, (rc.right - rc.left),(rc.bottom - rc.top),db,NULL,OurSelf,NULL);
ShowWindow(newrich,SW_SHOW);
 UpdateWindow(newrich);

  

#78789 11/04/04 10:02 AM
Joined: Mar 2003
Posts: 187
S
Vogon poet
OP Offline
Vogon poet
S
Joined: Mar 2003
Posts: 187
somehow(Dont ask how) fixed the above problem.
new problem though:

Code:
 HBITMAP hBitmap = (HBITMAP)LoadImage(GetModuleHandle(NULL),(LPCTSTR)"C:\\WINDOWS\\Zapotec.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE | LR_CREATEDIBSECTION);
 if (hBitmap == NULL) { 
	 lstrcpy(data,"E_RR Image is Null"); 
	 return 3;
 }
 
HBRUSH hBrush = CreatePatternBrush(hBitmap); 
 SetClassLong(newrich, GCL_HBRBACKGROUND, (LONG)hBrush);   


says "Not enough storage is available to process this command." (Error 8)

any clues?

#78790 11/04/04 11:32 AM
Joined: Jun 2003
Posts: 194
N
Vogon poet
Offline
Vogon poet
N
Joined: Jun 2003
Posts: 194
are you trying to draw a bg image? If so youll want to handle it in one of two ways.

1. in your WM_ERASEBKGND msg use StretchBlt making sure you SetStretchBltMode to COLORONCOLOR.

2. return (HRESULT)0L from WM_ERASEBKGND msg and handle WM_PAINT. in there create a compatible dc select your bitmap into the compat dc. use StretchBlt from abve. this will fill the image. use BitBlt instead to draw it normally, and use CreatePatternBrush and FillRect with that brush to tile the image.

Option 2 is the preffered method because its relatively fast (for a control bg image that is) and uses double buffer so no flicker on resize etc...

do not forget that a compatible dc has a 1x1 monochrome bmp that you need to save and restore before the end. the reason is in some cases a bmp selected into a compat dc is not destroyed when the dc is. so you can select the old bmp back then call DeleteObject on the one you just painted yourself.

Note: Its almost NEVER a good idea to alter class data as most of them (such as extra bytes) cannot be accessed afterwrds by new windows once the class is regged.


Link Copied to Clipboard