Chào mừng đến với Diễn đàn lập trình - Cộng đồng lập trình.
Kết quả 1 đến 6 của 6
  1. #1
    Ngày tham gia
    Sep 2015
    Bài viết
    0

    wndclass.hbrBackground Lại thêm 1 lỗi !

    Mã nguồn PHP:
    BOOL InitApplication(HINSTANCE hInstance) { WNDCLASS wndclass; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = winproc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon (NULL,IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); //wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wndclass.hbrBackground = GetStockObject(WHITE_BRUSH); wndclass.lpszClassName = AppName; wndclass.lpszMenuName = NULL; return RegisterClass(&wndclass); }  
    //wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);

    Đó lỗi chỗ đấy ? Nó bảo don't convert from ? to struct HBRUSH chán quá nè ?

  2. #2
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Online chờ các bro mà chẳng thấy ai ? Nghèo mà gặp eo thế này ? đau đầu thật ? :|


    wndclass.hbrBackground = CreateSolidBrush (RGB(0,0,0));
    sửa lỗi trên thành cái dòng này thì nó không báo lỗi ấy nữa Ctrl F7 thì không thấy chuyện gì xảy ra . Nhưng Ctrl F5 thì nó báo 2 lỗi như thế này :


    unresolved external symbol "int _cdecl InitInstance(struct HINSTANCE_ *,int)" (?InitInstance@@YAHPAUHINSTANCE_@@H@Z)
    unresolved external symbol "long _stdcall winproc(struct HWND_ *,ungsigned int,ingsigned int,long)" (?winproc@@YGJPAUHWND__@@IIJ@Z)
    Hix chẳng biết hỏi sao nữa ? Anh em coi giúp thử coi ?

    Nếu được thì test luôn đoạn code trên giúp . (Không biết 2 cái lỗi này fix xong thì gặp bi nhiêu lỗi nữa đây ? Vạn sự khởi đầu nan mà sao thấy nản thế này ? Chép nguyên trong sách chứ có sai gì đâu ?)

  3. #3
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Bạn thử lại với code này xem còn bị lỗi ko ?

    Mã:
    BOOL InitApplication(HINSTANCE hInstance)
    {
        WNDCLASS wndclass;
        wndclass.style =    CS_HREDRAW | CS_VREDRAW ;
        wndclass.lpfnWndProc =    winproc;
        wndclass.cbClsExtra  =    0;
        wndclass.cbWndExtra     =    0;
        wndclass.hInstance   =    hInstance;
        wndclass.hIcon        =    LoadIcon (NULL,IDI_APPLICATION);
        wndclass.hCursor    =    LoadCursor(NULL, IDC_ARROW);
        wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
        
        
        wndclass.lpszClassName = AppName;
        wndclass.lpszMenuName  = NULL;
        return RegisterClass(&wndclass);
    }

  4. #4
    Ngày tham gia
    Sep 2015
    Bài viết
    0

    wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
    Rồi thử ép kiểu vậy rồi nhưng mà không được mới chuyển qua dùng hàm :

    HBRUSH CreateSolidBrush (int );
    và có 2 lỗi như trên đấy !

  5. #5
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    kidkid đã đưa cho tớ mã nguồn. Test ra tổng cộng 3 lỗi. Tớ sẽ bôi đậm những chỗ cậu bị lỗi nghen

    Mã:
    // 3.cpp : Defines the entry point for the application.
    //
    
    #include "stdafx.h"
    
    LRESULT CALLBACK winproc(HWND, UINT, WPARAM, LPARAM);
    BOOL InitApplication (HINSTANCE);
    BOOL InitInstance(HINSTANCE, int);
    char AppName[]="HelloPgm";
    
    
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       cmdShow)
    {
     	MSG msg;
    	if(!InitApplication(hInstance)) return FALSE;
    	if(!InitInstance(hInstance, cmdShow)) return FALSE;
    	while(GetMessage(&msg,NULL,0,0))
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    
    
    	return msg.wParam;
    }
    
    
    BOOL InitApplication(HINSTANCE hInstance)
    {
    	WNDCLASS wndclass;
    	wndclass.style =	CS_HREDRAW | CS_VREDRAW ;
    	wndclass.lpfnWndProc =	winproc;
    	wndclass.cbClsExtra  =	0;
    	wndclass.cbWndExtra	 =	0;
    	wndclass.hInstance   =	hInstance;
    	wndclass.hIcon		=	LoadIcon (NULL,IDI_APPLICATION);
    	wndclass.hCursor	=	LoadCursor(NULL, IDC_ARROW);
    	wndclass.hbrBackground = GetStockObject(WHITE_BRUSH); // Cái này cậu thiếu (HBRUSH)
    	
    	
    	wndclass.lpszClassName = AppName;
    	wndclass.lpszMenuName  = NULL;
    	return RegisterClass(&wndclass);
    }
    
    BOOL InitInstane(HINSTANCE hInstance, int cmdShow) // Cái này gõ nhầm Instance thành Instane
    {
    	HWND hWnd;
    	hWnd = CreateWindow(AppName,
    						"Hello World",
    						WS_OVERLAPPEDWINDOW,
    						CW_USEDEFAULT,
    						0,
    						CW_USEDEFAULT,
    						0,
    						NULL,
    						NULL,
    						hInstance,
    						NULL);
    
    
    	if(!hWnd) return FALSE;
    	ShowWindow(hWnd,cmdShow);
    	UpdateWindow (hWnd);
    	return TRUE;
    }
    
    LRESULT CALLBACK Winproc(HWND hWnd,	 // Còn chỗ này thì Winproc không được viết hoa chữ W.
    						 UINT msg,
    						 WPARAM wparam,
    						 LPARAM lparam)
    {
    	HDC			hdc;
    	PAINTSTRUCT ps;
    	RECT		rect;
    	switch(msg)
    	{
    		case WM_PAINT:
    			hdc= BeginPaint ( hWnd,&ps);
    			GetClientRect(hWnd,&rect);
    			DrawText ( hdc, " Hello World ",-1,&rect,DT_SINGLELINE| DT_CENTER | DT_VCENTER);
    			EndPaint(hWnd,&ps);
    			return 0;
    		case WM_DESTROY:
    			PostQuitMessage(0);
    			return 0;
    	}
    	
    	return DefWindowProc(hWnd,msg,wparam,lparam);
    }
    Mã nguồn hoàn chỉnh sẽ là :

    Mã:
    // 3.cpp : Defines the entry point for the application.
    //
    
    #include "stdafx.h"
    
    LRESULT CALLBACK winproc(HWND, UINT, WPARAM, LPARAM);
    BOOL InitApplication (HINSTANCE);
    BOOL InitInstance(HINSTANCE, int);
    char AppName[]="HelloPgm";
    
    
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       cmdShow)
    {
     	MSG msg;
    	if(!InitApplication(hInstance)) return FALSE;
    	if(!InitInstance(hInstance, cmdShow)) return FALSE;
    	while(GetMessage(&msg,NULL,0,0))
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    
    
    	return msg.wParam;
    }
    
    
    BOOL InitApplication(HINSTANCE hInstance)
    {
    	WNDCLASS wndclass;
    	wndclass.style =	CS_HREDRAW | CS_VREDRAW ;
    	wndclass.lpfnWndProc =	winproc;
    	wndclass.cbClsExtra  =	0;
    	wndclass.cbWndExtra	 =	0;
    	wndclass.hInstance   =	hInstance;
    	wndclass.hIcon		=	LoadIcon (NULL,IDI_APPLICATION);
    	wndclass.hCursor	=	LoadCursor(NULL, IDC_ARROW);
    	wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    	
    	
    	wndclass.lpszClassName = AppName;
    	wndclass.lpszMenuName  = NULL;
    	return RegisterClass(&wndclass);
    }
    
    BOOL InitInstance(HINSTANCE hInstance, int cmdShow)
    {
    	HWND hWnd;
    	hWnd = CreateWindow(AppName,
    						"Hello World",
    						WS_OVERLAPPEDWINDOW,
    						CW_USEDEFAULT,
    						0,
    						CW_USEDEFAULT,
    						0,
    						NULL,
    						NULL,
    						hInstance,
    						NULL);
    
    
    	if(!hWnd) return FALSE;
    	ShowWindow(hWnd,cmdShow);
    	UpdateWindow (hWnd);
    	return TRUE;
    }
    
    LRESULT CALLBACK winproc(HWND hWnd,
    						 UINT msg,
    						 WPARAM wparam,
    						 LPARAM lparam)
    {
    	HDC			hdc;
    	PAINTSTRUCT ps;
    	RECT		rect;
    	switch(msg)
    	{
    		case WM_PAINT:
    			hdc= BeginPaint ( hWnd,&ps);
    			GetClientRect(hWnd,&rect);
    			DrawText ( hdc, " Hello World ",-1,&rect,DT_SINGLELINE| DT_CENTER | DT_VCENTER);
    			EndPaint(hWnd,&ps);
    			return 0;
    		case WM_DESTROY:
    			PostQuitMessage(0);
    			return 0;
    	}
    	
    	return DefWindowProc(hWnd,msg,wparam,lparam);
    }
    --May mà cậu send mã nguồn cho. Không thì xem mỗi đoạn đầu ở trên kia thì đến tết Tây cũng ko tìm ra lỗi.

  6. #6
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Rồi tớ chạy được rồi hieubm ơi ! Thanks tiếp nhé

 

 

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •