Page002
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]
開始行:
[[Page001]]
* Application class の作成 [#q5632480]
Program の規模が大きくなると、module化が必要である。ここ...
** Resource file の導入 [#iae1cd29]
前節の概要を見てわかるように、application が起動すると、s...
この instance handle は application と結び付けられた reso...
とりあえず必要なのは、前節で define 文を使って固定してい...
まずは resouce.h
// resource.h
#ifndef RESOURCE_H_INCLUDED
#define RESOURCE_H_INCLUDED
#define IDS_MY_WINCLASS 1025
#define IDS_MY_APPTITLE 1026
#endif // RESOURCE_H_INCLUDED
次に、resource file として、myapp.rc を用意する。
// myapp.rc
#include "resource.h"
// String Table
STRINGTABLE
BEGIN
IDS_MY_WINCLASS "MyAppWin"
IDS_MY_APPTITLE "My Application"
END
MinGW での resource file の compile には windres を用いる。
windres myapp.rc -o res.o
** CMyApp class の導入 [#v2c1b1b6]
さて、CMyApp class であるが、constructor で Window class...
ここで、WndProc の取扱いが問題になる。汎用 Window class ...
また、基底となる window の生成、及び message loop は CMyA...
まずは myapp.h
// myapp.h
#ifndef MYAPP_H_INCLUDED
#define MYAPP_H_INCLUDED
class CMyApp
{
private:
static const int MAX_LOAD_STRING = 256;
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPA...
public:
CMyApp(HINSTANCE hInstance, HINSTANCE hPrevInstance);
~CMyApp();
int Run(int nCmdShow);
public:
HINSTANCE m_hInstance;
private:
TCHAR m_szWinClass[(MAX_LOAD_STRING+1)];
TCHAR m_szAppTitle[(MAX_LOAD_STRING+1)];
};
#endif // MYAPP_H_INCLUDED
続いて、myapp.cpp
#include <windows.h>
#include <tchar.h>
#include "resource.h"
#include "myapp.h"
CMyApp::CMyApp(HINSTANCE hInstance, HINSTANCE hPrevInsta...
{
// Save the instance handle
m_hInstance = hInstance;
// Load the strings
int nChar;
nChar = LoadString(hInstance, IDS_MY_WINCLASS, m_szWinC...
m_szWinClass[nChar] = 0;
nChar = LoadString(hInstance, IDS_MY_APPTITLE, m_szAppT...
m_szAppTitle[nChar] = 0;
// Register the Window Class
if(hPrevInstance == 0)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(0, IDI_APPLICATION);
wcex.hCursor = LoadCursor(0, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = 0;
wcex.lpszClassName = m_szWinClass;
wcex.hIconSm = LoadIcon(0, IDI_APPLICATION);
RegisterClassEx(&wcex);
}
}
CMyApp::~CMyApp()
{
}
LRESULT CALLBACK
CMyApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, ...
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
int
CMyApp::Run(int nCmdShow)
{
// Create Window
HWND hWnd = CreateWindow(m_szWinClass, m_szAppTitle, WS...
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, 0, m_hInstance,...
if(!hWnd)
return 0;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
// Enter Message Loop
MSG msg;
while(GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
** Main program [#qfb6cffb]
これで一応 CMyApp class ができたので、前節の myapp01.cpp ...
#include <windows.h>
#include <tchar.h>
#include "myapp.h"
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPre...
LPSTR lpCmdLine, int nCmdShow)
{
// Create my application
CMyApp app(hInstance, hPrevInstance);
return app.Run(nCmdShow);
}
** Compile と link [#k02a9ada]
Compile と link は
windres myapp.res -o res.o
g++ -Wall -mwindows myapp02.cpp myapp.cpp res.o -o myapp...
である。makefile を作る手もあるが、この程度であれば、上記...
ここまでのファイル
- myapp02.cpp
- resource.h
- myapp.res
- myapp.cpp
- myapp.h
- build.bat
を tar と gzip で固めたものを、このページに &ref("myapp02...
終了行:
[[Page001]]
* Application class の作成 [#q5632480]
Program の規模が大きくなると、module化が必要である。ここ...
** Resource file の導入 [#iae1cd29]
前節の概要を見てわかるように、application が起動すると、s...
この instance handle は application と結び付けられた reso...
とりあえず必要なのは、前節で define 文を使って固定してい...
まずは resouce.h
// resource.h
#ifndef RESOURCE_H_INCLUDED
#define RESOURCE_H_INCLUDED
#define IDS_MY_WINCLASS 1025
#define IDS_MY_APPTITLE 1026
#endif // RESOURCE_H_INCLUDED
次に、resource file として、myapp.rc を用意する。
// myapp.rc
#include "resource.h"
// String Table
STRINGTABLE
BEGIN
IDS_MY_WINCLASS "MyAppWin"
IDS_MY_APPTITLE "My Application"
END
MinGW での resource file の compile には windres を用いる。
windres myapp.rc -o res.o
** CMyApp class の導入 [#v2c1b1b6]
さて、CMyApp class であるが、constructor で Window class...
ここで、WndProc の取扱いが問題になる。汎用 Window class ...
また、基底となる window の生成、及び message loop は CMyA...
まずは myapp.h
// myapp.h
#ifndef MYAPP_H_INCLUDED
#define MYAPP_H_INCLUDED
class CMyApp
{
private:
static const int MAX_LOAD_STRING = 256;
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPA...
public:
CMyApp(HINSTANCE hInstance, HINSTANCE hPrevInstance);
~CMyApp();
int Run(int nCmdShow);
public:
HINSTANCE m_hInstance;
private:
TCHAR m_szWinClass[(MAX_LOAD_STRING+1)];
TCHAR m_szAppTitle[(MAX_LOAD_STRING+1)];
};
#endif // MYAPP_H_INCLUDED
続いて、myapp.cpp
#include <windows.h>
#include <tchar.h>
#include "resource.h"
#include "myapp.h"
CMyApp::CMyApp(HINSTANCE hInstance, HINSTANCE hPrevInsta...
{
// Save the instance handle
m_hInstance = hInstance;
// Load the strings
int nChar;
nChar = LoadString(hInstance, IDS_MY_WINCLASS, m_szWinC...
m_szWinClass[nChar] = 0;
nChar = LoadString(hInstance, IDS_MY_APPTITLE, m_szAppT...
m_szAppTitle[nChar] = 0;
// Register the Window Class
if(hPrevInstance == 0)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(0, IDI_APPLICATION);
wcex.hCursor = LoadCursor(0, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = 0;
wcex.lpszClassName = m_szWinClass;
wcex.hIconSm = LoadIcon(0, IDI_APPLICATION);
RegisterClassEx(&wcex);
}
}
CMyApp::~CMyApp()
{
}
LRESULT CALLBACK
CMyApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, ...
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
int
CMyApp::Run(int nCmdShow)
{
// Create Window
HWND hWnd = CreateWindow(m_szWinClass, m_szAppTitle, WS...
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0, 0, m_hInstance,...
if(!hWnd)
return 0;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
// Enter Message Loop
MSG msg;
while(GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
** Main program [#qfb6cffb]
これで一応 CMyApp class ができたので、前節の myapp01.cpp ...
#include <windows.h>
#include <tchar.h>
#include "myapp.h"
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPre...
LPSTR lpCmdLine, int nCmdShow)
{
// Create my application
CMyApp app(hInstance, hPrevInstance);
return app.Run(nCmdShow);
}
** Compile と link [#k02a9ada]
Compile と link は
windres myapp.res -o res.o
g++ -Wall -mwindows myapp02.cpp myapp.cpp res.o -o myapp...
である。makefile を作る手もあるが、この程度であれば、上記...
ここまでのファイル
- myapp02.cpp
- resource.h
- myapp.res
- myapp.cpp
- myapp.h
- build.bat
を tar と gzip で固めたものを、このページに &ref("myapp02...
ページ名: