Created
December 28, 2012 09:01
-
-
Save anonymous/4396146 to your computer and use it in GitHub Desktop.
Demonstration of button border problem Windows API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | |
<assembly> | |
<dependency> | |
<dependentAssembly> | |
<assemblyIdentity | |
type="win32" | |
name="Microsoft.Windows.Common-Controls" | |
version="6.0.0.0" | |
processorArchitecture="*" | |
publicKeyToken="6595b64144ccf1df" | |
language="*" | |
/> | |
</dependentAssembly> | |
</dependency> | |
</assembly> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <assert.h> | |
#include <stdexcept> | |
#include <string> | |
using namespace std; | |
bool hopefully( bool const c ) { return c; } | |
bool throwX( string const& s ) { throw runtime_error( s ); } | |
#undef UNICODE | |
#define UNICODE | |
#include <windows.h> | |
LRESULT CALLBACK windowProc( | |
HWND const window, | |
UINT const messageId, | |
WPARAM const wParam, | |
LPARAM const lParam | |
) | |
{ | |
int const idStartButton = 100; | |
switch( messageId ) | |
{ | |
case WM_CLOSE: | |
DestroyWindow( window ); | |
break; | |
case WM_CREATE: | |
CreateWindowEx( | |
WS_EX_TRANSPARENT, L"Button", L"Blah blah", | |
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 20, 50, 75, 25, | |
window, | |
reinterpret_cast<HMENU>( idStartButton - 1 ), | |
GetModuleHandle( nullptr ), | |
nullptr | |
); | |
CreateWindowEx( | |
0, L"Button", L"Start", | |
WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, 120, 50, 75, 25, | |
window, | |
reinterpret_cast<HMENU>( idStartButton ), | |
GetModuleHandle( nullptr ), | |
nullptr | |
); | |
break; | |
case WM_DESTROY: | |
PostQuitMessage( EXIT_SUCCESS ); | |
break; | |
} | |
return DefWindowProc( window, messageId, wParam, lParam ); | |
} | |
void cppMain() | |
{ | |
WNDCLASS classInfo = {}; | |
classInfo.hbrBackground = reinterpret_cast<HBRUSH>( COLOR_WINDOW + 1 ); | |
classInfo.hCursor = LoadCursor( 0, IDC_ARROW ); | |
classInfo.hIcon = LoadIcon( 0, IDI_APPLICATION ); | |
classInfo.hInstance = GetModuleHandle( nullptr ); | |
classInfo.lpfnWndProc = &windowProc; | |
classInfo.lpszClassName = L"MainWindow"; | |
classInfo.style = 0; | |
ATOM const classId = RegisterClass( &classInfo ); | |
hopefully( classId != 0 ) | |
|| throwX( "RegisterClass failed" ); | |
HWND const window = CreateWindow( | |
MAKEINTATOM( classId ), | |
L"My main window", | |
WS_OVERLAPPEDWINDOW, | |
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, | |
0, // parent | |
0, // menu | |
GetModuleHandle( nullptr ), | |
0 // lpParam | |
); | |
hopefully( window != 0 ) | |
|| throwX( "CreateWindow failed" ); | |
ShowWindow( window, SW_SHOW ); | |
for( ;; ) | |
{ | |
MSG m; | |
int const result = GetMessage( &m, 0, 0, 0 ); | |
hopefully( result >= 0 ) | |
|| throwX( "GetMessage failed" ); | |
if( result == 0 ) | |
{ | |
assert( m.message == WM_QUIT ); | |
hopefully( m.wParam == EXIT_SUCCESS ) | |
|| throwX( "WM_QUIT with non-zero exit code." ); | |
break; | |
} | |
TranslateMessage( &m ); | |
DispatchMessage( &m ); | |
} | |
} | |
#include <iostream> | |
int main() | |
{ | |
try | |
{ | |
cppMain(); | |
return EXIT_SUCCESS; | |
} | |
catch( exception const& x ) | |
{ | |
cerr << "!" << x.what() << endl; | |
} | |
return EXIT_FAILURE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment