"콘솔에서 hinstance 얻기"의 두 판 사이의 차이
jjuiddong
(새 문서: * 출처 http://bobobobo.wordpress.com/2008/02/03/getting-the-hwnd-and-hinstance-of-the-console-window/ // console app #include <iostream> using namespace std; #include <windows.h>...) |
|||
1번째 줄: | 1번째 줄: | ||
+ | * 콘솔에서 HInstance 가져오기 | ||
+ | ** 출처 http://bobobobo.wordpress.com/2008/02/03/getting-the-hwnd-and-hinstance-of-the-console-window/ | ||
− | + | // console app | |
− | + | #include <iostream> | |
− | // console app | + | using namespace std; |
− | #include <iostream> | + | #include <windows.h> |
− | using namespace std; | + | |
− | + | int main() | |
− | #include <windows.h> | + | { |
− | + | ||
− | int main() | + | |
− | { | + | |
char title[500]; // to hold title | char title[500]; // to hold title | ||
− | + | ||
// get title of console window | // get title of console window | ||
GetConsoleTitleA( title, 500 ); | GetConsoleTitleA( title, 500 ); | ||
− | + | ||
// get HWND of console, based on its title | // get HWND of console, based on its title | ||
HWND hwndConsole = FindWindowA( NULL, title ); | HWND hwndConsole = FindWindowA( NULL, title ); | ||
− | + | ||
// get HINSTANCE of console, based on HWND | // get HINSTANCE of console, based on HWND | ||
HINSTANCE hInstance = (HINSTANCE)GetWindowLong(hwndConsole, GWL_HINSTANCE); | HINSTANCE hInstance = (HINSTANCE)GetWindowLong(hwndConsole, GWL_HINSTANCE); | ||
− | + | ||
//alternate way | //alternate way | ||
HWND hwndC = GetConsoleWindow() ; /* Great!! This function | HWND hwndC = GetConsoleWindow() ; /* Great!! This function | ||
30번째 줄: | 29번째 줄: | ||
HINSTANCE hInstC = GetModuleHandle( 0 ) ; // HMODULE=HINSTANCE | HINSTANCE hInstC = GetModuleHandle( 0 ) ; // HMODULE=HINSTANCE | ||
//HINSTANCE hInstCons = (HINSTANCE)GetWindowLong( hwndC, GWL_HINSTANCE ); | //HINSTANCE hInstCons = (HINSTANCE)GetWindowLong( hwndC, GWL_HINSTANCE ); | ||
− | } | + | } |
2013년 5월 19일 (일) 12:51 기준 최신판
- 콘솔에서 HInstance 가져오기
// console app #include <iostream> using namespace std; #include <windows.h> int main() { char title[500]; // to hold title // get title of console window GetConsoleTitleA( title, 500 ); // get HWND of console, based on its title HWND hwndConsole = FindWindowA( NULL, title ); // get HINSTANCE of console, based on HWND HINSTANCE hInstance = (HINSTANCE)GetWindowLong(hwndConsole, GWL_HINSTANCE); //alternate way HWND hwndC = GetConsoleWindow() ; /* Great!! This function cleverly "retrieves the window handle used by the console associated with the calling process", as msdn says */ // Then we could just get the HINSTANCE: HINSTANCE hInstC = GetModuleHandle( 0 ) ; // HMODULE=HINSTANCE //HINSTANCE hInstCons = (HINSTANCE)GetWindowLong( hwndC, GWL_HINSTANCE ); }