>修正しても駄目でした・・・^^;
>すいません、できましたー!
えっと。。。どっちだろう。。。?
一応タイトルとウィンドウに表示するサンプル貼っとこう。。。
(空白全角)
#Oh-Orangeさんがおっしゃっていることをそのままな感じデスガ
/*
* OpenFile Dialog Sample
* Windows XP Pro / VC++6.0
*/
#include<windows.h>
#define ALL_FILTER TEXT("All File {*.*}\0*.*\0")
#define TXT_FILTER TEXT("Text File {*.txt}\0*.txt\0")
#define FILE_FILTER (TXT_FILTER ALL_FILTER)
OPENFILENAME ofn = {0};
BOOL InitFileDialog( HWND hWnd );
BOOL GetOpenFilePath( CHAR* Path, INT cbSize );
LRESULT CALLBACK WndProc(HWND hWnd , UINT msg , WPARAM wp , LPARAM lp);
INT WINAPI WinMain( HINSTANCE hInstance , HINSTANCE hPrevInstance ,LPSTR lpCmdLine , int nCmdShow )
{
MSG msg;
HWND hWnd;
char* Class = "HOGE";
char* Titel = "HOGE";
WNDCLASS winc;
winc.style = CS_HREDRAW | CS_VREDRAW;
winc.lpfnWndProc = WndProc;
winc.cbClsExtra = 0;
winc.cbWndExtra = 0;
winc.hInstance = hInstance;
winc.hIcon = NULL;
winc.hCursor = NULL;
winc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
winc.lpszMenuName = NULL;
winc.lpszClassName = Class;
if( !RegisterClass( &winc )){
MessageBox( NULL, "アプリ登録失敗", NULL, MB_OK );
return 1;
}
hWnd = CreateWindowEx( WS_EX_TOPMOST, Class, Titel, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, hInstance, NULL );
if( !hWnd )
{
MessageBox( NULL, "ウィンドウ作成失敗", NULL, MB_OK );
return 2;
}
ShowWindow( hWnd, SW_SHOW );
while (GetMessage(&msg , NULL , 0 , 0 )) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc( HWND hWnd , UINT uMsg , WPARAM wParam , LPARAM lParam )
{
static HFONT hFont = NULL;
static HDC hDC = NULL;
static CHAR FullPath[256] = {0};
switch (uMsg) {
case WM_CREATE:
hFont = CreateFont( 20, 0, 0, 0, FW_REGULAR, FALSE, FALSE, FALSE,
SHIFTJIS_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,PROOF_QUALITY,
FIXED_PITCH | FF_MODERN, "MS ゴシック" );
if ( hFont == NULL )
{
MessageBox( hWnd, "フォントオブジェクトの生成に失敗", NULL, MB_OK );
PostQuitMessage(0);
}
hDC = GetDC( hWnd );
if(InitFileDialog(hWnd)==FALSE)
{
MessageBox( hWnd, "ファイルダイアログの初期化失敗", NULL, MB_OK );
CloseHandle( hFont );
PostQuitMessage(0);
}
break;
case WM_RBUTTONUP:
memset( FullPath, '\0', sizeof(FullPath));
GetOpenFilePath( FullPath, sizeof(FullPath) );
SetWindowText( hWnd, FullPath );
//読み込んだパスをWINDOW上に表示
TextOut( hDC, 20, 200, FullPath, lstrlen(FullPath));
//ダイアログで文字が欠けるので無効領域をクライアント領域に発生させる
InvalidateRect( hWnd, NULL, TRUE );
break;
case WM_PAINT:
//無効領域が発生した場合の再描画
HDC hPaint;
PAINTSTRUCT ps;
hPaint = BeginPaint(hWnd , &ps);
TextOut( hPaint , 20 , 200 , FullPath , lstrlen(FullPath));
EndPaint(hWnd , &ps);
break;
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
CloseHandle( hFont );
ReleaseDC( hWnd, hDC );
PostQuitMessage(0);
break;
default:
return DefWindowProc( hWnd, uMsg, wParam, lParam );
}
//何か処理をしたら0を返却する
return 0L;
}
BOOL InitFileDialog( HWND hWnd )
{
CHAR strFile[MAX_PATH];
if( hWnd==NULL ){
return FALSE;
}
ofn.lStructSize = sizeof (OPENFILENAME);
ofn.hwndOwner = hWnd;
ofn.lpstrFilter = FILE_FILTER;
ofn.lpstrFile = strFile;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_FILEMUSTEXIST | OFN_OVERWRITEPROMPT;
return TRUE;
}
BOOL GetOpenFilePath( CHAR* Path, INT cbSize )
{
GetOpenFileName(&ofn);
if( cbSize < (lstrlen(ofn.lpstrFile)+1)){
return FALSE;
}
lstrcpy( Path, ofn.lpstrFile );
return TRUE;
}
実は、WM_RBUTTONUPで描画しなくても、再描画してるから
無効領域を発生させるだけで描画できたりとか・・・:-P
補足
すいません、できております。 コンパイルしたのですが、 ファイルを選択したものの、何もウィンドウに表示されない。 そこで、タイトルバーをクリックしてウィンドウを広げた ところ、思い通りの結果がウィンドウ上に表示されました。 原因は何かを調べているところです。 また、ファイルを一回選択し、タイトルバーを広げると思い通りの結果が表示されるのですが、もう一度ファイルを開くと、その結果につけたした結果が出てしまうのです。カウンターが初期化されてないのでしょうかね。。 /* ---------------------表示部分 ---------------------------------- */ #define TITLE TEXT("CL(15:0)") LRESULT CALLBACK WndProc(HWND hWnd , UINT msg , WPARAM wp , LPARAM lp) { HDC hdc; HDC hDC; HPEN hpen; PAINTSTRUCT ps; HFONT hFont; HWND hwnd; int i; int j ; int k = 1; int l; int m=0; static TCHAR str[64]; static TCHAR strtwo[640]; static TCHAR strFile[MAX_PATH]; int modulecounter; /* "module"の数 */ int countertwo; int inputcounter; /* inputの数 */ int outputcounter; /* outputの数 */ FILE *fp; /* module名をとってくる */ char *y = modulename(m,strFile); /* module名をとってくる */ char word[100]; char finger; PAINTSTRUCT paint; static OPENFILENAME ofn = {0}; static TCHAR strCustom[256] = TEXT("Before files\0*.*\0\0"); modulecounter = ShowResult(); /* moduleの数を探してこい */ countertwo = ShowResultThree(); /* ";"の数を探して来い */ inputcounter = ShowResultTwo(); outputcounter = ShowResultFour(); switch (msg){ case WM_DESTROY: PostQuitMessage(0); return 0; /* ウィンドウからファイルオープンダイアグラム */ case WM_CREATE: ofn.lStructSize = sizeof (OPENFILENAME); ofn.hwndOwner = hWnd; ofn.lpstrFilter = TEXT("Text files {*.v}\0*.v\0") TEXT("HTML files {*.htm}\0*.htm;*.html\0") TEXT("All files {*.*}\0*.*\0\0"); ofn.lpstrCustomFilter = strCustom; ofn.nMaxCustFilter = 256; ofn.nFilterIndex = 0; ofn.lpstrFile = strFile; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_FILEMUSTEXIST; return 0; case WM_RBUTTONUP: hdc = GetDC( hWnd ); if ( GetOpenFileName(&ofn) ){ if ((fp = fopen(strFile, "r")) == NULL) { /* 読み込むファイル名 */ /* ファイルを開けなかったら */ /* fprintf(stderr, "Can't Open C Source File!\n"); メッセージを表示して */ exit(2);/* シェルへ戻る */ } /* 英単語が見つかったら予約語かどうか調べる */ while (GetWord(fp, word)) { BSearch(word); } SelectObject( hdc, hFont ); SetBkColor( hdc, RGB(255,255,255) ); TextOut( hdc, 200, 410, strFile, lstrlen(strFile) ); SetWindowText( hWnd, strFile ); }else{ MessageBox( hWnd, TEXT("キャンセルされました。"), TEXT("確認"), MB_OK ); } ReleaseDC( hWnd, hdc ); fclose(fp); break; case WM_PAINT: hdc = BeginPaint(hWnd , &ps); hFont = CreateFont( 15 , 0 , 0 , 0 , FW_THIN , 0 , 0 , FALSE , SHIFTJIS_CHARSET , OUT_DEFAULT_PRECIS , CLIP_DEFAULT_PRECIS , DEFAULT_QUALITY , VARIABLE_PITCH | FF_ROMAN , NULL ); /* フォント TRUE = 1 , FALSE = 0 */ hpen = CreatePen(PS_DASH , 0 , RGB(100 , 0 , 50)); /* 線の形・線の色・ペンの色 */ SelectObject(hdc , hpen); MoveToEx(hdc , 50 , 50 , NULL);/* 線のカレントポジション */ LineTo(hdc , 100 , 50); /* 左上X座標左上Y座標右下X座標右下Y座標 */ /* 円は、Ellipse(hdc , 30 , 30 , 180 , 180); */