frame_decoration

C++BuilderでWinMain()をいじるには

Unit1.cppではなくProject1.cppにWinMain()があるのでそこいじればおk


ウィンドウ表示テンプレ

#include <windows.h>

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
ATOM InitApp(HINSTANCE);
BOOL InitInstance(HINSTANCE,int);
	
char szClassName[] = "API01" ;
float g_temp = 10;
	
exmain(){
	WinMain(0,0,0,0);
}
	
int WINAPI WinMain(HINSTANCE hCurInst,HINSTANCE hPrevInst,
                    LPSTR lpsCmdLine,int nCmdShow)
{
    MSG msg;
    BOOL bRet;

    if(!InitApp(hCurInst))
        return FALSE;
    if(!InitInstance(hCurInst,nCmdShow))
        return FALSE;
    while((bRet = GetMessage(&msg,NULL,0,0)) != 0) {
        if(bRet ==-1){
            MessageBox(NULL,"GetMessageError","Error",MB_OK);
            break;
        } else {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
    return (int)msg.wParam;
}

//ウィンドウクラスの登録
ATOM InitApp(HINSTANCE hInst)
{
    WNDCLASSEX wc;
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInst;
    wc.hIcon = (HICON)LoadImage(NULL,
                                MAKEINTRESOURCE(IDI_APPLICATION),
                                IMAGE_ICON,
                                0,
                                0,
                                LR_DEFAULTSIZE | LR_SHARED);
    wc.hCursor = (HCURSOR)LoadImage(NULL,
                                    MAKEINTRESOURCE(IDC_ARROW),
                                    IMAGE_CURSOR,
                                    0,
                                    0,
                                    LR_DEFAULTSIZE | LR_SHARED);
    wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = (LPCSTR)szClassName;
    wc.hIconSm = (HICON)LoadImage(NULL,
                                MAKEINTRESOURCE(IDI_APPLICATION),
                                IMAGE_ICON,
                                0,
                                0,
                                LR_DEFAULTSIZE | LR_SHARED);
    return (RegisterClassEx(&wc));
}

//ウィンドウの生成
BOOL InitInstance(HINSTANCE hInst,int nCmdShow)
{
    HWND hWnd;

    hWnd = CreateWindow(szClassName,
                        "APIのてすと",
                        WS_OVERLAPPEDWINDOW,
                        CW_USEDEFAULT,
                        CW_USEDEFAULT,
                        CW_USEDEFAULT,
                        CW_USEDEFAULT,
                        NULL,
                        NULL,
                        hInst,
                        NULL);
    if(!hWnd)
        return FALSE;
    ShowWindow(hWnd,nCmdShow);
    UpdateWindow(hWnd);
    return TRUE;
}

//ウィンドウプロシージャ
LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wp,LPARAM lp)
{
    switch(msg){
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        default :
            return (DefWindowProc(hWnd,msg,wp,lp));
    }
    return 0;
}
最終更新:2007年06月08日 01:57